Enabling triggered tests and adding one new for deleting struct

This commit is contained in:
Djordje Mijovic 2020-09-18 13:45:11 +02:00
parent 700390a68b
commit 4e8275df2c
5 changed files with 98 additions and 0 deletions

View File

@ -0,0 +1,24 @@
contract C {
struct S {
uint16 v;
S[] x;
}
uint8[77] padding;
S s;
constructor() {
s.v = 21;
s.x.push(); s.x.push(); s.x.push();
s.x[0].v = 101; s.x[1].v = 102; s.x[2].v = 103;
}
function f() public returns (uint256 a, uint256 b, uint256 c, uint256 d) {
S storage sptr1 = s.x[0];
S storage sptr2 = s.x[1];
S storage sptr3 = s.x[2];
uint256 slot1; uint256 slot2; uint256 slot3;
assembly { slot1 := sptr1.slot slot2 := sptr2.slot slot3 := sptr3.slot }
delete s;
assembly { a := sload(s.slot) b := sload(slot1) c := sload(slot2) d := sload(slot3) }
}
}
// ----
// f() -> 0, 0, 0, 0

View File

@ -15,5 +15,7 @@ contract C {
}
}
// ====
// compileViaYul: also
// ----
// f() -> 1

View File

@ -0,0 +1,23 @@
contract C {
struct S {
uint256 x;
uint128 y;
uint32 z;
}
uint8 b = 23;
S s;
uint8 a = 17;
function f() public {
s.x = 42; s.y = 42; s.y = 42;
delete s;
assert(s.x == 0);
assert(s.y == 0);
assert(s.z == 0);
assert(b == 23);
assert(a == 17);
}
}
// ====
// compileViaYul: also
// ----
// f() ->

View File

@ -0,0 +1,47 @@
pragma experimental ABIEncoderV2;
contract C {
struct S {
uint128 a;
uint256[] x;
uint240 b;
}
uint8 b = 23;
S s;
uint8 a = 17;
function f() public {
delete s;
s.x.push(42); s.x.push(42); s.x.push(42);
delete s;
assert(s.x.length == 0);
uint256[] storage x = s.x;
assembly { sstore(x.slot, 3) }
assert(s.x[0] == 0);
assert(s.x[1] == 0);
assert(s.x[2] == 0);
assert(b == 23);
assert(a == 17);
}
function g() public {
delete s;
s.x.push(42); s.x.push(42); s.x.push(42);
s.a = 1; s.b = 2;
delete s.x;
assert(s.x.length == 0);
uint256[] storage x = s.x;
assembly { sstore(x.slot, 3) }
assert(s.x[0] == 0);
assert(s.x[1] == 0);
assert(s.x[2] == 0);
assert(b == 23);
assert(a == 17);
assert(s.a == 1);
assert(s.b == 2);
}
}
// ====
// compileViaYul: also
// ----
// f() ->
// g() ->

View File

@ -14,5 +14,7 @@ contract test {
}
}
// ====
// compileViaYul: also
// ----
// deleteIt() -> 0