From e6c778e740bfdbca0b5d6f48f0f053a16335887e Mon Sep 17 00:00:00 2001 From: chriseth Date: Fri, 6 Mar 2015 13:00:54 +0100 Subject: [PATCH] Fix for arrays containing mappings. --- SolidityEndToEndTest.cpp | 37 +++++++++++++++++++++++++++++++++++++ 1 file changed, 37 insertions(+) diff --git a/SolidityEndToEndTest.cpp b/SolidityEndToEndTest.cpp index c8664b4d0..ab6e572f1 100644 --- a/SolidityEndToEndTest.cpp +++ b/SolidityEndToEndTest.cpp @@ -3070,6 +3070,43 @@ BOOST_AUTO_TEST_CASE(array_copy_nested_array) )) == encodeArgs(10)); } +BOOST_AUTO_TEST_CASE(array_copy_including_mapping) +{ + char const* sourceCode = R"( + contract c { + mapping(uint=>uint)[90][] large; + mapping(uint=>uint)[3][] small; + function test() returns (uint r) { + large.length = small.length = 7; + large[3][2][0] = 2; + large[1] = large[3]; + small[3][2][0] = 2; + small[1] = small[2]; + r = (( + small[3][2][0] * 0x100 | + small[1][2][0]) * 0x100 | + large[3][2][0]) * 0x100 | + large[1][2][0]; + delete small; + delete large; + } + function clear() returns (uint r) { + large.length = small.length = 7; + small[3][2][0] = 0; + large[3][2][0] = 0; + small.length = large.length = 0; + return 7; + } + } + )"; + compileAndRun(sourceCode); + BOOST_CHECK(callContractFunction("test()") == encodeArgs(0x02000200)); + // storage is not empty because we cannot delete the mappings + BOOST_CHECK(!m_state.storage(m_contractAddress).empty()); + BOOST_CHECK(callContractFunction("clear()") == encodeArgs(7)); + BOOST_CHECK(m_state.storage(m_contractAddress).empty()); +} + BOOST_AUTO_TEST_CASE(pass_dynamic_arguments_to_the_base) { char const* sourceCode = R"(