diff --git a/execution/state.go b/execution/state.go index 5cec4b7c856bf446f5a42b5636f22b18794fae6f..e3687b49a0ae9eeda7d587397263ae16d1c1941a 100644 --- a/execution/state.go +++ b/execution/state.go @@ -277,7 +277,7 @@ func (s *State) GetStorage(address crypto.Address, key binary.Word256) (binary.W func (ws *writeState) SetStorage(address crypto.Address, key, value binary.Word256) error { if value == binary.Zero256 { - ws.state.tree.Remove(key.Bytes()) + ws.state.tree.Remove(prefixedKey(storagePrefix, address.Bytes(), key.Bytes())) } else { ws.state.tree.Set(prefixedKey(storagePrefix, address.Bytes(), key.Bytes()), value.Bytes()) } diff --git a/tests/jobs_fixtures/app50-set-storage-zero/deploy.yaml b/tests/jobs_fixtures/app50-set-storage-zero/deploy.yaml new file mode 100644 index 0000000000000000000000000000000000000000..af3589dc2bbfb56ca4020d6666fb579a7e86af19 --- /dev/null +++ b/tests/jobs_fixtures/app50-set-storage-zero/deploy.yaml @@ -0,0 +1,179 @@ +jobs: + +- name: deployStorageK + deploy: + contract: storageIssueWithZero.sol + +- name: makeSureDeployed + assert: + key: $deployStorageK + relation: ne + val: "" + +#set Int to 5000 +- name: setStorageBaseInt + set: + val: 50000 + +- name: setStorageInt + call: + destination: $deployStorageK + function: setInt + data: [$setStorageBaseInt] + +- name: queryStorageInt + query-contract: + destination: $deployStorageK + function: getInt + +- name: assertStorageInt + assert: + key: $queryStorageInt + relation: eq + val: $setStorageBaseInt + +#set Int to Zero using Yaml +- name: setStorageBaseInt2 + set: + val: 0 + +- name: setStorageInt2 + call: + destination: $deployStorageK + function: setInt + data: [$setStorageBaseInt2] + +- name: queryStorageInt2 + query-contract: + destination: $deployStorageK + function: getInt + +- name: assertStorageInt2 + assert: + key: $queryStorageInt2 + relation: eq + val: $setStorageBaseInt2 + +#set Int to Zero using solidity +- name: setStorageInt3 + call: + destination: $deployStorageK + function: setIntToZero + data: + +- name: queryStorageInt3 + query-contract: + destination: $deployStorageK + function: getInt + +- name: assertStorageInt3 + assert: + key: $queryStorageInt3 + relation: eq + val: 0 + +#set Int to another number +- name: setStorageBaseInt4 + set: + val: 777 + +- name: setStorageInt4 + call: + destination: $deployStorageK + function: setInt + data: [$setStorageBaseInt4] + +- name: queryStorageInt4 + query-contract: + destination: $deployStorageK + function: getInt + +- name: assertStorageInt4 + assert: + key: $queryStorageInt4 + relation: eq + val: $setStorageBaseInt4 + +#set Uint to 9999 +- name: setStorageBaseUint + set: + val: 9999 + +- name: setStorageUint + call: + destination: $deployStorageK + function: setUint + data: [$setStorageBaseUint] + +- name: queryStorageUint + query-contract: + destination: $deployStorageK + function: getUint + +- name: assertStorageUint + assert: + key: $queryStorageUint + relation: eq + val: $setStorageBaseUint + +#set Uint to 0 using Yaml +- name: setStorageBaseUint2 + set: + val: 0 + +- name: setStorageUint2 + call: + destination: $deployStorageK + function: setUint + data: [$setStorageBaseUint2] + +- name: queryStorageUint2 + query-contract: + destination: $deployStorageK + function: getUint + +- name: assertStorageUint2 + assert: + key: $queryStorageUint2 + relation: eq + val: $setStorageBaseUint2 + +#set Uint to 0 using solidity +- name: setStorageUint3 + call: + destination: $deployStorageK + function: setUintToZero + data: + +- name: queryStorageUint3 + query-contract: + destination: $deployStorageK + function: getUint + +- name: assertStorageUint3 + assert: + key: $queryStorageUint3 + relation: eq + val: 0 + +#set Uint to another number +- name: setStorageBaseUint4 + set: + val: 111 + +- name: setStorageUint4 + call: + destination: $deployStorageK + function: setUint + data: [$setStorageBaseUint4] + +- name: queryStorageUint4 + query-contract: + destination: $deployStorageK + function: getUint + +- name: assertStorageUint4 + assert: + key: $queryStorageUint4 + relation: eq + val: $setStorageBaseUint4 diff --git a/tests/jobs_fixtures/app50-set-storage-zero/readme.md b/tests/jobs_fixtures/app50-set-storage-zero/readme.md new file mode 100644 index 0000000000000000000000000000000000000000..9a508852f83cebd3ff7cbe9d197c039255f3e6eb --- /dev/null +++ b/tests/jobs_fixtures/app50-set-storage-zero/readme.md @@ -0,0 +1,2 @@ +# Cannot reset an int/uint to zero +* https://github.com/hyperledger/burrow/issues/847 diff --git a/tests/jobs_fixtures/app50-set-storage-zero/storageIssueWithZero.sol b/tests/jobs_fixtures/app50-set-storage-zero/storageIssueWithZero.sol new file mode 100644 index 0000000000000000000000000000000000000000..197992d12ce4d8e0f5d49b5568f6731a88e9e3e0 --- /dev/null +++ b/tests/jobs_fixtures/app50-set-storage-zero/storageIssueWithZero.sol @@ -0,0 +1,33 @@ +pragma solidity ^0.4.20; + +contract storageIssueWithZero { + + int private storedInt; + uint private storedUint; + int foo = 102; + + function setInt(int x) public { + storedInt = x; + } + + function setIntToZero() public { + storedInt = 0; + } + + function getInt() constant public returns (int retInt) { + return storedInt; + } + + function setUint(uint x) public { + storedUint = x; + } + + function setUintToZero() public { + storedUint = 0; + } + + function getUint() constant public returns (uint retUint) { + return storedUint; + } + +}