mirror of
https://github.com/ethereum/solidity
synced 2023-10-03 13:03:40 +00:00
Merge pull request #1029 from chriseth/sol_bytesContinuation
length member for bytes
This commit is contained in:
commit
b04258b6f4
@ -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()
|
||||
|
||||
}
|
||||
|
Loading…
Reference in New Issue
Block a user