diff options
author | Christian <c@ethdev.com> | 2015-02-26 03:27:55 +0800 |
---|---|---|
committer | Christian <c@ethdev.com> | 2015-02-28 05:52:19 +0800 |
commit | dca13033973c4346326cd23c71a02c8ea12b0e50 (patch) | |
tree | e9a1a6bf202d16eb9dece17f9b195827ab70a891 | |
parent | 157f93898ae57cff875beb6549314bcb4ac66cdf (diff) | |
download | dexon-solidity-dca13033973c4346326cd23c71a02c8ea12b0e50.tar dexon-solidity-dca13033973c4346326cd23c71a02c8ea12b0e50.tar.gz dexon-solidity-dca13033973c4346326cd23c71a02c8ea12b0e50.tar.bz2 dexon-solidity-dca13033973c4346326cd23c71a02c8ea12b0e50.tar.lz dexon-solidity-dca13033973c4346326cd23c71a02c8ea12b0e50.tar.xz dexon-solidity-dca13033973c4346326cd23c71a02c8ea12b0e50.tar.zst dexon-solidity-dca13033973c4346326cd23c71a02c8ea12b0e50.zip |
Shortening of dynamic arrays.
-rw-r--r-- | SolidityEndToEndTest.cpp | 90 |
1 files changed, 90 insertions, 0 deletions
diff --git a/SolidityEndToEndTest.cpp b/SolidityEndToEndTest.cpp index f52b52d1..5b99f72e 100644 --- a/SolidityEndToEndTest.cpp +++ b/SolidityEndToEndTest.cpp @@ -2768,6 +2768,96 @@ BOOST_AUTO_TEST_CASE(dynamic_out_of_bounds_array_access) BOOST_CHECK(callContractFunction("length()") == encodeArgs(4)); } +BOOST_AUTO_TEST_CASE(fixed_array_cleanup) +{ + char const* sourceCode = R"( + contract c { + uint spacer1; + uint spacer2; + uint[20] data; + function fill() { + for (uint i = 0; i < data.length; ++i) data[i] = i+1; + } + function clear() { delete data; } + } + )"; + compileAndRun(sourceCode); + BOOST_CHECK(m_state.storage(m_contractAddress).empty()); + BOOST_CHECK(callContractFunction("fill()") == bytes()); + BOOST_CHECK(!m_state.storage(m_contractAddress).empty()); + BOOST_CHECK(callContractFunction("clear()") == bytes()); + BOOST_CHECK(m_state.storage(m_contractAddress).empty()); +} + +BOOST_AUTO_TEST_CASE(short_fixed_array_cleanup) +{ + char const* sourceCode = R"( + contract c { + uint spacer1; + uint spacer2; + uint[3] data; + function fill() { + for (uint i = 0; i < data.length; ++i) data[i] = i+1; + } + function clear() { delete data; } + } + )"; + compileAndRun(sourceCode); + BOOST_CHECK(m_state.storage(m_contractAddress).empty()); + BOOST_CHECK(callContractFunction("fill()") == bytes()); + BOOST_CHECK(!m_state.storage(m_contractAddress).empty()); + BOOST_CHECK(callContractFunction("clear()") == bytes()); + BOOST_CHECK(m_state.storage(m_contractAddress).empty()); +} + +BOOST_AUTO_TEST_CASE(dynamic_array_cleanup) +{ + char const* sourceCode = R"( + contract c { + uint[20] spacer; + uint[] dynamic; + function fill() { + dynamic.length = 21; + for (uint i = 0; i < dynamic.length; ++i) dynamic[i] = i+1; + } + function halfClear() { dynamic.length = 5; } + function fullClear() { delete dynamic; } + } + )"; + compileAndRun(sourceCode); + BOOST_CHECK(m_state.storage(m_contractAddress).empty()); + BOOST_CHECK(callContractFunction("fill()") == bytes()); + BOOST_CHECK(!m_state.storage(m_contractAddress).empty()); + BOOST_CHECK(callContractFunction("halfClear()") == bytes()); + BOOST_CHECK(!m_state.storage(m_contractAddress).empty()); + BOOST_CHECK(callContractFunction("fullClear()") == bytes()); + BOOST_CHECK(m_state.storage(m_contractAddress).empty()); +} + +BOOST_AUTO_TEST_CASE(dynamic_multi_array_cleanup) +{ + char const* sourceCode = R"( + contract c { + struct s { uint[][] d; } + s[] data; + function fill() returns (uint) { + data.length = 3; + data[2].d.length = 4; + data[2].d[3].length = 5; + data[2].d[3][4] = 8; + return data[2].d[3][4]; + } + function clear() { delete data; } + } + )"; + compileAndRun(sourceCode); + BOOST_CHECK(m_state.storage(m_contractAddress).empty()); + BOOST_CHECK(callContractFunction("fill()") == encodeArgs(8)); + BOOST_CHECK(!m_state.storage(m_contractAddress).empty()); + BOOST_CHECK(callContractFunction("clear()") == bytes()); + BOOST_CHECK(m_state.storage(m_contractAddress).empty()); +} + BOOST_AUTO_TEST_SUITE_END() } |