Skip to content

Commit a6503ed

Browse files
committed
Additional test coverage for named parameters
1 parent da88516 commit a6503ed

File tree

5 files changed

+105
-6
lines changed

5 files changed

+105
-6
lines changed
Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,18 @@
1+
contract C {
2+
event E(uint256 a, uint256 b, string c);
3+
4+
function trigger() public {
5+
emit E(2, 7, "event");
6+
emit E({b: 7, a: 2, c: "event"});
7+
emit E({a: 2, c: "event", b: 7});
8+
emit E({c: "event", a: 2, b: 7});
9+
emit E({a: 2, b: 7, c: "event"});
10+
}
11+
}
12+
// ----
13+
// trigger() ->
14+
// ~ emit E(uint256,uint256,string): 0x02, 0x07, 0x60, 0x05, "event"
15+
// ~ emit E(uint256,uint256,string): 0x02, 0x07, 0x60, 0x05, "event"
16+
// ~ emit E(uint256,uint256,string): 0x02, 0x07, 0x60, 0x05, "event"
17+
// ~ emit E(uint256,uint256,string): 0x02, 0x07, 0x60, 0x05, "event"
18+
// ~ emit E(uint256,uint256,string): 0x02, 0x07, 0x60, 0x05, "event"
Lines changed: 17 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,19 @@
1-
contract test {
2-
function a(uint a, uint b, uint c) public returns (uint r) { r = a * 100 + b * 10 + c * 1; }
3-
function b() public returns (uint r) { r = a({a: 1, b: 2, c: 3}); }
4-
function c() public returns (uint r) { r = a({b: 2, c: 3, a: 1}); }
1+
contract C {
2+
function internalFunction(uint a, uint b, uint c) internal returns (uint r) { r = a * 100 + b * 10 + c * 1; }
3+
function publicFunction(uint a, uint b, uint c) public returns (uint r) { r = a * 100 + b * 10 + c * 1; }
4+
function externalFunction(uint a, uint b, uint c) public returns (uint r) { r = a * 100 + b * 10 + c * 1; }
5+
6+
function internalOrdered() public returns (uint r) { r = internalFunction({a: 1, b: 2, c: 3}); }
7+
function internalUnordered() public returns (uint r) { r = internalFunction({b: 2, c: 3, a: 1}); }
8+
function publicOrdered() public returns (uint r) { r = publicFunction({a: 1, b: 2, c: 3}); }
9+
function publicUnordered() public returns (uint r) { r = publicFunction({b: 2, c: 3, a: 1}); }
10+
function externalOrdered() public returns (uint r) { r = externalFunction({a: 1, b: 2, c: 3}); }
11+
function externalUnordered() public returns (uint r) { r = publicFunction({b: 2, c: 3, a: 1}); }
512
}
613
// ----
7-
// b() -> 123
8-
// c() -> 123
14+
// internalOrdered() -> 123
15+
// internalUnordered() -> 123
16+
// publicOrdered() -> 123
17+
// publicUnordered() -> 123
18+
// externalOrdered() -> 123
19+
// externalUnordered() -> 123
Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,20 @@
1+
contract A {
2+
function f(uint256 a, uint256 b, uint256 c) internal virtual returns (uint256) {
3+
return 1 * a + 2 * b + 3 * c;
4+
}
5+
}
6+
7+
contract B is A {
8+
function f(uint256 b, uint256 a, uint256 c) internal override returns (uint256) {
9+
return 0;
10+
}
11+
function baseOrdered() public returns (uint256) {
12+
return A.f({a: 1, b: 2, c: 3});
13+
}
14+
function baseUnordered() public returns (uint256) {
15+
return A.f({c: 3, a: 1, b: 2});
16+
}
17+
}
18+
// ----
19+
// baseOrdered() -> 14
20+
// baseUnordered() -> 14
Lines changed: 29 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,29 @@
1+
library L {
2+
function fi(uint256 a, uint256 b, uint256 c) internal returns (uint256) {
3+
return 1 * a + 2 * b + 3 * c;
4+
}
5+
function fe(uint256 a, uint256 b, uint256 c) external returns (uint256) {
6+
return 1 * a + 2 * b + 3 * c;
7+
}
8+
}
9+
10+
contract C {
11+
function internalOrdered() public returns (uint256) {
12+
return L.fi({a: 1, b: 2, c:3});
13+
}
14+
function internalUnordered() public returns (uint256) {
15+
return L.fi({c: 3, a: 1, b: 2});
16+
}
17+
function externalOrdered() external returns (uint256) {
18+
return L.fe({a: 1, b: 2, c:3});
19+
}
20+
function externalUnordered() public returns (uint256) {
21+
return L.fe({c: 3, a: 1, b: 2});
22+
}
23+
}
24+
// ----
25+
// library: L
26+
// internalOrdered() -> 14
27+
// internalUnordered() -> 14
28+
// externalOrdered() -> 14
29+
// externalUnordered() -> 14
Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,21 @@
1+
library L {
2+
function multiply(uint256 self, uint256 x, uint256 y) internal pure returns (uint256, uint256) {
3+
return (self * x, self * y);
4+
}
5+
}
6+
7+
contract C {
8+
using L for uint256;
9+
10+
function ordered() external pure returns (uint256, uint256) {
11+
uint256 value = 1;
12+
return value.multiply({x: 2, y: 7});
13+
}
14+
function unordered() external pure returns (uint256, uint256) {
15+
uint256 value = 1;
16+
return value.multiply({y: 7, x: 2});
17+
}
18+
}
19+
// ----
20+
// ordered() -> 2, 7
21+
// unordered() -> 2, 7

0 commit comments

Comments
 (0)