Add tests for ABI coding empty strings and string literals

Include the case of revert("")
This commit is contained in:
Alex Beregszaszi 2020-11-03 18:29:53 +00:00
parent 24cce56215
commit 39f6286e9f
6 changed files with 127 additions and 0 deletions

View File

@ -0,0 +1,34 @@
contract C {
function f1() public returns (bytes memory) {
return abi.encode("");
}
function f2(string calldata msg) public returns (bytes memory) {
return abi.encode(msg);
}
function g1() public returns (bytes memory) {
return abi.encodePacked("");
}
function g2(string calldata msg) public returns (bytes memory) {
return abi.encodePacked(msg);
}
function h1() public returns (bytes memory) {
return abi.encodeWithSelector(0x00000001, "");
}
function h2(string calldata msg) public returns (bytes memory) {
return abi.encodeWithSelector(0x00000001, msg);
}
}
// ====
// ABIEncoderV1Only: true
// compileViaYul: false
// ----
// f1() -> 0x20, 0x60, 0x20, 0, 0
// f2(string): 0x20, 0 -> 0x20, 0x40, 0x20, 0
// f2(string): 0x20, 0, 0 -> 0x20, 0x40, 0x20, 0
// g1() -> 32, 0
// g2(string): 0x20, 0 -> 0x20, 0
// g2(string): 0x20, 0, 0 -> 0x20, 0
// h1() -> 0x20, 0x64, 26959946667150639794667015087019630673637144422540572481103610249216, 862718293348820473429344482784628181556388621521298319395315527974912, 0, 0
// h2(string): 0x20, 0 -> 0x20, 0x44, 26959946667150639794667015087019630673637144422540572481103610249216, 862718293348820473429344482784628181556388621521298319395315527974912, 0
// h2(string): 0x20, 0, 0 -> 0x20, 0x44, 26959946667150639794667015087019630673637144422540572481103610249216, 862718293348820473429344482784628181556388621521298319395315527974912, 0

View File

@ -0,0 +1,18 @@
pragma abicoder v1;
contract C {
function f() public {
revert("");
}
function g(string calldata msg) public {
revert(msg);
}
}
// ====
// ABIEncoderV1Only: true
// EVMVersion: >=byzantium
// compileViaYul: false
// revertStrings: debug
// ----
// f() -> FAILURE, hex"08c379a0", 0x20, 0, ""
// g(string): 0x20, 0, "" -> FAILURE, hex"08c379a0", 0x20, 0
// g(string): 0x20, 0 -> FAILURE, hex"08c379a0", 0x20, 0

View File

@ -0,0 +1,18 @@
contract C {
function f() public {
revert("");
}
function g(string calldata msg) public {
revert(msg);
}
}
// ====
// ABIEncoderV1Only: true
// EVMVersion: >=byzantium
// compileViaYul: true
// revertStrings: debug
// ----
// f() -> FAILURE, hex"08c379a0", 0x20, 0
// g(string): "" -> FAILURE, hex"08c379a0", 0x20, 0
// g(string): 0x20, 0, "" -> FAILURE, hex"08c379a0", 0x20, 0
// g(string): 0x20, 0 -> FAILURE, hex"08c379a0", 0x20, 0

View File

@ -0,0 +1,18 @@
pragma experimental ABIEncoderV2;
contract C {
function f() public {
revert("");
}
function g(string calldata msg) public {
revert(msg);
}
}
// ====
// EVMVersion: >=byzantium
// compileViaYul: also
// revertStrings: debug
// ----
// f() -> FAILURE, hex"08c379a0", 0x20, 0
// g(string): "" -> FAILURE, hex"08c379a0", 0x20, 0
// g(string): 0x20, 0, "" -> FAILURE, hex"08c379a0", 0x20, 0
// g(string): 0x20, 0 -> FAILURE, hex"08c379a0", 0x20, 0

View File

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

View File

@ -0,0 +1,30 @@
contract C {
function f() public pure returns (string memory) {
return "";
}
function g(string calldata msg) public pure returns (string memory) {
return msg;
}
function h(string calldata msg, uint256 v) public pure returns (string memory, uint256) {
return (msg, v);
}
// Adjusting order of input/output intentionally.
function i(string calldata msg1, uint256 v, string calldata msg2) public pure returns (string memory, string memory, uint256) {
return (msg1, msg2, v);
}
function j(string calldata msg1, uint256 v) public pure returns (string memory, string memory, uint256) {
return (msg1, "", v);
}
}
// ====
// compileViaYul: also
// ----
// f() -> 0x20, 0
// g(string): 0x20, 0, "" -> 0x20, 0
// g(string): 0x20, 0 -> 0x20, 0
// h(string,uint256): 0x40, 0x888, 0, "" -> 0x40, 0x0888, 0
// h(string,uint256): 0x40, 0x888, 0 -> 0x40, 0x0888, 0
// i(string,uint256,string): 0x60, 0x888, 0x60, 0, "" -> 0x60, 0x80, 0x0888, 0, 0
// i(string,uint256,string): 0x60, 0x888, 0x60, 0 -> 0x60, 0x80, 0x0888, 0, 0
// j(string,uint256): 0x40, 0x888, 0, "" -> 0x60, 0x80, 0x0888, 0, 0
// j(string,uint256): 0x40, 0x888, 0 -> 0x60, 0x80, 0x0888, 0, 0