forked from ethereum/solidity
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Adding semantic tests for bytes.concat.
- Loading branch information
Showing
6 changed files
with
113 additions
and
0 deletions.
There are no files selected for viewing
30 changes: 30 additions & 0 deletions
30
test/libsolidity/semanticTests/array/concat/bytes_concat_2_args.sol
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -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" |
10 changes: 10 additions & 0 deletions
10
test/libsolidity/semanticTests/array/concat/bytes_concat_3_args.sol
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -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" |
18 changes: 18 additions & 0 deletions
18
test/libsolidity/semanticTests/array/concat/bytes_concat_as_argument.sol
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -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 |
37 changes: 37 additions & 0 deletions
37
test/libsolidity/semanticTests/array/concat/bytes_concat_different_types.sol
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -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" |
9 changes: 9 additions & 0 deletions
9
test/libsolidity/semanticTests/array/concat/bytes_concat_empty.sol
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,9 @@ | ||
contract C { | ||
function f() public returns (bytes memory) { | ||
return bytes.concat(); | ||
} | ||
} | ||
// ==== | ||
// compileViaYul: also | ||
// ---- | ||
// f() -> 0x20, 0 |
9 changes: 9 additions & 0 deletions
9
test/libsolidity/semanticTests/array/concat/bytes_concat_nested.sol
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -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" |