Skip to content

Commit 0eae9e7

Browse files
committed
Tests for copying structs between data locations
1 parent dfe8fce commit 0eae9e7

4 files changed

+81
-0
lines changed
Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,16 @@
1+
pragma abicoder v2;
2+
3+
contract C {
4+
struct S {
5+
uint8[1] x;
6+
uint8[] y;
7+
}
8+
9+
function test(S calldata s) public returns (S memory) {
10+
return s;
11+
}
12+
}
13+
14+
// ----
15+
// test((uint8[1],uint8[])): 0x20, 3, 0x40, 2, 7, 11 -> 0x20, 3, 0x40, 2, 7, 11
16+
// test((uint8[1],uint8[])): 0x20, 3, 0x40, 3, 17, 19, 23 -> 0x20, 3, 0x40, 3, 17, 19, 23
Lines changed: 22 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,22 @@
1+
pragma abicoder v2;
2+
3+
contract C {
4+
struct S {
5+
uint8[1] x;
6+
uint8[] y;
7+
}
8+
9+
S s;
10+
11+
function test(S calldata src) public {
12+
s = src;
13+
14+
require(s.x[0] == 3);
15+
require(s.y.length == 2);
16+
require(s.y[0] == 7);
17+
require(s.y[1] == 11);
18+
}
19+
}
20+
21+
// ----
22+
// test((uint8[1],uint8[])): 0x20, 3, 0x40, 2, 7, 11
Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,16 @@
1+
pragma abicoder v2;
2+
3+
contract C {
4+
struct S {
5+
uint8[1] x;
6+
uint8[] y;
7+
}
8+
9+
function test(S memory s) public returns (S memory r) {
10+
return r;
11+
}
12+
}
13+
14+
// ----
15+
// test((uint8[1],uint8[])): 0x20, 3, 0x40, 2, 7, 11 -> 0x20, 0, 0x40, 0
16+
// test((uint8[1],uint8[])): 0x20, 3, 0x40, 3, 17, 19, 23 -> 0x20, 0, 0x40, 0
Lines changed: 27 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,27 @@
1+
contract C {
2+
struct S {
3+
uint8[1] x;
4+
uint8[] y;
5+
}
6+
7+
S src;
8+
S dst;
9+
10+
constructor() {
11+
src.x = [3];
12+
src.y.push(7);
13+
src.y.push(11);
14+
}
15+
16+
function test() public {
17+
dst = src;
18+
19+
require(dst.x[0] == 3);
20+
require(dst.y.length == 2);
21+
require(dst.y[0] == 7);
22+
require(dst.y[1] == 11);
23+
}
24+
}
25+
26+
// ----
27+
// test()

0 commit comments

Comments
 (0)