Tests for copying structs between data locations

This commit is contained in:
wechman 2022-09-09 06:57:27 +02:00
parent dfe8fce369
commit 0eae9e70ff
4 changed files with 81 additions and 0 deletions

View File

@ -0,0 +1,16 @@
pragma abicoder v2;
contract C {
struct S {
uint8[1] x;
uint8[] y;
}
function test(S calldata s) public returns (S memory) {
return s;
}
}
// ----
// test((uint8[1],uint8[])): 0x20, 3, 0x40, 2, 7, 11 -> 0x20, 3, 0x40, 2, 7, 11
// test((uint8[1],uint8[])): 0x20, 3, 0x40, 3, 17, 19, 23 -> 0x20, 3, 0x40, 3, 17, 19, 23

View File

@ -0,0 +1,22 @@
pragma abicoder v2;
contract C {
struct S {
uint8[1] x;
uint8[] y;
}
S s;
function test(S calldata src) public {
s = src;
require(s.x[0] == 3);
require(s.y.length == 2);
require(s.y[0] == 7);
require(s.y[1] == 11);
}
}
// ----
// test((uint8[1],uint8[])): 0x20, 3, 0x40, 2, 7, 11

View File

@ -0,0 +1,16 @@
pragma abicoder v2;
contract C {
struct S {
uint8[1] x;
uint8[] y;
}
function test(S memory s) public returns (S memory r) {
return r;
}
}
// ----
// test((uint8[1],uint8[])): 0x20, 3, 0x40, 2, 7, 11 -> 0x20, 0, 0x40, 0
// test((uint8[1],uint8[])): 0x20, 3, 0x40, 3, 17, 19, 23 -> 0x20, 0, 0x40, 0

View File

@ -0,0 +1,27 @@
contract C {
struct S {
uint8[1] x;
uint8[] y;
}
S src;
S dst;
constructor() {
src.x = [3];
src.y.push(7);
src.y.push(11);
}
function test() public {
dst = src;
require(dst.x[0] == 3);
require(dst.y.length == 2);
require(dst.y[0] == 7);
require(dst.y[1] == 11);
}
}
// ----
// test()