aboutsummaryrefslogtreecommitdiffstats
path: root/test/libsolidity
diff options
context:
space:
mode:
authorchriseth <chris@ethereum.org>2018-04-16 21:23:36 +0800
committerGitHub <noreply@github.com>2018-04-16 21:23:36 +0800
commit3d04d832972cf56555945fe51f9a7eb2fe9c4ac1 (patch)
tree67622d6d4ff1a0fc88e66bd930eb875d7e28a127 /test/libsolidity
parent533d08517f37496295e213194b489cd6ed15432b (diff)
parenta9c16b8c3976dbd2c386586cdf143150a4266ac0 (diff)
downloaddexon-solidity-3d04d832972cf56555945fe51f9a7eb2fe9c4ac1.tar
dexon-solidity-3d04d832972cf56555945fe51f9a7eb2fe9c4ac1.tar.gz
dexon-solidity-3d04d832972cf56555945fe51f9a7eb2fe9c4ac1.tar.bz2
dexon-solidity-3d04d832972cf56555945fe51f9a7eb2fe9c4ac1.tar.lz
dexon-solidity-3d04d832972cf56555945fe51f9a7eb2fe9c4ac1.tar.xz
dexon-solidity-3d04d832972cf56555945fe51f9a7eb2fe9c4ac1.tar.zst
dexon-solidity-3d04d832972cf56555945fe51f9a7eb2fe9c4ac1.zip
Merge pull request #3868 from ethereum/bytescleanup
Properly force-clean for shortening bytesXX conversions.
Diffstat (limited to 'test/libsolidity')
-rw-r--r--test/libsolidity/SolidityEndToEndTest.cpp23
1 files changed, 23 insertions, 0 deletions
diff --git a/test/libsolidity/SolidityEndToEndTest.cpp b/test/libsolidity/SolidityEndToEndTest.cpp
index 8440449c..789b89d1 100644
--- a/test/libsolidity/SolidityEndToEndTest.cpp
+++ b/test/libsolidity/SolidityEndToEndTest.cpp
@@ -8830,6 +8830,24 @@ BOOST_AUTO_TEST_CASE(cleanup_bytes_types)
ABI_CHECK(callContractFunction("f(bytes2,uint16)", string("abc"), u256(0x040102)), encodeArgs(0));
}
+BOOST_AUTO_TEST_CASE(cleanup_bytes_types_shortening)
+{
+ char const* sourceCode = R"(
+ contract C {
+ function f() pure returns (bytes32 r) {
+ bytes4 x = 0xffffffff;
+ bytes2 y = bytes2(x);
+ assembly { r := y }
+ // At this point, r and y both store four bytes, but
+ // y is properly cleaned before the equality check
+ require(y == bytes2(0xffff));
+ }
+ }
+ )";
+ compileAndRun(sourceCode, 0, "C");
+ ABI_CHECK(callContractFunction("f()"), encodeArgs("\xff\xff\xff\xff"));
+}
+
BOOST_AUTO_TEST_CASE(skip_dynamic_types)
{
// The EVM cannot provide access to dynamically-sized return values, so we have to skip them.
@@ -11345,6 +11363,10 @@ BOOST_AUTO_TEST_CASE(abi_encode)
y[0] = "e";
require(y[0] == "e");
}
+ function f4() returns (bytes) {
+ bytes4 x = "abcd";
+ return abi.encode(bytes2(x));
+ }
}
)";
compileAndRun(sourceCode, 0, "C");
@@ -11352,6 +11374,7 @@ BOOST_AUTO_TEST_CASE(abi_encode)
ABI_CHECK(callContractFunction("f1()"), encodeArgs(0x20, 0x40, 1, 2));
ABI_CHECK(callContractFunction("f2()"), encodeArgs(0x20, 0xa0, 1, 0x60, 2, 3, "abc"));
ABI_CHECK(callContractFunction("f3()"), encodeArgs(0x20, 0xa0, 1, 0x60, 2, 3, "abc"));
+ ABI_CHECK(callContractFunction("f4()"), encodeArgs(0x20, 0x20, "ab"));
}
BOOST_AUTO_TEST_CASE(abi_encode_v2)