diff options
author | chriseth <chris@ethereum.org> | 2018-05-06 21:23:20 +0800 |
---|---|---|
committer | chriseth <chris@ethereum.org> | 2018-05-16 15:48:03 +0800 |
commit | 8b98ff470ccb11fbe0e7c1729db5958355c2f84a (patch) | |
tree | b77456a7a393b94ea18dd94fbcf0ee20eca23418 /test/libsolidity/SolidityEndToEndTest.cpp | |
parent | 03c248440770202bb67b4818ff86608fd6a7789d (diff) | |
download | dexon-solidity-8b98ff470ccb11fbe0e7c1729db5958355c2f84a.tar.gz dexon-solidity-8b98ff470ccb11fbe0e7c1729db5958355c2f84a.tar.zst dexon-solidity-8b98ff470ccb11fbe0e7c1729db5958355c2f84a.zip |
Add test for forwarding length check.
Diffstat (limited to 'test/libsolidity/SolidityEndToEndTest.cpp')
-rw-r--r-- | test/libsolidity/SolidityEndToEndTest.cpp | 45 |
1 files changed, 45 insertions, 0 deletions
diff --git a/test/libsolidity/SolidityEndToEndTest.cpp b/test/libsolidity/SolidityEndToEndTest.cpp index 42f69099..1efcfde0 100644 --- a/test/libsolidity/SolidityEndToEndTest.cpp +++ b/test/libsolidity/SolidityEndToEndTest.cpp @@ -3959,6 +3959,51 @@ BOOST_AUTO_TEST_CASE(call_forward_bytes) ABI_CHECK(callContractFunction("val()"), encodeArgs(0x80)); } +BOOST_AUTO_TEST_CASE(call_forward_bytes_length) +{ + char const* sourceCode = R"( + contract receiver { + uint public calledLength; + function() { calledLength = msg.data.length; } + } + contract sender { + receiver rec; + constructor() { rec = new receiver(); } + function viaCalldata() returns (uint) { + require(rec.call(msg.data)); + return rec.calledLength(); + } + function viaMemory() returns (uint) { + bytes memory x = msg.data; + require(rec.call(x)); + return rec.calledLength(); + } + bytes s; + function viaStorage() returns (uint) { + s = msg.data; + require(rec.call(s)); + return rec.calledLength(); + } + } + )"; + compileAndRun(sourceCode, 0, "sender"); + + // No additional data, just function selector + ABI_CHECK(callContractFunction("viaCalldata()"), encodeArgs(4)); + ABI_CHECK(callContractFunction("viaMemory()"), encodeArgs(0x20)); + // Should be this with 0.5.0: encodeArgs(4)); + ABI_CHECK(callContractFunction("viaStorage()"), encodeArgs(0x20)); + // Should be this with 0.5.0: encodeArgs(4)); + + // Some additional unpadded data + bytes unpadded = asBytes(string("abc")); + ABI_CHECK(callContractFunctionNoEncoding("viaCalldata()", unpadded), encodeArgs(7)); + ABI_CHECK(callContractFunctionNoEncoding("viaMemory()", unpadded), encodeArgs(0x20)); + // Should be this with 0.5.0: encodeArgs(7)); + ABI_CHECK(callContractFunctionNoEncoding("viaStorage()", unpadded), encodeArgs(0x20)); + // Should be this with 0.5.0: encodeArgs(7)); +} + BOOST_AUTO_TEST_CASE(copying_bytes_multiassign) { char const* sourceCode = R"( |