diff options
author | Daniel Kirchner <daniel@ekpyron.org> | 2018-06-12 23:19:20 +0800 |
---|---|---|
committer | GitHub <noreply@github.com> | 2018-06-12 23:19:20 +0800 |
commit | e2f4a9fcf409df1108d355824de12ff43682a728 (patch) | |
tree | 0e1be338e5347370ebca2075b164b56bc61046dd /test | |
parent | 2c8eca5dcfc5f961615eb1673f150d3088954a46 (diff) | |
parent | 510f227bd78cda33181531141c88c6b948d72935 (diff) | |
download | dexon-solidity-e2f4a9fcf409df1108d355824de12ff43682a728.tar dexon-solidity-e2f4a9fcf409df1108d355824de12ff43682a728.tar.gz dexon-solidity-e2f4a9fcf409df1108d355824de12ff43682a728.tar.bz2 dexon-solidity-e2f4a9fcf409df1108d355824de12ff43682a728.tar.lz dexon-solidity-e2f4a9fcf409df1108d355824de12ff43682a728.tar.xz dexon-solidity-e2f4a9fcf409df1108d355824de12ff43682a728.tar.zst dexon-solidity-e2f4a9fcf409df1108d355824de12ff43682a728.zip |
Merge pull request #4277 from ethereum/signedRightShift
Signed Right Shift: Additional test and more explanation.
Diffstat (limited to 'test')
-rw-r--r-- | test/libsolidity/SolidityEndToEndTest.cpp | 33 |
1 files changed, 33 insertions, 0 deletions
diff --git a/test/libsolidity/SolidityEndToEndTest.cpp b/test/libsolidity/SolidityEndToEndTest.cpp index 3b3cc4f7..a4c02888 100644 --- a/test/libsolidity/SolidityEndToEndTest.cpp +++ b/test/libsolidity/SolidityEndToEndTest.cpp @@ -10508,6 +10508,39 @@ BOOST_AUTO_TEST_CASE(shift_right_garbled) ABI_CHECK(callContractFunction("f(uint8,uint8)", u256(0x0), u256(0x1004)), encodeArgs(u256(0xf))); } +BOOST_AUTO_TEST_CASE(shift_right_garbled_signed) +{ + char const* sourceCode = R"( + contract C { + function f(int8 a, uint8 b) returns (int) { + assembly { + a := 0xfffffff0 + } + // Higher bits should be signextended before the shift + return a >> b; + } + function g(int8 a, uint8 b) returns (int) { + assembly { + a := 0xf0 + } + // Higher bits should be signextended before the shift + return a >> b; + } + } + )"; + compileAndRun(sourceCode, 0, "C"); + ABI_CHECK(callContractFunction("f(int8,uint8)", u256(0x0), u256(3)), encodeArgs(u256(-2))); + ABI_CHECK(callContractFunction("f(int8,uint8)", u256(0x0), u256(4)), encodeArgs(u256(-1))); + ABI_CHECK(callContractFunction("f(int8,uint8)", u256(0x0), u256(0xFF)), encodeArgs(u256(-1))); + ABI_CHECK(callContractFunction("f(int8,uint8)", u256(0x0), u256(0x1003)), encodeArgs(u256(-2))); + ABI_CHECK(callContractFunction("f(int8,uint8)", u256(0x0), u256(0x1004)), encodeArgs(u256(-1))); + ABI_CHECK(callContractFunction("g(int8,uint8)", u256(0x0), u256(3)), encodeArgs(u256(-2))); + ABI_CHECK(callContractFunction("g(int8,uint8)", u256(0x0), u256(4)), encodeArgs(u256(-1))); + ABI_CHECK(callContractFunction("g(int8,uint8)", u256(0x0), u256(0xFF)), encodeArgs(u256(-1))); + ABI_CHECK(callContractFunction("g(int8,uint8)", u256(0x0), u256(0x1003)), encodeArgs(u256(-2))); + ABI_CHECK(callContractFunction("g(int8,uint8)", u256(0x0), u256(0x1004)), encodeArgs(u256(-1))); +} + BOOST_AUTO_TEST_CASE(shift_right_uint32) { char const* sourceCode = R"( |