Organizing array tests into more directories.

This commit is contained in:
Djordje Mijovic
2020-11-13 12:32:39 +01:00
parent 11033c9536
commit 31981bad12
39 changed files with 0 additions and 0 deletions
@@ -0,0 +1,20 @@
contract c {
bytes data;
function test1() external returns (bool) {
data = new bytes(100);
for (uint256 i = 0; i < data.length; i++) data[i] = bytes1(uint8(i));
delete data[94];
delete data[96];
delete data[98];
return
data[94] == 0 &&
uint8(data[95]) == 95 &&
data[96] == 0 &&
uint8(data[97]) == 97;
}
}
// ====
// compileViaYul: also
// ----
// test1() -> true
@@ -0,0 +1,37 @@
contract C {
bytes data;
function f() public returns (uint ret) {
data.push("a");
data.push("b");
delete data;
assembly {
ret := sload(data.slot)
}
}
function g() public returns (uint ret) {
assembly {
sstore(data.slot, 67)
}
data.push("a");
data.push("b");
assert(data.length == 35);
delete data;
assert(data.length == 0);
uint size = 999;
assembly {
size := sload(data.slot)
mstore(0, data.slot)
ret := sload(keccak256(0, 32))
}
assert(size == 0);
}
}
// ====
// compileViaYul: also
// ----
// f() -> 0
// g() -> 0
@@ -0,0 +1,17 @@
contract C {
function len() public returns (uint ret) {
uint[] memory data = new uint[](2);
data[0] = 234;
data[1] = 123;
delete data;
assembly {
ret := mload(data)
}
}
}
// ====
// compileViaYul: also
// ----
// len() -> 0
@@ -0,0 +1,22 @@
// Test for a bug where we did not increment the counter properly while deleting a dynamic array.
contract C {
struct S {
uint256 x;
uint256[] y;
}
S[] data;
function f() public returns (bool) {
S storage s1 = data.push();
s1.x = 2**200;
S storage s2 = data.push();
s2.x = 2**200;
delete data;
return true;
}
}
// ====
// compileViaYul: also
// ----
// f() -> true # This code interprets x as an array length and thus will go out of gas. neither of the two should throw due to out-of-bounds access #
@@ -0,0 +1,12 @@
contract c {
fallback() external { data = msg.data; }
function del() public returns (bool) { delete data; return true; }
bytes data;
}
// ====
// compileViaYul: also
// ----
// (): 7 ->
// storage: nonempty
// del(): 7 -> true
// storage: empty
@@ -0,0 +1,40 @@
contract C {
uint[] data;
function len() public returns (uint ret) {
data.push(234);
data.push(123);
delete data;
assembly {
ret := sload(data.slot)
}
}
function val() public returns (uint ret) {
assembly {
sstore(0, 2)
mstore(0, 0)
sstore(keccak256(0, 32), 234)
sstore(add(keccak256(0, 32), 1), 123)
}
assert(data[0] == 234);
assert(data[1] == 123);
delete data;
uint size = 999;
assembly {
size := sload(0)
mstore(0, 0)
ret := sload(keccak256(0, 32))
}
}
}
// ====
// compileViaYul: also
// ----
// len() -> 0
// val() -> 0
@@ -0,0 +1,18 @@
contract C {
uint120[] data;
function f() public returns (uint120, uint120, uint120) {
data.push(123);
data.push(234);
data.push(345);
delete data;
assembly {
sstore(data.slot, 3)
}
return (data[0], data[1], data[2]);
}
}
// ====
// compileViaYul: also
// ----
// f() -> 0, 0, 0