aboutsummaryrefslogtreecommitdiffstats
path: root/test/libsolidity
diff options
context:
space:
mode:
authorchriseth <c@ethdev.com>2016-12-07 06:45:17 +0800
committerchriseth <c@ethdev.com>2016-12-12 18:12:12 +0800
commit273804503096d8d5d0c9d1fcece48da871f2d90f (patch)
tree7ba765f21be9a6f3177cb2a3023bc475e14f3a93 /test/libsolidity
parent2df60bec923e1bac74cde00ae9bda641ca29d6c1 (diff)
downloaddexon-solidity-273804503096d8d5d0c9d1fcece48da871f2d90f.tar.gz
dexon-solidity-273804503096d8d5d0c9d1fcece48da871f2d90f.tar.zst
dexon-solidity-273804503096d8d5d0c9d1fcece48da871f2d90f.zip
Cleaner shift handling and type conversion for binary operations.
Diffstat (limited to 'test/libsolidity')
-rw-r--r--test/libsolidity/SolidityEndToEndTest.cpp25
1 files changed, 22 insertions, 3 deletions
diff --git a/test/libsolidity/SolidityEndToEndTest.cpp b/test/libsolidity/SolidityEndToEndTest.cpp
index 0ac88a81..3d38516d 100644
--- a/test/libsolidity/SolidityEndToEndTest.cpp
+++ b/test/libsolidity/SolidityEndToEndTest.cpp
@@ -8507,17 +8507,18 @@ BOOST_AUTO_TEST_CASE(shift_left_uint8)
BOOST_AUTO_TEST_CASE(shift_left_larger_type)
{
+ // This basically tests proper cleanup and conversion. It should not convert x to int8.
char const* sourceCode = R"(
contract C {
function f() returns (int8) {
- uint8 x = 255;
+ uint8 x = 254;
int8 y = 1;
- return a << b;
+ return y << x;
}
}
)";
compileAndRun(sourceCode, 0, "C");
- BOOST_CHECK(callContractFunction("f()") == encodeArgs(u256(1) << 255));
+ BOOST_CHECK(callContractFunction("f()") == encodeArgs(u256(0)));
}
BOOST_AUTO_TEST_CASE(shift_left_assignment)
@@ -8570,6 +8571,7 @@ BOOST_AUTO_TEST_CASE(shift_right_garbled)
)";
compileAndRun(sourceCode, 0, "C");
BOOST_CHECK(callContractFunction("f(uint256,uint256)", u256(0x0), u256(4)) == encodeArgs(u256(0xf)));
+ BOOST_CHECK(callContractFunction("f(uint256,uint256)", u256(0x0), u256(0x1004)) == encodeArgs(u256(0xf)));
}
BOOST_AUTO_TEST_CASE(shift_right_uint32)
@@ -8769,6 +8771,23 @@ BOOST_AUTO_TEST_CASE(shift_overflow)
BOOST_CHECK(callContractFunction("leftS(int8,int8)", 1, 6) == encodeArgs(u256(64)));
}
+BOOST_AUTO_TEST_CASE(cleanup_in_compound_assign)
+{
+ char const* sourceCode = R"(
+ contract C {
+ function test() returns (uint, uint) {
+ uint32 a = 0xffffffff;
+ uint16 x = uint16(a);
+ uint16 y = x;
+ x /= 0x100;
+ return (x, y);
+ }
+ }
+ )";
+ compileAndRun(sourceCode, 0, "C");
+ BOOST_CHECK(callContractFunction("test()") == encodeArgs(u256(0xff), u256(0xff)));
+}
+
BOOST_AUTO_TEST_CASE(inline_assembly_in_modifiers)
{
char const* sourceCode = R"(