diff --git a/test/libsolidity/semanticTests/viaYul/array_storage_index_access.sol b/test/libsolidity/semanticTests/viaYul/array_storage_index_access.sol index 6a9ea8e85..d286fc36c 100644 --- a/test/libsolidity/semanticTests/viaYul/array_storage_index_access.sol +++ b/test/libsolidity/semanticTests/viaYul/array_storage_index_access.sol @@ -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; diff --git a/test/libsolidity/semanticTests/viaYul/array_storage_index_boundary_test.sol b/test/libsolidity/semanticTests/viaYul/array_storage_index_boundary_test.sol index 0beef81cf..5fe4a381d 100644 --- a/test/libsolidity/semanticTests/viaYul/array_storage_index_boundary_test.sol +++ b/test/libsolidity/semanticTests/viaYul/array_storage_index_boundary_test.sol @@ -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]; } } diff --git a/test/libsolidity/semanticTests/viaYul/array_storage_index_zeroed_test.sol b/test/libsolidity/semanticTests/viaYul/array_storage_index_zeroed_test.sol index 684a3d179..98b25a40e 100644 --- a/test/libsolidity/semanticTests/viaYul/array_storage_index_zeroed_test.sol +++ b/test/libsolidity/semanticTests/viaYul/array_storage_index_zeroed_test.sol @@ -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++) { diff --git a/test/libsolidity/semanticTests/viaYul/array_storage_pop_zero_length.sol b/test/libsolidity/semanticTests/viaYul/array_storage_pop_zero_length.sol new file mode 100644 index 000000000..932a4d642 --- /dev/null +++ b/test/libsolidity/semanticTests/viaYul/array_storage_pop_zero_length.sol @@ -0,0 +1,11 @@ +contract C { + uint[] storageArray; + function popEmpty() public { + storageArray.pop(); + } +} +// ==== +// EVMVersion: >=petersburg +// compileViaYul: true +// ---- +// popEmpty() -> FAILURE diff --git a/test/libsolidity/semanticTests/viaYul/array_storage_push_empty.sol b/test/libsolidity/semanticTests/viaYul/array_storage_push_empty.sol new file mode 100644 index 000000000..e692b273a --- /dev/null +++ b/test/libsolidity/semanticTests/viaYul/array_storage_push_empty.sol @@ -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 # \ No newline at end of file diff --git a/test/libsolidity/semanticTests/viaYul/array_storage_push_empty_length_address.sol b/test/libsolidity/semanticTests/viaYul/array_storage_push_empty_length_address.sol new file mode 100644 index 000000000..7f9bd82dd --- /dev/null +++ b/test/libsolidity/semanticTests/viaYul/array_storage_push_empty_length_address.sol @@ -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 #