Implement array push and pop for yul and replace assignments in via yul tests.

This commit is contained in:
Daniel Kirchner
2019-11-20 12:04:42 +01:00
committed by Erik Kundt
parent 2d2fb547e7
commit 372df6b9e1
9 changed files with 192 additions and 51 deletions
@@ -2,7 +2,9 @@ contract C {
uint[] storageArray;
function test_indices(uint256 len) public
{
storageArray = new uint[](len);
// storageArray = new uint[](len);
while (storageArray.length < len) storageArray.push();
while (storageArray.length > len) storageArray.pop();
for (uint i = 0; i < len; i++)
storageArray[i] = i + 1;
@@ -10,6 +12,8 @@ contract C {
require(storageArray[i] == i + 1);
}
}
// ====
// compileViaYul: true
// ----
// test_indices(uint256): 1 ->
// test_indices(uint256): 129 ->
@@ -0,0 +1,22 @@
contract C {
uint[] storageArray;
function test_boundary_check(uint256 len, uint256 access) public returns (uint256)
{
// storageArray = new uint[](len);
while(storageArray.length < len) storageArray.push();
while(storageArray.length > len) storageArray.pop();
return storageArray[access];
}
}
// ====
// compileViaYul: true
// ----
// test_boundary_check(uint256, uint256): 10, 11 -> FAILURE
// test_boundary_check(uint256, uint256): 10, 9 -> 0
// test_boundary_check(uint256, uint256): 1, 9 -> FAILURE
// test_boundary_check(uint256, uint256): 1, 1 -> FAILURE
// test_boundary_check(uint256, uint256): 10, 10 -> FAILURE
// test_boundary_check(uint256, uint256): 256, 256 -> FAILURE
// test_boundary_check(uint256, uint256): 256, 255 -> 0
// test_boundary_check(uint256, uint256): 256, 0xFFFF -> FAILURE
// test_boundary_check(uint256, uint256): 256, 2 -> 0
@@ -1,18 +0,0 @@
contract C {
uint[] storageArray;
function test_boundery_check(uint256 len, uint256 access) public returns (uint256)
{
storageArray = new uint[](len);
return storageArray[access];
}
}
// ----
// test_boundery_check(uint256, uint256): 10, 11 -> FAILURE
// test_boundery_check(uint256, uint256): 10, 9 -> 0
// test_boundery_check(uint256, uint256): 1, 9 -> FAILURE
// test_boundery_check(uint256, uint256): 1, 1 -> FAILURE
// test_boundery_check(uint256, uint256): 10, 10 -> FAILURE
// test_boundery_check(uint256, uint256): 256, 256 -> FAILURE
// test_boundery_check(uint256, uint256): 256, 255 -> 0
// test_boundery_check(uint256, uint256): 256, 0xFFFF -> FAILURE
// test_boundery_check(uint256, uint256): 256, 2 -> 0
@@ -2,14 +2,18 @@ contract C {
uint[] storageArray;
function test_zeroed_indicies(uint256 len) public
{
storageArray = new uint[](len);
//storageArray = new uint[](len);
while(storageArray.length < len) storageArray.push();
while(storageArray.length > len) storageArray.pop();
for (uint i = 0; i < len; i++)
storageArray[i] = i + 1;
if (len > 3)
{
storageArray = new uint[](3);
//storageArray = new uint[](3);
while(storageArray.length > 0) storageArray.pop();
while(storageArray.length < 3) storageArray.push();
for (uint i = 3; i < len; i++)
{
@@ -25,8 +29,10 @@ contract C {
}
storageArray = new uint[](0);
storageArray = new uint[](len);
//storageArray = new uint[](0);
while(storageArray.length > 0) storageArray.pop();
//storageArray = new uint[](len);
while(storageArray.length < len) storageArray.push();
for (uint i = 0; i < len; i++)
{
@@ -41,6 +47,8 @@ contract C {
}
}
}
// ====
// compileViaYul: true
// ----
// test_zeroed_indicies(uint256): 1 ->
// test_zeroed_indicies(uint256): 5 ->
@@ -1,8 +1,8 @@
contract C {
uint[] storageArray;
function set_get_length(uint256 len) public returns (uint256)
{
storageArray = new uint[](len);
function set_get_length(uint256 len) public returns (uint256) {
while(storageArray.length < len)
storageArray.push();
return storageArray.length;
}
}
@@ -13,7 +13,6 @@ contract C {
// set_get_length(uint256): 1 -> 1
// set_get_length(uint256): 10 -> 10
// set_get_length(uint256): 20 -> 20
// set_get_length(uint256): 0 -> 0
// set_get_length(uint256): 0xFF -> 0xFF
// set_get_length(uint256): 0xFFF -> 0xFFF
// set_get_length(uint256): 0xFFFF -> FAILURE # Out-of-gas #
@@ -0,0 +1,20 @@
contract C {
uint[] storageArray;
function set_get_length(uint256 len) public returns (uint256) {
while(storageArray.length < len)
storageArray.push();
while(storageArray.length > 0)
storageArray.pop();
return storageArray.length;
}
}
// ====
// compileViaYul: true
// ----
// set_get_length(uint256): 0 -> 0
// set_get_length(uint256): 1 -> 0
// set_get_length(uint256): 10 -> 0
// set_get_length(uint256): 20 -> 0
// set_get_length(uint256): 0xFF -> 0
// set_get_length(uint256): 0xFFF -> 0
// set_get_length(uint256): 0xFFFF -> FAILURE # Out-of-gas #