Test for bytes in mapping.

This commit is contained in:
Christian 2015-02-12 15:18:50 +01:00
parent d089703254
commit 2472e2b998

View File

@ -2385,6 +2385,30 @@ BOOST_AUTO_TEST_CASE(copy_removes_bytes_data)
BOOST_CHECK(m_state.storage(m_contractAddress).empty()); BOOST_CHECK(m_state.storage(m_contractAddress).empty());
} }
BOOST_AUTO_TEST_CASE(bytes_inside_mappings)
{
char const* sourceCode = R"(
contract c {
function set(uint key) returns (bool) { data[key] = msg.data; return true; }
function copy(uint from, uint to) returns (bool) { data[to] = data[from]; return true; }
mapping(uint => bytes) data;
}
)";
compileAndRun(sourceCode);
// store a short byte array at 1 and a longer one at 2
BOOST_CHECK(callContractFunction("set(uint256)", 1, 2) == encodeArgs(true));
BOOST_CHECK(callContractFunction("set(uint256)", 2, 2, 3, 4, 5) == encodeArgs(true));
BOOST_CHECK(!m_state.storage(m_contractAddress).empty());
// copy shorter to longer
BOOST_CHECK(callContractFunction("copy(uint256,uint256)", 1, 2) == encodeArgs(true));
BOOST_CHECK(!m_state.storage(m_contractAddress).empty());
// copy empty to both
BOOST_CHECK(callContractFunction("copy(uint256,uint256)", 99, 1) == encodeArgs(true));
BOOST_CHECK(!m_state.storage(m_contractAddress).empty());
BOOST_CHECK(callContractFunction("copy(uint256,uint256)", 99, 2) == encodeArgs(true));
BOOST_CHECK(m_state.storage(m_contractAddress).empty());
}
BOOST_AUTO_TEST_SUITE_END() BOOST_AUTO_TEST_SUITE_END()
} }