Skip to content

Commit bb05038

Browse files
committed
add end to end tests
1 parent da9b6ac commit bb05038

File tree

1 file changed

+125
-0
lines changed

1 file changed

+125
-0
lines changed

test/libsolidity/SolidityEndToEndTest.cpp

Lines changed: 125 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -11141,6 +11141,131 @@ BOOST_AUTO_TEST_CASE(swap_peephole_optimisation)
1114111141
BOOST_CHECK(callContractFunction("div(uint256,uint256)", u256(0), u256(1)) == encodeArgs(u256(0)));
1114211142
}
1114311143

11144+
BOOST_AUTO_TEST_CASE(bitwise_shifting_constantinople)
11145+
{
11146+
if (!dev::test::Options::get().evmVersion().hasBitwiseShifting())
11147+
return;
11148+
char const* sourceCode = R"(
11149+
contract C {
11150+
function shl(uint a, uint b) returns (uint c) {
11151+
assembly {
11152+
a
11153+
b
11154+
shl
11155+
=: c
11156+
}
11157+
}
11158+
function shr(uint a, uint b) returns (uint c) {
11159+
assembly {
11160+
a
11161+
b
11162+
shr
11163+
=: c
11164+
}
11165+
}
11166+
function sar(uint a, uint b) returns (uint c) {
11167+
assembly {
11168+
a
11169+
b
11170+
sar
11171+
=: c
11172+
}
11173+
}
11174+
}
11175+
)";
11176+
compileAndRun(sourceCode);
11177+
BOOST_CHECK(callContractFunction("shl(uint256,uint256)", u256(1), u256(2)) == encodeArgs(u256(1)));
11178+
BOOST_CHECK(callContractFunction("shl(uint256,uint256)", u256("0xffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffff"), u256(1)) == encodeArgs(u256("0xfffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffe")));
11179+
BOOST_CHECK(callContractFunction("shl(uint256,uint256)", u256("0xffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffff"), u256(256)) == encodeArgs(u256(0)));
11180+
BOOST_CHECK(callContractFunction("shr(uint256,uint256)", u256(3), u256(1)) == encodeArgs(u256(1)));
11181+
BOOST_CHECK(callContractFunction("shr(uint256,uint256)", u256("0xffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffff"), u256(1)) == encodeArgs(u256("0x7fffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffff")));
11182+
BOOST_CHECK(callContractFunction("shr(uint256,uint256)", u256("0xffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffff"), u256(256)) == encodeArgs(u256(1)));
11183+
BOOST_CHECK(callContractFunction("sar(uint256,uint256)", u256(3), u256(1)) == encodeArgs(u256(2)));
11184+
BOOST_CHECK(callContractFunction("sar(uint256,uint256)", u256("0xffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffff"), u256(1)) == encodeArgs(u256("0xffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffff")));
11185+
BOOST_CHECK(callContractFunction("sar(uint256,uint256)", u256("0xffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffff"), u256(256)) == encodeArgs(u256("0xffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffff")));
11186+
}
11187+
11188+
BOOST_AUTO_TEST_CASE(bitwise_shifting_constants_constantinople)
11189+
{
11190+
if (!dev::test::Options::get().evmVersion().hasBitwiseShifting())
11191+
return;
11192+
char const* sourceCode = R"(
11193+
contract C {
11194+
function shl_1() returns (bool) {
11195+
assembly {
11196+
1
11197+
2
11198+
shl
11199+
=: c
11200+
}
11201+
assert(c == 4);
11202+
return true;
11203+
}
11204+
function shl_2() returns (bool) {
11205+
assembly {
11206+
0
11207+
not
11208+
1
11209+
shl
11210+
=: c
11211+
}
11212+
assert(c == 0xfffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffe);
11213+
return true;
11214+
}
11215+
function shl_3() returns (bool) {
11216+
assembly {
11217+
0
11218+
not
11219+
256
11220+
shl
11221+
=: c
11222+
}
11223+
assert(c == 0);
11224+
return true;
11225+
}
11226+
function shr_1() returns (bool) {
11227+
assembly {
11228+
3
11229+
1
11230+
shr
11231+
=: c
11232+
}
11233+
assert(c == 1);
11234+
return true;
11235+
}
11236+
function shr_2() returns (bool) {
11237+
assembly {
11238+
0
11239+
not
11240+
1
11241+
shr
11242+
=: c
11243+
}
11244+
assert(c == 0x7fffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffff);
11245+
return true;
11246+
}
11247+
function shr_3() returns (bool) {
11248+
assembly {
11249+
0
11250+
not
11251+
256
11252+
shr
11253+
=: c
11254+
}
11255+
assert(c == 0);
11256+
return true;
11257+
}
11258+
}
11259+
)";
11260+
compileAndRun(sourceCode);
11261+
BOOST_CHECK(callContractFunction("shl_1") == encodeArgs(u256(1)));
11262+
BOOST_CHECK(callContractFunction("shl_2") == encodeArgs(u256(1)));
11263+
BOOST_CHECK(callContractFunction("shl_3") == encodeArgs(u256(1)));
11264+
BOOST_CHECK(callContractFunction("shr_1") == encodeArgs(u256(1)));
11265+
BOOST_CHECK(callContractFunction("shr_2") == encodeArgs(u256(1)));
11266+
BOOST_CHECK(callContractFunction("shr_3") == encodeArgs(u256(1)));
11267+
}
11268+
1114411269
BOOST_AUTO_TEST_SUITE_END()
1114511270

1114611271
}

0 commit comments

Comments
 (0)