mirror of
https://github.com/ethereum/solidity
synced 2023-10-03 13:03:40 +00:00
Adds and updates Yul tests for push() and pop().
This commit is contained in:
parent
372df6b9e1
commit
01705efb70
@ -2,9 +2,10 @@ contract C {
|
||||
uint[] storageArray;
|
||||
function test_indices(uint256 len) public
|
||||
{
|
||||
// storageArray = new uint[](len);
|
||||
while (storageArray.length < len) storageArray.push();
|
||||
while (storageArray.length > len) storageArray.pop();
|
||||
while (storageArray.length < len)
|
||||
storageArray.push();
|
||||
while (storageArray.length > len)
|
||||
storageArray.pop();
|
||||
for (uint i = 0; i < len; i++)
|
||||
storageArray[i] = i + 1;
|
||||
|
||||
|
@ -2,9 +2,10 @@ 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();
|
||||
while(storageArray.length < len)
|
||||
storageArray.push();
|
||||
while(storageArray.length > len)
|
||||
storageArray.pop();
|
||||
return storageArray[access];
|
||||
}
|
||||
}
|
||||
|
@ -2,18 +2,20 @@ contract C {
|
||||
uint[] storageArray;
|
||||
function test_zeroed_indicies(uint256 len) public
|
||||
{
|
||||
//storageArray = new uint[](len);
|
||||
while(storageArray.length < len) storageArray.push();
|
||||
while(storageArray.length > len) storageArray.pop();
|
||||
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);
|
||||
while(storageArray.length > 0) storageArray.pop();
|
||||
while(storageArray.length < 3) storageArray.push();
|
||||
while(storageArray.length > 0)
|
||||
storageArray.pop();
|
||||
while(storageArray.length < 3)
|
||||
storageArray.push();
|
||||
|
||||
for (uint i = 3; i < len; i++)
|
||||
{
|
||||
@ -29,10 +31,10 @@ contract C {
|
||||
|
||||
}
|
||||
|
||||
//storageArray = new uint[](0);
|
||||
while(storageArray.length > 0) storageArray.pop();
|
||||
//storageArray = new uint[](len);
|
||||
while(storageArray.length < len) storageArray.push();
|
||||
while(storageArray.length > 0)
|
||||
storageArray.pop();
|
||||
while(storageArray.length < len)
|
||||
storageArray.push();
|
||||
|
||||
for (uint i = 0; i < len; i++)
|
||||
{
|
||||
|
@ -0,0 +1,11 @@
|
||||
contract C {
|
||||
uint[] storageArray;
|
||||
function popEmpty() public {
|
||||
storageArray.pop();
|
||||
}
|
||||
}
|
||||
// ====
|
||||
// EVMVersion: >=petersburg
|
||||
// compileViaYul: true
|
||||
// ----
|
||||
// popEmpty() -> FAILURE
|
@ -0,0 +1,17 @@
|
||||
contract C {
|
||||
uint256[] storageArray;
|
||||
function pushEmpty(uint256 len) public {
|
||||
while(storageArray.length < len)
|
||||
storageArray.push();
|
||||
|
||||
for (uint i = 0; i < len; i++)
|
||||
require(storageArray[i] == 0);
|
||||
}
|
||||
}
|
||||
// ====
|
||||
// compileViaYul: true
|
||||
// EVMVersion: >=petersburg
|
||||
// ----
|
||||
// pushEmpty(uint256): 128
|
||||
// pushEmpty(uint256): 256
|
||||
// pushEmpty(uint256): 32768 -> FAILURE # out-of-gas #
|
@ -0,0 +1,23 @@
|
||||
contract C {
|
||||
address[] addressArray;
|
||||
function set_get_length(uint256 len) public returns (uint256)
|
||||
{
|
||||
while(addressArray.length < len)
|
||||
addressArray.push();
|
||||
while(addressArray.length > len)
|
||||
addressArray.pop();
|
||||
return addressArray.length;
|
||||
}
|
||||
}
|
||||
// ====
|
||||
// compileViaYul: true
|
||||
// EVMVersion: >=petersburg
|
||||
// ----
|
||||
// set_get_length(uint256): 0 -> 0
|
||||
// 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 #
|
Loading…
Reference in New Issue
Block a user