diff options
author | Gav Wood <g@ethdev.com> | 2015-02-13 02:30:08 +0800 |
---|---|---|
committer | Gav Wood <g@ethdev.com> | 2015-02-13 02:30:08 +0800 |
commit | b04258b6f46ba613bf51a625bf8d9c6105ec56e4 (patch) | |
tree | d71751921fbb379045296b2877cbed881a1f9eba | |
parent | 1f6198a9ae6c67061d897d67a0d40a1c1806fdec (diff) | |
parent | c90adbf5938b0f8e163953cd267d484aa3988c1c (diff) | |
download | dexon-solidity-b04258b6f46ba613bf51a625bf8d9c6105ec56e4.tar.gz dexon-solidity-b04258b6f46ba613bf51a625bf8d9c6105ec56e4.tar.zst dexon-solidity-b04258b6f46ba613bf51a625bf8d9c6105ec56e4.zip |
Merge pull request #1029 from chriseth/sol_bytesContinuation
length member for bytes
-rw-r--r-- | SolidityEndToEndTest.cpp | 39 |
1 files changed, 39 insertions, 0 deletions
diff --git a/SolidityEndToEndTest.cpp b/SolidityEndToEndTest.cpp index 6c90ca62..587d4193 100644 --- a/SolidityEndToEndTest.cpp +++ b/SolidityEndToEndTest.cpp @@ -2385,6 +2385,45 @@ BOOST_AUTO_TEST_CASE(copy_removes_bytes_data) 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_CASE(bytes_length_member) +{ + char const* sourceCode = R"( + contract c { + function set() returns (bool) { data = msg.data; return true; } + function getLength() returns (uint) { return data.length; } + bytes data; + } + )"; + compileAndRun(sourceCode); + BOOST_CHECK(callContractFunction("getLength()") == encodeArgs(0)); + BOOST_CHECK(callContractFunction("set()", 1, 2) == encodeArgs(true)); + BOOST_CHECK(callContractFunction("getLength()") == encodeArgs(4+32+32)); +} + BOOST_AUTO_TEST_SUITE_END() } |