From c601377c2db7a91c01e4a47665d19f5f7af215f1 Mon Sep 17 00:00:00 2001 From: LJ <81748770+elle-j@users.noreply.github.com> Date: Tue, 20 Jan 2026 14:34:27 +0100 Subject: [PATCH] Add integration test for deleting struct (#459) Differentially tests the behavior of deleting a struct with a member that do not occupy the full 32-byte slot. From [this issue](https://github.com/paritytech/contract-issues/issues/118) it was unclear whether the `delete` was expected to reset only the bytes occupied or the entire slot. The current behavior of resetting the entire slot is expected. --- Cargo.lock | 7 --- .../contracts/StructDeleteStorage.sol | 45 +++++++++++++++++++ crates/integration/src/tests.rs | 5 +++ 3 files changed, 50 insertions(+), 7 deletions(-) create mode 100644 crates/integration/contracts/StructDeleteStorage.sol diff --git a/Cargo.lock b/Cargo.lock index e4f53e9..e0fc3d8 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -9154,13 +9154,6 @@ dependencies = [ "serde", ] -[[package]] -name = "revive-replay" -version = "0.1.0" -dependencies = [ - "anyhow", -] - [[package]] name = "revive-runner" version = "0.4.0" diff --git a/crates/integration/contracts/StructDeleteStorage.sol b/crates/integration/contracts/StructDeleteStorage.sol new file mode 100644 index 0000000..8b80835 --- /dev/null +++ b/crates/integration/contracts/StructDeleteStorage.sol @@ -0,0 +1,45 @@ +// SPDX-License-Identifier: MIT + +pragma solidity ^0.8; + +/* runner.json +{ + "differential": true, + "actions": [ + { + "Instantiate": { + "code": { + "Solidity": { + "contract": "StructDeleteStorage" + } + } + } + }, + { + "Call": { + "dest": { + "Instantiated": 0 + }, + "data": "e70c830d" + } + } + ] +} +*/ + +contract StructDeleteStorage { + struct S { + uint8 a; + } + S s; + + function store_and_delete() public returns (uint256 r1) { + assembly { + sstore(s.slot, 0xffffff) + } + delete s; + assembly { + r1 := sload(s.slot) + } + } +} diff --git a/crates/integration/src/tests.rs b/crates/integration/src/tests.rs index c59d4e2..ee2760f 100644 --- a/crates/integration/src/tests.rs +++ b/crates/integration/src/tests.rs @@ -68,6 +68,11 @@ test_spec!(selfdestruct, "Selfdestruct", "Selfdestruct.sol"); test_spec!(clz, "CountLeadingZeros", "CountLeadingZeros.sol"); test_spec!(call_gas, "CallGas", "CallGas.sol"); test_spec!(linker_symbol, "Linked", "Linked.sol"); +test_spec!( + struct_delete_storage, + "StructDeleteStorage", + "StructDeleteStorage.sol" +); fn instantiate(path: &str, contract: &str) -> Vec { vec![Instantiate {