Add tests for constant shifts

This commit is contained in:
Alex Beregszaszi
2016-10-20 00:03:09 +01:00
parent 33250eef9e
commit 59603f7b8e
2 changed files with 84 additions and 0 deletions
+44
View File
@@ -7260,6 +7260,50 @@ BOOST_AUTO_TEST_CASE(mem_resize_is_not_paid_at_call)
BOOST_CHECK(callContractFunction("f(address)", cAddrOpt) == encodeArgs(u256(7)));
}
BOOST_AUTO_TEST_CASE(shift_constant_left)
{
char const* sourceCode = R"(
contract C {
uint public a = 0x42 << 8;
}
)";
compileAndRun(sourceCode, 0, "C");
BOOST_CHECK(callContractFunction("a()") == encodeArgs(u256(0x4200)));
}
BOOST_AUTO_TEST_CASE(shift_negative_constant_left)
{
char const* sourceCode = R"(
contract C {
int public a = -0x42 << 8;
}
)";
compileAndRun(sourceCode, 0, "C");
BOOST_CHECK(callContractFunction("a()") == encodeArgs(u256(-0x4200)));
}
BOOST_AUTO_TEST_CASE(shift_constant_right)
{
char const* sourceCode = R"(
contract C {
uint public a = 0x4200 >> 8;
}
)";
compileAndRun(sourceCode, 0, "C");
BOOST_CHECK(callContractFunction("a()") == encodeArgs(u256(0x42)));
}
BOOST_AUTO_TEST_CASE(shift_negative_constant_right)
{
char const* sourceCode = R"(
contract C {
int public a = -0x4200 >> 8;
}
)";
compileAndRun(sourceCode, 0, "C");
BOOST_CHECK(callContractFunction("a()") == encodeArgs(u256(-0x42)));
}
BOOST_AUTO_TEST_SUITE_END()
}