mirror of
https://github.com/ethereum/solidity
synced 2023-10-03 13:03:40 +00:00
Merge pull request #6079 from ethereum/shift-tests
Add more test cases for shifts with constants
This commit is contained in:
commit
7a2645f7d2
@ -14558,6 +14558,115 @@ BOOST_AUTO_TEST_CASE(bitwise_shifting_constants_constantinople)
|
||||
BOOST_CHECK(callContractFunction("shr_3()") == encodeArgs(u256(1)));
|
||||
}
|
||||
|
||||
BOOST_AUTO_TEST_CASE(bitwise_shifting_constantinople_combined)
|
||||
{
|
||||
if (!dev::test::Options::get().evmVersion().hasBitwiseShifting())
|
||||
return;
|
||||
char const* sourceCode = R"(
|
||||
contract C {
|
||||
function shl_zero(uint a) public returns (uint c) {
|
||||
assembly {
|
||||
c := shl(0, a)
|
||||
}
|
||||
}
|
||||
function shr_zero(uint a) public returns (uint c) {
|
||||
assembly {
|
||||
c := shr(0, a)
|
||||
}
|
||||
}
|
||||
function sar_zero(uint a) public returns (uint c) {
|
||||
assembly {
|
||||
c := sar(0, a)
|
||||
}
|
||||
}
|
||||
|
||||
function shl_large(uint a) public returns (uint c) {
|
||||
assembly {
|
||||
c := shl(0x110, a)
|
||||
}
|
||||
}
|
||||
function shr_large(uint a) public returns (uint c) {
|
||||
assembly {
|
||||
c := shr(0x110, a)
|
||||
}
|
||||
}
|
||||
function sar_large(uint a) public returns (uint c) {
|
||||
assembly {
|
||||
c := sar(0x110, a)
|
||||
}
|
||||
}
|
||||
|
||||
function shl_combined(uint a) public returns (uint c) {
|
||||
assembly {
|
||||
c := shl(4, shl(12, a))
|
||||
}
|
||||
}
|
||||
function shr_combined(uint a) public returns (uint c) {
|
||||
assembly {
|
||||
c := shr(4, shr(12, a))
|
||||
}
|
||||
}
|
||||
function sar_combined(uint a) public returns (uint c) {
|
||||
assembly {
|
||||
c := sar(4, sar(12, a))
|
||||
}
|
||||
}
|
||||
|
||||
function shl_combined_large(uint a) public returns (uint c) {
|
||||
assembly {
|
||||
c := shl(0xd0, shl(0x40, a))
|
||||
}
|
||||
}
|
||||
function shr_combined_large(uint a) public returns (uint c) {
|
||||
assembly {
|
||||
c := shr(0xd0, shr(0x40, a))
|
||||
}
|
||||
}
|
||||
function sar_combined_large(uint a) public returns (uint c) {
|
||||
assembly {
|
||||
c := sar(0xd0, sar(0x40, a))
|
||||
}
|
||||
}
|
||||
}
|
||||
)";
|
||||
compileAndRun(sourceCode);
|
||||
|
||||
BOOST_CHECK(callContractFunction("shl_zero(uint256)", u256(0)) == encodeArgs(u256(0)));
|
||||
BOOST_CHECK(callContractFunction("shl_zero(uint256)", u256("0xffff")) == encodeArgs(u256("0xffff")));
|
||||
BOOST_CHECK(callContractFunction("shl_zero(uint256)", u256("0xffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffff")) == encodeArgs(u256("0xffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffff")));
|
||||
BOOST_CHECK(callContractFunction("shr_zero(uint256)", u256(0)) == encodeArgs(u256(0)));
|
||||
BOOST_CHECK(callContractFunction("shr_zero(uint256)", u256("0xffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffff")) == encodeArgs(u256("0xffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffff")));
|
||||
BOOST_CHECK(callContractFunction("sar_zero(uint256)", u256(0)) == encodeArgs(u256(0)));
|
||||
BOOST_CHECK(callContractFunction("sar_zero(uint256)", u256("0xffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffff")) == encodeArgs(u256("0xffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffff")));
|
||||
|
||||
BOOST_CHECK(callContractFunction("shl_large(uint256)", u256(0)) == encodeArgs(u256(0)));
|
||||
BOOST_CHECK(callContractFunction("shl_large(uint256)", u256("0xffff")) == encodeArgs(u256(0)));
|
||||
BOOST_CHECK(callContractFunction("shl_large(uint256)", u256("0xffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffff")) == encodeArgs(u256(0)));
|
||||
BOOST_CHECK(callContractFunction("shr_large(uint256)", u256(0)) == encodeArgs(u256(0)));
|
||||
BOOST_CHECK(callContractFunction("shr_large(uint256)", u256("0xffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffff")) == encodeArgs(u256(0)));
|
||||
BOOST_CHECK(callContractFunction("sar_large(uint256)", u256(0)) == encodeArgs(u256(0)));
|
||||
BOOST_CHECK(callContractFunction("sar_large(uint256)", u256("0x7fffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffff")) == encodeArgs(u256(0)));
|
||||
BOOST_CHECK(callContractFunction("sar_large(uint256)", u256("0xffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffff")) == encodeArgs(u256("0xffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffff")));
|
||||
|
||||
BOOST_CHECK(callContractFunction("shl_combined(uint256)", u256(0)) == encodeArgs(u256(0)));
|
||||
BOOST_CHECK(callContractFunction("shl_combined(uint256)", u256("0xffff")) == encodeArgs(u256("0xffff0000")));
|
||||
BOOST_CHECK(callContractFunction("shl_combined(uint256)", u256("0xffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffff")) == encodeArgs(u256("0xffffffffffffffffffffffffffffffffffffffffffffffffffffffffffff0000")));
|
||||
BOOST_CHECK(callContractFunction("shr_combined(uint256)", u256(0)) == encodeArgs(u256(0)));
|
||||
BOOST_CHECK(callContractFunction("shr_combined(uint256)", u256("0xffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffff")) == encodeArgs(u256("0x0000ffffffffffffffffffffffffffffffffffffffffffffffffffffffffffff")));
|
||||
BOOST_CHECK(callContractFunction("sar_combined(uint256)", u256(0)) == encodeArgs(u256(0)));
|
||||
BOOST_CHECK(callContractFunction("sar_combined(uint256)", u256("0x7fffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffff")) == encodeArgs(u256("0x00007fffffffffffffffffffffffffffffffffffffffffffffffffffffffffff")));
|
||||
BOOST_CHECK(callContractFunction("sar_combined(uint256)", u256("0xffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffff")) == encodeArgs(u256("0xffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffff")));
|
||||
|
||||
BOOST_CHECK(callContractFunction("shl_combined_large(uint256)", u256(0)) == encodeArgs(u256(0)));
|
||||
BOOST_CHECK(callContractFunction("shl_combined_large(uint256)", u256("0xffff")) == encodeArgs(u256(0)));
|
||||
BOOST_CHECK(callContractFunction("shl_combined_large(uint256)", u256("0xffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffff")) == encodeArgs(u256(0)));
|
||||
BOOST_CHECK(callContractFunction("shr_combined_large(uint256)", u256(0)) == encodeArgs(u256(0)));
|
||||
BOOST_CHECK(callContractFunction("shr_combined_large(uint256)", u256("0xffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffff")) == encodeArgs(u256(0)));
|
||||
BOOST_CHECK(callContractFunction("sar_combined_large(uint256)", u256(0)) == encodeArgs(u256(0)));
|
||||
BOOST_CHECK(callContractFunction("sar_combined_large(uint256)", u256("0x7fffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffff")) == encodeArgs(u256(0)));
|
||||
BOOST_CHECK(callContractFunction("sar_combined_large(uint256)", u256("0xffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffff")) == encodeArgs(u256("0xffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffff")));
|
||||
}
|
||||
|
||||
BOOST_AUTO_TEST_CASE(senders_balance)
|
||||
{
|
||||
char const* sourceCode = R"(
|
||||
|
Loading…
Reference in New Issue
Block a user