Adding semantic tests for bytes.concat.

This commit is contained in:
Djordje Mijovic 2021-02-22 17:45:11 +01:00
parent 4e75c6c3e8
commit d0a854b312
6 changed files with 113 additions and 0 deletions

View File

@ -0,0 +1,30 @@
contract C {
function f(bytes memory a, bytes memory b) public returns (bytes memory) {
return bytes.concat(a, b);
}
}
// ====
// compileViaYul: also
// ----
// f(bytes, bytes): 0x40, 0x80, 32, "abcdabcdabcdabcdabcdabcdabcdabcd", 5, "bcdef" -> 0x20, 37, "abcdabcdabcdabcdabcdabcdabcdabcd", "bcdef"
//
// f(bytes, bytes):
// 0x40, 0xa0, 64, "abcdabcdabcdabcdabcdabcdabcdabcd", "abcdabcdabcdabcdabcdabcdabcdabcd", 5, "bcdef"
// ->
// 0x20, 69, "abcdabcdabcdabcdabcdabcdabcdabcd", "abcdabcdabcdabcdabcdabcdabcdabcd", "bcdef"
// f(bytes, bytes): 0x40, 0x80, 3, "abc", 3, "def" -> 0x20, 6, "abcdef"
//
// f(bytes, bytes):
// 0x40, 0xa0, 34, "abcdabcdabcdabcdabcdabcdabcdabcd", "ab", 30, "cdabcdabcdabcdabcdabcdabcdabcd"
// ->
// 0x20, 64, "abcdabcdabcdabcdabcdabcdabcdabcd", "abcdabcdabcdabcdabcdabcdabcdabcd"
//
// f(bytes, bytes):
// 0x40, 0xa0, 34, "abcdabcdabcdabcdabcdabcdabcdabcd", "ab", 34, "cdabcdabcdabcdabcdabcdabcdabcdab", "cd"
// ->
// 0x20, 68, "abcdabcdabcdabcdabcdabcdabcdabcd", "abcdabcdabcdabcdabcdabcdabcdabcd", "abcd"
//
// f(bytes, bytes):
// 0x40, 0x80, 3, "abc", 30, "dabcdabcdabcdabcdabcdabcdabcda"
// ->
// 0x20, 33, "abcdabcdabcdabcdabcdabcdabcdabcd", "a"

View File

@ -0,0 +1,10 @@
contract C {
function f(bytes memory a, bytes memory b, bytes memory c) public returns (bytes memory) {
return bytes.concat(a, b, c);
}
}
// ====
// compileViaYul: also
// ----
// f(bytes, bytes, bytes): 0x60, 0xa0, 0xe0, 32, "abcdabcdabcdabcdabcdabcdabcdabcd", 5, "bcdef", 3, "abc" -> 0x20, 40, "abcdabcdabcdabcdabcdabcdabcdabcd", "bcdefabc"
// f(bytes, bytes, bytes): 0x60, 0xa0, 0xe0, 3, "abc", 2, "de", 3, "fgh" -> 0x20, 8, "abcdefgh"

View File

@ -0,0 +1,18 @@
contract C {
function f(bytes memory a, bytes memory b) public returns (bytes32) {
return keccak256(bytes.concat(a, b));
}
function h(bytes memory a) internal returns (uint256) {
return a.length;
}
function g(bytes memory a, bytes memory b) public returns (uint256) {
return h(bytes.concat(a, b));
}
}
// ====
// compileViaYul: also
// ----
// f(bytes,bytes): 0x40, 0x80, 32, "abcdabcdabcdabcdabcdabcdabcdabcd", 5, "bcdef" -> 0x1106e19b6f06d1cce71c2d816754f83dfa5b95df958c5cbf12b7c472320c427c
// g(bytes,bytes): 0x40, 0x80, 32, "abcdabcdabcdabcdabcdabcdabcdabcd", 5, "bcdef" -> 37

View File

@ -0,0 +1,37 @@
contract C {
bytes s = "bcdef";
function f(bytes memory a) public returns (bytes memory) {
return bytes.concat(a, "bcdef");
}
function g(bytes calldata a) public returns (bytes memory) {
return bytes.concat(a, "abcdefghabcdefghabcdefghabcdefghab");
}
function h(bytes calldata a) public returns (bytes memory) {
return bytes.concat(a, s);
}
function j(bytes calldata a) public returns (bytes memory) {
bytes storage ref = s;
return bytes.concat(a, ref, s);
}
function k(bytes calldata a, string memory b) public returns (bytes memory) {
return bytes.concat(a, bytes(b));
}
function slice(bytes calldata a) public returns (bytes memory) {
require(a.length > 2, "");
return bytes.concat(a[:2], a[2:]);
}
function strParam(string calldata a) public returns (bytes memory) {
return bytes.concat(bytes(a), "bcdef");
}
}
// ====
// compileViaYul: also
// ----
// f(bytes): 0x20, 32, "abcdabcdabcdabcdabcdabcdabcdabcd" -> 0x20, 37, "abcdabcdabcdabcdabcdabcdabcdabcd", "bcdef"
// g(bytes): 0x20, 32, "abcdabcdabcdabcdabcdabcdabcdabcd" -> 0x20, 66, "abcdabcdabcdabcdabcdabcdabcdabcd", "abcdefghabcdefghabcdefghabcdefgh", "ab"
// h(bytes): 0x20, 32, "abcdabcdabcdabcdabcdabcdabcdabcd" -> 0x20, 37, "abcdabcdabcdabcdabcdabcdabcdabcd", "bcdef"
// j(bytes): 0x20, 32, "abcdabcdabcdabcdabcdabcdabcdabcd" -> 0x20, 42, "abcdabcdabcdabcdabcdabcdabcdabcd", "bcdefbcdef"
// k(bytes, string): 0x40, 0x80, 32, "abcdabcdabcdabcdabcdabcdabcdabcd", 5, "bcdef" -> 0x20, 37, "abcdabcdabcdabcdabcdabcdabcdabcd", "bcdef"
// slice(bytes): 0x20, 4, "abcd" -> 0x20, 4, "abcd"
// strParam(string): 0x20, 32, "abcdabcdabcdabcdabcdabcdabcdabcd" -> 0x20, 37, "abcdabcdabcdabcdabcdabcdabcdabcd", "bcdef"

View File

@ -0,0 +1,9 @@
contract C {
function f() public returns (bytes memory) {
return bytes.concat();
}
}
// ====
// compileViaYul: also
// ----
// f() -> 0x20, 0

View File

@ -0,0 +1,9 @@
contract C {
function f(bytes memory a, bytes memory b, bytes memory c) public returns (bytes memory) {
return bytes.concat(bytes.concat(a, b), c);
}
}
// ====
// compileViaYul: also
// ----
// f(bytes, bytes, bytes): 0x60, 0x60, 0x60, 2, "ab" -> 0x20, 6, "ababab"