Merge pull request #10817 from ethereum/splitShiftBytesTest

Split shift bytes test.
This commit is contained in:
Leonardo 2021-01-19 16:16:45 +01:00 committed by GitHub
commit 0b023b893e
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
3 changed files with 38 additions and 21 deletions

View File

@ -4427,27 +4427,6 @@ BOOST_AUTO_TEST_CASE(shift_bytes)
ABI_CHECK(callContractFunction("right(bytes20,uint8)", "12345678901234567890", 8 * 8), encodeArgs(string(8, 0) + "123456789012"));
}
BOOST_AUTO_TEST_CASE(shift_bytes_cleanup)
{
char const* sourceCode = R"(
contract C {
function left(uint8 y) public returns (bytes20) {
bytes20 x;
assembly { x := "12345678901234567890abcde" }
return x << y;
}
function right(uint8 y) public returns (bytes20) {
bytes20 x;
assembly { x := "12345678901234567890abcde" }
return x >> y;
}
}
)";
compileAndRun(sourceCode, 0, "C");
ABI_CHECK(callContractFunction("left(uint8)", 8 * 8), encodeArgs("901234567890" + string(8, 0)));
ABI_CHECK(callContractFunction("right(uint8)", 8 * 8), encodeArgs(string(8, 0) + "123456789012"));
}
BOOST_AUTO_TEST_CASE(contracts_separated_with_comment)
{
char const* sourceCode = R"(

View File

@ -0,0 +1,19 @@
contract C {
function l(uint8 y) public returns (bytes20) {
bytes20 x;
assembly { x := "12345678901234567890abcde" }
// When compiling via IR, `x` is truncated before applying
// the operation.
return x << y;
}
function r(uint8 y) public returns (bytes20) {
bytes20 x;
assembly { x := "12345678901234567890abcde" }
return x >> y;
}
}
// ====
// compileViaYul: false
// ----
// l(uint8): 64 -> 0x3930313233343536373839300000000000000000000000000000000000000000
// r(uint8): 64 -> 0x313233343536373839303132000000000000000000000000

View File

@ -0,0 +1,19 @@
contract C {
function l(uint8 y) public returns (bytes20) {
bytes20 x;
assembly { x := "12345678901234567890abcde" }
// When compiling via IR, `x` is truncated before applying
// the operation.
return x << y;
}
function r(uint8 y) public returns (bytes20) {
bytes20 x;
assembly { x := "12345678901234567890abcde" }
return x >> y;
}
}
// ====
// compileViaYul: true
// ----
// l(uint8): 64 -> 0x3930313233343536373839306162636465000000000000000000000000000000
// r(uint8): 64 -> 0x313233343536373839303132000000000000000000000000