Skip to content

Commit 4f25bcf

Browse files
committed
fixup! Additional test coverage for named parameters
1 parent d08ff02 commit 4f25bcf

4 files changed

Lines changed: 222 additions & 0 deletions
Lines changed: 50 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,50 @@
1+
error IntWidening(uint256 a, uint256 b);
2+
error TwoStrings(string a, string b);
3+
error StringAndUint(string a, uint256 b);
4+
error BytesAndBool(bytes a, bool b);
5+
error MixedDynamic(string a, uint256 b, bytes c, bool d);
6+
error AddressConversion(address a, uint256 b);
7+
error SmallInts(uint8 a, uint16 b, uint256 c);
8+
9+
contract C {
10+
function intWidening() external pure {
11+
require(false, IntWidening({b: 200, a: 1}));
12+
}
13+
14+
function twoStringsUnordered() external pure {
15+
require(false, TwoStrings({b: "longer string value", a: "short"}));
16+
}
17+
function twoStringsOrdered() external pure {
18+
require(false, TwoStrings({a: "short", b: "longer string value"}));
19+
}
20+
21+
function stringAndUint() external pure {
22+
require(false, StringAndUint({b: 42, a: "hello"}));
23+
}
24+
25+
function bytesAndBool() external pure {
26+
require(false, BytesAndBool({b: true, a: hex"deadbeef"}));
27+
}
28+
29+
function mixedDynamic() external pure {
30+
require(false, MixedDynamic({d: true, c: hex"cafe", b: 7, a: "test"}));
31+
}
32+
33+
function addressConversion() external pure {
34+
require(false, AddressConversion({b: 99, a: address(0x1234)}));
35+
}
36+
37+
function smallInts() external pure {
38+
require(false, SmallInts({c: 300, b: 200, a: 1}));
39+
}
40+
}
41+
42+
// ----
43+
// intWidening() -> FAILURE, hex"57685228", 1, 200
44+
// twoStringsUnordered() -> FAILURE, hex"16b9a491", 0x40, 0x80, 5, "short", 19, "longer string value"
45+
// twoStringsOrdered() -> FAILURE, hex"16b9a491", 0x40, 0x80, 5, "short", 19, "longer string value"
46+
// stringAndUint() -> FAILURE, hex"81a3bbac", 0x40, 42, 5, "hello"
47+
// bytesAndBool() -> FAILURE, hex"ea504c15", 0x40, 1, 4, left(0xdeadbeef)
48+
// mixedDynamic() -> FAILURE, hex"e45ff7f0", 0x80, 7, 0xc0, 1, 4, "test", 2, left(0xcafe)
49+
// addressConversion() -> FAILURE, hex"6366476b", 0x1234, 99
50+
// smallInts() -> FAILURE, hex"641a758d", 1, 200, 300
Lines changed: 61 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,61 @@
1+
error StringAndUint(string a, uint256 b);
2+
error TwoStrings(string a, string b);
3+
error BytesAndUint(bytes a, uint256 b);
4+
error MixedLocations(string a, uint256 b, bytes c);
5+
6+
contract C {
7+
string storedString = "from storage";
8+
bytes storedBytes = hex"aabbccdd";
9+
10+
function storageString() external view {
11+
require(false, StringAndUint({b: 42, a: storedString}));
12+
}
13+
14+
function memoryString() external pure {
15+
string memory s = "from memory";
16+
require(false, StringAndUint({b: 42, a: s}));
17+
}
18+
19+
function calldataString(string calldata s) external pure {
20+
require(false, StringAndUint({b: 42, a: s}));
21+
}
22+
23+
function storageAndMemoryStrings() external view {
24+
string memory m = "from memory";
25+
require(false, TwoStrings({b: m, a: storedString}));
26+
}
27+
28+
function storageBytes() external view {
29+
require(false, BytesAndUint({b: 99, a: storedBytes}));
30+
}
31+
32+
function memoryBytes() external pure {
33+
bytes memory b = hex"aabbccdd";
34+
require(false, BytesAndUint({b: 99, a: b}));
35+
}
36+
37+
function calldataBytes(bytes calldata b) external pure {
38+
require(false, BytesAndUint({b: 99, a: b}));
39+
}
40+
41+
function mixedLocations() external view {
42+
bytes memory b = hex"cafe";
43+
require(false, MixedLocations({c: b, b: 7, a: storedString}));
44+
}
45+
46+
function calldataViaMemory(string calldata s) external pure {
47+
string memory m = s;
48+
require(false, StringAndUint({b: 42, a: m}));
49+
}
50+
}
51+
52+
// ----
53+
// storageString() -> FAILURE, hex"81a3bbac", 0x40, 42, 12, "from storage"
54+
// memoryString() -> FAILURE, hex"81a3bbac", 0x40, 42, 11, "from memory"
55+
// calldataString(string): 0x20, 13, "from calldata" -> FAILURE, hex"81a3bbac", 0x40, 42, 13, "from calldata"
56+
// storageAndMemoryStrings() -> FAILURE, hex"16b9a491", 0x40, 0x80, 12, "from storage", 11, "from memory"
57+
// storageBytes() -> FAILURE, hex"2d6fd48a", 0x40, 99, 4, left(0xaabbccdd)
58+
// memoryBytes() -> FAILURE, hex"2d6fd48a", 0x40, 99, 4, left(0xaabbccdd)
59+
// calldataBytes(bytes): 0x20, 4, left(0xaabbccdd) -> FAILURE, hex"2d6fd48a", 0x40, 99, 4, left(0xaabbccdd)
60+
// mixedLocations() -> FAILURE, hex"f8ce5df5", 0x60, 7, 0xa0, 12, "from storage", 2, left(0xcafe)
61+
// calldataViaMemory(string): 0x20, 13, "from calldata" -> FAILURE, hex"81a3bbac", 0x40, 42, 13, "from calldata"
Lines changed: 50 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,50 @@
1+
error IntWidening(uint256 a, uint256 b);
2+
error TwoStrings(string a, string b);
3+
error StringAndUint(string a, uint256 b);
4+
error BytesAndBool(bytes a, bool b);
5+
error MixedDynamic(string a, uint256 b, bytes c, bool d);
6+
error AddressConversion(address a, uint256 b);
7+
error SmallInts(uint8 a, uint16 b, uint256 c);
8+
9+
contract C {
10+
function intWidening() external pure {
11+
revert IntWidening({b: 200, a: 1});
12+
}
13+
14+
function twoStringsUnordered() external pure {
15+
revert TwoStrings({b: "longer string value", a: "short"});
16+
}
17+
function twoStringsOrdered() external pure {
18+
revert TwoStrings({a: "short", b: "longer string value"});
19+
}
20+
21+
function stringAndUint() external pure {
22+
revert StringAndUint({b: 42, a: "hello"});
23+
}
24+
25+
function bytesAndBool() external pure {
26+
revert BytesAndBool({b: true, a: hex"deadbeef"});
27+
}
28+
29+
function mixedDynamic() external pure {
30+
revert MixedDynamic({d: true, c: hex"cafe", b: 7, a: "test"});
31+
}
32+
33+
function addressConversion() external pure {
34+
revert AddressConversion({b: 99, a: address(0x1234)});
35+
}
36+
37+
function smallInts() external pure {
38+
revert SmallInts({c: 300, b: 200, a: 1});
39+
}
40+
}
41+
42+
// ----
43+
// intWidening() -> FAILURE, hex"57685228", 1, 200
44+
// twoStringsUnordered() -> FAILURE, hex"16b9a491", 0x40, 0x80, 5, "short", 19, "longer string value"
45+
// twoStringsOrdered() -> FAILURE, hex"16b9a491", 0x40, 0x80, 5, "short", 19, "longer string value"
46+
// stringAndUint() -> FAILURE, hex"81a3bbac", 0x40, 42, 5, "hello"
47+
// bytesAndBool() -> FAILURE, hex"ea504c15", 0x40, 1, 4, left(0xdeadbeef)
48+
// mixedDynamic() -> FAILURE, hex"e45ff7f0", 0x80, 7, 0xc0, 1, 4, "test", 2, left(0xcafe)
49+
// addressConversion() -> FAILURE, hex"6366476b", 0x1234, 99
50+
// smallInts() -> FAILURE, hex"641a758d", 1, 200, 300
Lines changed: 61 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,61 @@
1+
error StringAndUint(string a, uint256 b);
2+
error TwoStrings(string a, string b);
3+
error BytesAndUint(bytes a, uint256 b);
4+
error MixedLocations(string a, uint256 b, bytes c);
5+
6+
contract C {
7+
string storedString = "from storage";
8+
bytes storedBytes = hex"aabbccdd";
9+
10+
function storageString() external view {
11+
revert StringAndUint({b: 42, a: storedString});
12+
}
13+
14+
function memoryString() external pure {
15+
string memory s = "from memory";
16+
revert StringAndUint({b: 42, a: s});
17+
}
18+
19+
function calldataString(string calldata s) external pure {
20+
revert StringAndUint({b: 42, a: s});
21+
}
22+
23+
function storageAndMemoryStrings() external view {
24+
string memory m = "from memory";
25+
revert TwoStrings({b: m, a: storedString});
26+
}
27+
28+
function storageBytes() external view {
29+
revert BytesAndUint({b: 99, a: storedBytes});
30+
}
31+
32+
function memoryBytes() external pure {
33+
bytes memory b = hex"aabbccdd";
34+
revert BytesAndUint({b: 99, a: b});
35+
}
36+
37+
function calldataBytes(bytes calldata b) external pure {
38+
revert BytesAndUint({b: 99, a: b});
39+
}
40+
41+
function mixedLocations() external view {
42+
bytes memory b = hex"cafe";
43+
revert MixedLocations({c: b, b: 7, a: storedString});
44+
}
45+
46+
function calldataViaMemory(string calldata s) external pure {
47+
string memory m = s;
48+
revert StringAndUint({b: 42, a: m});
49+
}
50+
}
51+
52+
// ----
53+
// storageString() -> FAILURE, hex"81a3bbac", 0x40, 42, 12, "from storage"
54+
// memoryString() -> FAILURE, hex"81a3bbac", 0x40, 42, 11, "from memory"
55+
// calldataString(string): 0x20, 13, "from calldata" -> FAILURE, hex"81a3bbac", 0x40, 42, 13, "from calldata"
56+
// storageAndMemoryStrings() -> FAILURE, hex"16b9a491", 0x40, 0x80, 12, "from storage", 11, "from memory"
57+
// storageBytes() -> FAILURE, hex"2d6fd48a", 0x40, 99, 4, left(0xaabbccdd)
58+
// memoryBytes() -> FAILURE, hex"2d6fd48a", 0x40, 99, 4, left(0xaabbccdd)
59+
// calldataBytes(bytes): 0x20, 4, left(0xaabbccdd) -> FAILURE, hex"2d6fd48a", 0x40, 99, 4, left(0xaabbccdd)
60+
// mixedLocations() -> FAILURE, hex"f8ce5df5", 0x60, 7, 0xa0, 12, "from storage", 2, left(0xcafe)
61+
// calldataViaMemory(string): 0x20, 13, "from calldata" -> FAILURE, hex"81a3bbac", 0x40, 42, 13, "from calldata"

0 commit comments

Comments
 (0)