From e9dcfb0b624e5443942451fc865c154a2c5a73d7 Mon Sep 17 00:00:00 2001 From: bitshift Date: Fri, 9 Mar 2018 17:46:24 +0100 Subject: Implements pop() for value type arrays. --- test/libsolidity/SolidityEndToEndTest.cpp | 66 +++++++++++++++++++++++++++++++ 1 file changed, 66 insertions(+) (limited to 'test') diff --git a/test/libsolidity/SolidityEndToEndTest.cpp b/test/libsolidity/SolidityEndToEndTest.cpp index 40962294..b4cf6950 100644 --- a/test/libsolidity/SolidityEndToEndTest.cpp +++ b/test/libsolidity/SolidityEndToEndTest.cpp @@ -5111,6 +5111,72 @@ BOOST_AUTO_TEST_CASE(byte_array_push_transition) ABI_CHECK(callContractFunction("test()"), encodeArgs(0)); } +BOOST_AUTO_TEST_CASE(array_pop) +{ + char const* sourceCode = R"( + contract c { + uint[] data; + function test() public returns (uint x, uint y, uint l) { + data.push(7); + x = data.push(3); + data.pop(); + y = data.push(2); + l = data.length; + } + } + )"; + compileAndRun(sourceCode); + ABI_CHECK(callContractFunction("test()"), encodeArgs(2, 2, 2)); +} + +BOOST_AUTO_TEST_CASE(array_pop_empty) +{ + char const* sourceCode = R"( + contract c { + uint[] data; + function test() public returns (bool) { + data.pop(); + return true; + } + } + )"; + compileAndRun(sourceCode); + ABI_CHECK(callContractFunction("test()"), encodeArgs()); +} + +BOOST_AUTO_TEST_CASE(bytearray_pop) +{ + char const* sourceCode = R"( + contract c { + bytes data; + function test() public returns (uint x, uint y, uint l) { + data.push(7); + x = data.push(3); + data.pop(); + data.pop(); + y = data.push(2); + l = data.length; + } + } + )"; + compileAndRun(sourceCode); + ABI_CHECK(callContractFunction("test()"), encodeArgs(2, 1, 1)); +} + +BOOST_AUTO_TEST_CASE(bytearray_pop_empty) +{ + char const* sourceCode = R"( + contract c { + bytes data; + function test() public returns (bool) { + data.pop(); + } + } + )"; + compileAndRun(sourceCode); + ABI_CHECK(callContractFunction("test()"), encodeArgs()); +} + BOOST_AUTO_TEST_CASE(external_array_args) { char const* sourceCode = R"( -- cgit v1.2.3 From 7156a01acc822ab66c189435421564afc8b1c922 Mon Sep 17 00:00:00 2001 From: Erik Kundt Date: Fri, 16 Mar 2018 17:06:38 +0100 Subject: Implements pop() for byte arrays. --- test/libsolidity/SolidityEndToEndTest.cpp | 87 ++++++++++++++++++++++++++++--- 1 file changed, 81 insertions(+), 6 deletions(-) (limited to 'test') diff --git a/test/libsolidity/SolidityEndToEndTest.cpp b/test/libsolidity/SolidityEndToEndTest.cpp index b4cf6950..41101223 100644 --- a/test/libsolidity/SolidityEndToEndTest.cpp +++ b/test/libsolidity/SolidityEndToEndTest.cpp @@ -5115,21 +5115,23 @@ BOOST_AUTO_TEST_CASE(array_pop) { char const* sourceCode = R"( contract c { + uint256 a; uint[] data; - function test() public returns (uint x, uint y, uint l) { + function test() public returns (uint x, uint l) { data.push(7); x = data.push(3); data.pop(); - y = data.push(2); + x = data.length; + data.pop(); l = data.length; } } )"; compileAndRun(sourceCode); - ABI_CHECK(callContractFunction("test()"), encodeArgs(2, 2, 2)); + ABI_CHECK(callContractFunction("test()"), encodeArgs(1, 0)); } -BOOST_AUTO_TEST_CASE(array_pop_empty) +BOOST_AUTO_TEST_CASE(array_pop_empty_exception) { char const* sourceCode = R"( contract c { @@ -5144,7 +5146,23 @@ BOOST_AUTO_TEST_CASE(array_pop_empty) ABI_CHECK(callContractFunction("test()"), encodeArgs()); } -BOOST_AUTO_TEST_CASE(bytearray_pop) +BOOST_AUTO_TEST_CASE(array_pop_storage_empty) +{ + char const* sourceCode = R"( + contract c { + uint[] data; + function test() public { + data.push(7); + data.pop(); + } + } + )"; + compileAndRun(sourceCode); + ABI_CHECK(callContractFunction("test()"), encodeArgs()); + BOOST_CHECK(storageEmpty(m_contractAddress)); +} + +BOOST_AUTO_TEST_CASE(byte_array_pop) { char const* sourceCode = R"( contract c { @@ -5163,13 +5181,31 @@ BOOST_AUTO_TEST_CASE(bytearray_pop) ABI_CHECK(callContractFunction("test()"), encodeArgs(2, 1, 1)); } -BOOST_AUTO_TEST_CASE(bytearray_pop_empty) +BOOST_AUTO_TEST_CASE(byte_array_pop_long) +{ + char const* sourceCode = R"( + contract c { + bytes data; + function test() public returns (uint l) { + for (uint i = 0; i < 33; i++) + data.push(byte(i)); + data.pop(); + l = data.length; + } + } + )"; + compileAndRun(sourceCode); + ABI_CHECK(callContractFunction("test()"), encodeArgs(32)); +} + +BOOST_AUTO_TEST_CASE(byte_array_pop_empty_exception) { char const* sourceCode = R"( contract c { bytes data; function test() public returns (bool) { data.pop(); + return true; } } )"; @@ -5177,6 +5213,45 @@ BOOST_AUTO_TEST_CASE(bytearray_pop_empty) ABI_CHECK(callContractFunction("test()"), encodeArgs()); } +BOOST_AUTO_TEST_CASE(byte_array_pop_storage_empty) +{ + char const* sourceCode = R"( + contract c { + bytes data; + function test() public { + data.push(7); + data.push(5); + data.push(3); + data.pop(); + data.pop(); + data.pop(); + } + } + )"; + compileAndRun(sourceCode); + ABI_CHECK(callContractFunction("test()"), encodeArgs()); + BOOST_CHECK(storageEmpty(m_contractAddress)); +} + +BOOST_AUTO_TEST_CASE(byte_array_pop_storage_empty_long) +{ + char const* sourceCode = R"( + contract c { + bytes data; + function test() public returns (uint l) { + for (uint i = 0; i < 33; i++) + data.push(3); + for (uint j = 0; j < 33; j++) + data.pop(); + l = data.length; + } + } + )"; + compileAndRun(sourceCode); + ABI_CHECK(callContractFunction("test()"), encodeArgs(0)); + BOOST_CHECK(storageEmpty(m_contractAddress)); +} + BOOST_AUTO_TEST_CASE(external_array_args) { char const* sourceCode = R"( -- cgit v1.2.3 From 34b5eca1f8d9a8f04db20139601c6e944532f4e4 Mon Sep 17 00:00:00 2001 From: Erik Kundt Date: Wed, 4 Apr 2018 18:21:06 +0200 Subject: Improves assembly and adds more tests. --- test/libsolidity/SolidityEndToEndTest.cpp | 125 +++++++++++++++++++++++++++++- 1 file changed, 124 insertions(+), 1 deletion(-) (limited to 'test') diff --git a/test/libsolidity/SolidityEndToEndTest.cpp b/test/libsolidity/SolidityEndToEndTest.cpp index 41101223..b0ab15c8 100644 --- a/test/libsolidity/SolidityEndToEndTest.cpp +++ b/test/libsolidity/SolidityEndToEndTest.cpp @@ -5115,7 +5115,6 @@ BOOST_AUTO_TEST_CASE(array_pop) { char const* sourceCode = R"( contract c { - uint256 a; uint[] data; function test() public returns (uint x, uint l) { data.push(7); @@ -5131,6 +5130,86 @@ BOOST_AUTO_TEST_CASE(array_pop) ABI_CHECK(callContractFunction("test()"), encodeArgs(1, 0)); } +BOOST_AUTO_TEST_CASE(array_pop_uint16_transition) +{ + char const* sourceCode = R"( + contract c { + uint16[] data; + function test() public returns (uint16 x, uint16 y, uint16 z) { + for (uint i = 1; i <= 48; i++) + data.push(uint16(i)); + for (uint j = 1; j <= 10; j++) + data.pop(); + x = data[data.length - 1]; + for (uint k = 1; k <= 10; k++) + data.pop(); + y = data[data.length - 1]; + for (uint l = 1; l <= 10; l++) + data.pop(); + z = data[data.length - 1]; + for (uint m = 1; m <= 18; m++) + data.pop(); + } + } + )"; + compileAndRun(sourceCode); + ABI_CHECK(callContractFunction("test()"), encodeArgs(38, 28, 18)); + BOOST_CHECK(storageEmpty(m_contractAddress)); +} + +BOOST_AUTO_TEST_CASE(array_pop_uint24_transition) +{ + char const* sourceCode = R"( + contract c { + uint24[] data; + function test() public returns (uint24 x, uint24 y) { + for (uint i = 1; i <= 30; i++) + data.push(uint24(i)); + for (uint j = 1; j <= 10; j++) + data.pop(); + x = data[data.length - 1]; + for (uint k = 1; k <= 10; k++) + data.pop(); + y = data[data.length - 1]; + for (uint l = 1; l <= 10; l++) + data.pop(); + } + } + )"; + compileAndRun(sourceCode); + ABI_CHECK(callContractFunction("test()"), encodeArgs(20, 10)); + BOOST_CHECK(storageEmpty(m_contractAddress)); +} + +BOOST_AUTO_TEST_CASE(array_pop_array_transition) +{ + char const* sourceCode = R"( + contract c { + uint16[] inner = [1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15, 16]; + uint16[][] data; + function test() public returns (uint x, uint y, uint z) { + for (uint i = 1; i <= 48; i++) + data.push(inner); + for (uint j = 1; j <= 10; j++) + data.pop(); + x = data[data.length - 1][0]; + for (uint k = 1; k <= 10; k++) + data.pop(); + y = data[data.length - 1][1]; + for (uint l = 1; l <= 10; l++) + data.pop(); + z = data[data.length - 1][2]; + for (uint m = 1; m <= 18; m++) + data.pop(); + delete inner; + } + } + )"; + compileAndRun(sourceCode); + ABI_CHECK(callContractFunction("test()"), encodeArgs(1, 2, 3)); + BOOST_CHECK(storageEmpty(m_contractAddress)); +} + BOOST_AUTO_TEST_CASE(array_pop_empty_exception) { char const* sourceCode = R"( @@ -5252,6 +5331,50 @@ BOOST_AUTO_TEST_CASE(byte_array_pop_storage_empty_long) BOOST_CHECK(storageEmpty(m_contractAddress)); } +BOOST_AUTO_TEST_CASE(byte_array_pop_masking_long) +{ + char const* sourceCode = R"( + contract c { + bytes data; + function test() public returns (bytes) { + for (uint i = 0; i < 34; i++) + data.push(3); + data.pop(); + return data; + } + } + )"; + compileAndRun(sourceCode); + ABI_CHECK(callContractFunction("test()"), encodeArgs( + u256(0x20), + u256(33), + asString(fromHex("0303030303030303030303030303030303030303030303030303030303030303")), + asString(fromHex("03")) + )); +} + +BOOST_AUTO_TEST_CASE(byte_array_pop_copy_long) +{ + char const* sourceCode = R"( + contract c { + bytes data; + function test() public returns (bytes) { + for (uint i = 0; i < 33; i++) + data.push(3); + for (uint j = 0; j < 4; j++) + data.pop(); + return data; + } + } + )"; + compileAndRun(sourceCode); + ABI_CHECK(callContractFunction("test()"), encodeArgs( + u256(0x20), + u256(29), + asString(fromHex("0303030303030303030303030303030303030303030303030303030303")) + )); +} + BOOST_AUTO_TEST_CASE(external_array_args) { char const* sourceCode = R"( -- cgit v1.2.3 From 98d52beba3f989b3a5eeaba2d257de8de5df60a7 Mon Sep 17 00:00:00 2001 From: Erik Kundt Date: Wed, 16 May 2018 17:18:30 +0200 Subject: Adds syntax tests, documentation and changelog entry. Refines comment for array utility function. --- test/libsolidity/syntaxTests/array/array_pop.sol | 7 ++++++ .../syntaxTests/array/array_pop_arg.sol | 8 +++++++ test/libsolidity/syntaxTests/array/bytes_pop.sol | 7 ++++++ .../syntaxTests/array/dynamic_memory_array_pop.sol | 8 +++++++ ...ength_cannot_be_constant_function_parameter.sol | 7 ++++++ .../array/length/can_be_constant_in_function.sol | 8 +++++++ .../array/length/can_be_constant_in_struct.sol | 7 ++++++ .../array/length/can_be_recursive_constant.sol | 6 ++++++ .../array/length/cannot_be_function.sol | 6 ++++++ .../array/length/cannot_be_function_call.sol | 7 ++++++ .../array/length/complex_cyclic_constant.sol | 10 +++++++++ .../array/length/const_cannot_be_fractional.sol | 6 ++++++ .../syntaxTests/array/length/constant_var.sol | 5 +++++ .../syntaxTests/array/length/cyclic_constant.sol | 8 +++++++ .../syntaxTests/array/length/inline_array.sol | 5 +++++ .../array/length/invalid_expression_1.sol | 5 +++++ .../array/length/invalid_expression_2.sol | 5 +++++ .../array/length/invalid_expression_3.sol | 5 +++++ .../array/length/invalid_expression_4.sol | 5 +++++ .../array/length/invalid_expression_5.sol | 5 +++++ .../array/length/non_integer_constant_var.sol | 6 ++++++ .../array/length/not_convertible_to_integer.sol | 5 +++++ .../syntaxTests/array/length/parentheses.sol | 25 ++++++++++++++++++++++ .../syntaxTests/array/length/pure_functions.sol | 6 ++++++ .../syntaxTests/array/length/too_large.sol | 5 +++++ .../syntaxTests/array/length/tuples.sol | 5 +++++ .../libsolidity/syntaxTests/array/no_array_pop.sol | 8 +++++++ .../syntaxTests/array/static_storage_array_pop.sol | 8 +++++++ test/libsolidity/syntaxTests/array/string_pop.sol | 8 +++++++ ...ength_cannot_be_constant_function_parameter.sol | 7 ------ .../arrayLength/can_be_constant_in_function.sol | 8 ------- .../arrayLength/can_be_constant_in_struct.sol | 7 ------ .../arrayLength/can_be_recursive_constant.sol | 6 ------ .../syntaxTests/arrayLength/cannot_be_function.sol | 6 ------ .../arrayLength/cannot_be_function_call.sol | 7 ------ .../arrayLength/complex_cyclic_constant.sol | 10 --------- .../arrayLength/const_cannot_be_fractional.sol | 6 ------ .../syntaxTests/arrayLength/constant_var.sol | 5 ----- .../syntaxTests/arrayLength/cyclic_constant.sol | 8 ------- .../syntaxTests/arrayLength/inline_array.sol | 5 ----- .../arrayLength/invalid_expression_1.sol | 5 ----- .../arrayLength/invalid_expression_2.sol | 5 ----- .../arrayLength/invalid_expression_3.sol | 5 ----- .../arrayLength/invalid_expression_4.sol | 5 ----- .../arrayLength/invalid_expression_5.sol | 5 ----- .../arrayLength/non_integer_constant_var.sol | 6 ------ .../arrayLength/not_convertible_to_integer.sol | 5 ----- .../syntaxTests/arrayLength/parentheses.sol | 25 ---------------------- .../syntaxTests/arrayLength/pure_functions.sol | 6 ------ .../syntaxTests/arrayLength/too_large.sol | 5 ----- .../libsolidity/syntaxTests/arrayLength/tuples.sol | 5 ----- 51 files changed, 206 insertions(+), 152 deletions(-) create mode 100644 test/libsolidity/syntaxTests/array/array_pop.sol create mode 100644 test/libsolidity/syntaxTests/array/array_pop_arg.sol create mode 100644 test/libsolidity/syntaxTests/array/bytes_pop.sol create mode 100644 test/libsolidity/syntaxTests/array/dynamic_memory_array_pop.sol create mode 100644 test/libsolidity/syntaxTests/array/length/array_length_cannot_be_constant_function_parameter.sol create mode 100644 test/libsolidity/syntaxTests/array/length/can_be_constant_in_function.sol create mode 100644 test/libsolidity/syntaxTests/array/length/can_be_constant_in_struct.sol create mode 100644 test/libsolidity/syntaxTests/array/length/can_be_recursive_constant.sol create mode 100644 test/libsolidity/syntaxTests/array/length/cannot_be_function.sol create mode 100644 test/libsolidity/syntaxTests/array/length/cannot_be_function_call.sol create mode 100644 test/libsolidity/syntaxTests/array/length/complex_cyclic_constant.sol create mode 100644 test/libsolidity/syntaxTests/array/length/const_cannot_be_fractional.sol create mode 100644 test/libsolidity/syntaxTests/array/length/constant_var.sol create mode 100644 test/libsolidity/syntaxTests/array/length/cyclic_constant.sol create mode 100644 test/libsolidity/syntaxTests/array/length/inline_array.sol create mode 100644 test/libsolidity/syntaxTests/array/length/invalid_expression_1.sol create mode 100644 test/libsolidity/syntaxTests/array/length/invalid_expression_2.sol create mode 100644 test/libsolidity/syntaxTests/array/length/invalid_expression_3.sol create mode 100644 test/libsolidity/syntaxTests/array/length/invalid_expression_4.sol create mode 100644 test/libsolidity/syntaxTests/array/length/invalid_expression_5.sol create mode 100644 test/libsolidity/syntaxTests/array/length/non_integer_constant_var.sol create mode 100644 test/libsolidity/syntaxTests/array/length/not_convertible_to_integer.sol create mode 100644 test/libsolidity/syntaxTests/array/length/parentheses.sol create mode 100644 test/libsolidity/syntaxTests/array/length/pure_functions.sol create mode 100644 test/libsolidity/syntaxTests/array/length/too_large.sol create mode 100644 test/libsolidity/syntaxTests/array/length/tuples.sol create mode 100644 test/libsolidity/syntaxTests/array/no_array_pop.sol create mode 100644 test/libsolidity/syntaxTests/array/static_storage_array_pop.sol create mode 100644 test/libsolidity/syntaxTests/array/string_pop.sol delete mode 100644 test/libsolidity/syntaxTests/arrayLength/array_length_cannot_be_constant_function_parameter.sol delete mode 100644 test/libsolidity/syntaxTests/arrayLength/can_be_constant_in_function.sol delete mode 100644 test/libsolidity/syntaxTests/arrayLength/can_be_constant_in_struct.sol delete mode 100644 test/libsolidity/syntaxTests/arrayLength/can_be_recursive_constant.sol delete mode 100644 test/libsolidity/syntaxTests/arrayLength/cannot_be_function.sol delete mode 100644 test/libsolidity/syntaxTests/arrayLength/cannot_be_function_call.sol delete mode 100644 test/libsolidity/syntaxTests/arrayLength/complex_cyclic_constant.sol delete mode 100644 test/libsolidity/syntaxTests/arrayLength/const_cannot_be_fractional.sol delete mode 100644 test/libsolidity/syntaxTests/arrayLength/constant_var.sol delete mode 100644 test/libsolidity/syntaxTests/arrayLength/cyclic_constant.sol delete mode 100644 test/libsolidity/syntaxTests/arrayLength/inline_array.sol delete mode 100644 test/libsolidity/syntaxTests/arrayLength/invalid_expression_1.sol delete mode 100644 test/libsolidity/syntaxTests/arrayLength/invalid_expression_2.sol delete mode 100644 test/libsolidity/syntaxTests/arrayLength/invalid_expression_3.sol delete mode 100644 test/libsolidity/syntaxTests/arrayLength/invalid_expression_4.sol delete mode 100644 test/libsolidity/syntaxTests/arrayLength/invalid_expression_5.sol delete mode 100644 test/libsolidity/syntaxTests/arrayLength/non_integer_constant_var.sol delete mode 100644 test/libsolidity/syntaxTests/arrayLength/not_convertible_to_integer.sol delete mode 100644 test/libsolidity/syntaxTests/arrayLength/parentheses.sol delete mode 100644 test/libsolidity/syntaxTests/arrayLength/pure_functions.sol delete mode 100644 test/libsolidity/syntaxTests/arrayLength/too_large.sol delete mode 100644 test/libsolidity/syntaxTests/arrayLength/tuples.sol (limited to 'test') diff --git a/test/libsolidity/syntaxTests/array/array_pop.sol b/test/libsolidity/syntaxTests/array/array_pop.sol new file mode 100644 index 00000000..3804f911 --- /dev/null +++ b/test/libsolidity/syntaxTests/array/array_pop.sol @@ -0,0 +1,7 @@ +contract C { + uint[] data; + function test() public { + data.pop(); + } +} +// ---- diff --git a/test/libsolidity/syntaxTests/array/array_pop_arg.sol b/test/libsolidity/syntaxTests/array/array_pop_arg.sol new file mode 100644 index 00000000..bb7803e2 --- /dev/null +++ b/test/libsolidity/syntaxTests/array/array_pop_arg.sol @@ -0,0 +1,8 @@ +contract C { + uint[] data; + function test() public { + data.pop(5); + } +} +// ---- +// TypeError: (65-76): Wrong argument count for function call: 1 arguments given but expected 0. diff --git a/test/libsolidity/syntaxTests/array/bytes_pop.sol b/test/libsolidity/syntaxTests/array/bytes_pop.sol new file mode 100644 index 00000000..cd5aa0eb --- /dev/null +++ b/test/libsolidity/syntaxTests/array/bytes_pop.sol @@ -0,0 +1,7 @@ +contract C { + bytes data; + function test() public { + data.pop(); + } +} +// ---- diff --git a/test/libsolidity/syntaxTests/array/dynamic_memory_array_pop.sol b/test/libsolidity/syntaxTests/array/dynamic_memory_array_pop.sol new file mode 100644 index 00000000..5a79afc9 --- /dev/null +++ b/test/libsolidity/syntaxTests/array/dynamic_memory_array_pop.sol @@ -0,0 +1,8 @@ +contract C { + function test() public { + uint[] memory data; + data.pop(); + } +} +// ---- +// TypeError: (74-82): Member "pop" is not available in uint256[] memory outside of storage. diff --git a/test/libsolidity/syntaxTests/array/length/array_length_cannot_be_constant_function_parameter.sol b/test/libsolidity/syntaxTests/array/length/array_length_cannot_be_constant_function_parameter.sol new file mode 100644 index 00000000..11d40f26 --- /dev/null +++ b/test/libsolidity/syntaxTests/array/length/array_length_cannot_be_constant_function_parameter.sol @@ -0,0 +1,7 @@ +contract C { + function f(uint constant LEN) { + uint[LEN] a; + } +} +// ---- +// TypeError: (62-65): Invalid array length, expected integer literal or constant expression. diff --git a/test/libsolidity/syntaxTests/array/length/can_be_constant_in_function.sol b/test/libsolidity/syntaxTests/array/length/can_be_constant_in_function.sol new file mode 100644 index 00000000..92536dd5 --- /dev/null +++ b/test/libsolidity/syntaxTests/array/length/can_be_constant_in_function.sol @@ -0,0 +1,8 @@ +contract C { + uint constant LEN = 10; + function f() public pure { + uint[LEN] memory a; + a; + } +} +// ---- diff --git a/test/libsolidity/syntaxTests/array/length/can_be_constant_in_struct.sol b/test/libsolidity/syntaxTests/array/length/can_be_constant_in_struct.sol new file mode 100644 index 00000000..89e174f2 --- /dev/null +++ b/test/libsolidity/syntaxTests/array/length/can_be_constant_in_struct.sol @@ -0,0 +1,7 @@ +contract C { + uint constant LEN = 10; + struct Test { + uint[LEN] ids; + } +} +// ---- diff --git a/test/libsolidity/syntaxTests/array/length/can_be_recursive_constant.sol b/test/libsolidity/syntaxTests/array/length/can_be_recursive_constant.sol new file mode 100644 index 00000000..6810a9d6 --- /dev/null +++ b/test/libsolidity/syntaxTests/array/length/can_be_recursive_constant.sol @@ -0,0 +1,6 @@ +contract C { + uint constant L = 5; + uint constant LEN = L + 4 * L; + uint[LEN] ids; +} +// ---- diff --git a/test/libsolidity/syntaxTests/array/length/cannot_be_function.sol b/test/libsolidity/syntaxTests/array/length/cannot_be_function.sol new file mode 100644 index 00000000..ac3abc4c --- /dev/null +++ b/test/libsolidity/syntaxTests/array/length/cannot_be_function.sol @@ -0,0 +1,6 @@ +contract C { + function f() {} + uint[f] ids; +} +// ---- +// TypeError: (42-43): Invalid array length, expected integer literal or constant expression. diff --git a/test/libsolidity/syntaxTests/array/length/cannot_be_function_call.sol b/test/libsolidity/syntaxTests/array/length/cannot_be_function_call.sol new file mode 100644 index 00000000..a6863955 --- /dev/null +++ b/test/libsolidity/syntaxTests/array/length/cannot_be_function_call.sol @@ -0,0 +1,7 @@ +contract C { + function f(uint x) {} + uint constant LEN = f(); + uint[LEN] ids; +} +// ---- +// TypeError: (77-80): Invalid array length, expected integer literal or constant expression. diff --git a/test/libsolidity/syntaxTests/array/length/complex_cyclic_constant.sol b/test/libsolidity/syntaxTests/array/length/complex_cyclic_constant.sol new file mode 100644 index 00000000..254f9f02 --- /dev/null +++ b/test/libsolidity/syntaxTests/array/length/complex_cyclic_constant.sol @@ -0,0 +1,10 @@ +contract C { + uint constant L2 = LEN - 10; + uint constant L1 = L2 / 10; + uint constant LEN = 10 + L1 * 5; + function f() { + uint[LEN] a; + } +} +// ---- +// TypeError: (36-39): Cyclic constant definition (or maximum recursion depth exhausted). diff --git a/test/libsolidity/syntaxTests/array/length/const_cannot_be_fractional.sol b/test/libsolidity/syntaxTests/array/length/const_cannot_be_fractional.sol new file mode 100644 index 00000000..397bbbcd --- /dev/null +++ b/test/libsolidity/syntaxTests/array/length/const_cannot_be_fractional.sol @@ -0,0 +1,6 @@ +contract C { + fixed constant L = 10.5; + uint[L] ids; +} +// ---- +// TypeError: (51-52): Array with fractional length specified. diff --git a/test/libsolidity/syntaxTests/array/length/constant_var.sol b/test/libsolidity/syntaxTests/array/length/constant_var.sol new file mode 100644 index 00000000..41750250 --- /dev/null +++ b/test/libsolidity/syntaxTests/array/length/constant_var.sol @@ -0,0 +1,5 @@ +contract C { + uint constant LEN = 10; + uint[LEN] ids; +} +// ---- \ No newline at end of file diff --git a/test/libsolidity/syntaxTests/array/length/cyclic_constant.sol b/test/libsolidity/syntaxTests/array/length/cyclic_constant.sol new file mode 100644 index 00000000..91ba9045 --- /dev/null +++ b/test/libsolidity/syntaxTests/array/length/cyclic_constant.sol @@ -0,0 +1,8 @@ +contract C { + uint constant LEN = LEN; + function f() { + uint[LEN] a; + } +} +// ---- +// TypeError: (37-40): Cyclic constant definition (or maximum recursion depth exhausted). diff --git a/test/libsolidity/syntaxTests/array/length/inline_array.sol b/test/libsolidity/syntaxTests/array/length/inline_array.sol new file mode 100644 index 00000000..a30745d3 --- /dev/null +++ b/test/libsolidity/syntaxTests/array/length/inline_array.sol @@ -0,0 +1,5 @@ +contract C { + uint[[2]] a15; +} +// ---- +// TypeError: (22-25): Invalid array length, expected integer literal or constant expression. diff --git a/test/libsolidity/syntaxTests/array/length/invalid_expression_1.sol b/test/libsolidity/syntaxTests/array/length/invalid_expression_1.sol new file mode 100644 index 00000000..c92861eb --- /dev/null +++ b/test/libsolidity/syntaxTests/array/length/invalid_expression_1.sol @@ -0,0 +1,5 @@ +contract C { + uint[-true] ids; +} +// ---- +// TypeError: (22-27): Invalid array length, expected integer literal or constant expression. diff --git a/test/libsolidity/syntaxTests/array/length/invalid_expression_2.sol b/test/libsolidity/syntaxTests/array/length/invalid_expression_2.sol new file mode 100644 index 00000000..92e3c3cf --- /dev/null +++ b/test/libsolidity/syntaxTests/array/length/invalid_expression_2.sol @@ -0,0 +1,5 @@ +contract C { + uint[true/1] ids; +} +// ---- +// TypeError: (22-28): Invalid array length, expected integer literal or constant expression. diff --git a/test/libsolidity/syntaxTests/array/length/invalid_expression_3.sol b/test/libsolidity/syntaxTests/array/length/invalid_expression_3.sol new file mode 100644 index 00000000..26add45c --- /dev/null +++ b/test/libsolidity/syntaxTests/array/length/invalid_expression_3.sol @@ -0,0 +1,5 @@ +contract C { + uint[1/true] ids; +} +// ---- +// TypeError: (22-28): Invalid array length, expected integer literal or constant expression. diff --git a/test/libsolidity/syntaxTests/array/length/invalid_expression_4.sol b/test/libsolidity/syntaxTests/array/length/invalid_expression_4.sol new file mode 100644 index 00000000..a0d58f4a --- /dev/null +++ b/test/libsolidity/syntaxTests/array/length/invalid_expression_4.sol @@ -0,0 +1,5 @@ +contract C { + uint[1.111111E1111111111111] ids; +} +// ---- +// TypeError: (22-44): Invalid array length, expected integer literal or constant expression. diff --git a/test/libsolidity/syntaxTests/array/length/invalid_expression_5.sol b/test/libsolidity/syntaxTests/array/length/invalid_expression_5.sol new file mode 100644 index 00000000..38a80867 --- /dev/null +++ b/test/libsolidity/syntaxTests/array/length/invalid_expression_5.sol @@ -0,0 +1,5 @@ +contract C { + uint[3/0] ids; +} +// ---- +// TypeError: (22-25): Operator / not compatible with types int_const 3 and int_const 0 diff --git a/test/libsolidity/syntaxTests/array/length/non_integer_constant_var.sol b/test/libsolidity/syntaxTests/array/length/non_integer_constant_var.sol new file mode 100644 index 00000000..7a853a34 --- /dev/null +++ b/test/libsolidity/syntaxTests/array/length/non_integer_constant_var.sol @@ -0,0 +1,6 @@ +contract C { + bool constant LEN = true; + uint[LEN] ids; +} +// ---- +// TypeError: (52-55): Invalid array length, expected integer literal or constant expression. diff --git a/test/libsolidity/syntaxTests/array/length/not_convertible_to_integer.sol b/test/libsolidity/syntaxTests/array/length/not_convertible_to_integer.sol new file mode 100644 index 00000000..b44ccfe9 --- /dev/null +++ b/test/libsolidity/syntaxTests/array/length/not_convertible_to_integer.sol @@ -0,0 +1,5 @@ +contract C { + uint[true] ids; +} +// ---- +// TypeError: (22-26): Invalid array length, expected integer literal or constant expression. diff --git a/test/libsolidity/syntaxTests/array/length/parentheses.sol b/test/libsolidity/syntaxTests/array/length/parentheses.sol new file mode 100644 index 00000000..40f55ad6 --- /dev/null +++ b/test/libsolidity/syntaxTests/array/length/parentheses.sol @@ -0,0 +1,25 @@ +contract C { + uint constant L1 = (2); + uint constant L2 = ((2)); + uint constant L3 = ((((2)))); + uint constant L4 = (2 + 1); + uint constant L5 = ((2 + 1)); + uint constant L6 = (((2) + ((1)))); + uint constant L7 = (2 + 1) / 1; + uint constant L8 = (2 + ((1))) / (1); + uint[L1] a1; + uint[L2] a2; + uint[L3] a3; + uint[L4] a4; + uint[L5] a5; + uint[L6] a6; + uint[L7] a7; + uint[L8] a8; + uint[(2)] a9; + uint[(2 + 1)] a10; + uint[(2 + 1) + 1] a11; + uint[((2) + 1) + 1] a12; + uint[(2 + 1) + ((1))] a13; + uint[(((2) + 1)) + (((1)))] a14; + uint[((((2) + 1)) + (((1))))%1] a15; +} diff --git a/test/libsolidity/syntaxTests/array/length/pure_functions.sol b/test/libsolidity/syntaxTests/array/length/pure_functions.sol new file mode 100644 index 00000000..b620db76 --- /dev/null +++ b/test/libsolidity/syntaxTests/array/length/pure_functions.sol @@ -0,0 +1,6 @@ +contract C { + uint constant LEN = keccak256(ripemd160(33)); + uint[LEN] ids; +} +// ---- +// TypeError: (72-75): Invalid array length, expected integer literal or constant expression. diff --git a/test/libsolidity/syntaxTests/array/length/too_large.sol b/test/libsolidity/syntaxTests/array/length/too_large.sol new file mode 100644 index 00000000..c90a7494 --- /dev/null +++ b/test/libsolidity/syntaxTests/array/length/too_large.sol @@ -0,0 +1,5 @@ +contract C { + uint[8**90] ids; +} +// ---- +// TypeError: (22-27): Invalid array length, expected integer literal or constant expression. diff --git a/test/libsolidity/syntaxTests/array/length/tuples.sol b/test/libsolidity/syntaxTests/array/length/tuples.sol new file mode 100644 index 00000000..bc10b3b5 --- /dev/null +++ b/test/libsolidity/syntaxTests/array/length/tuples.sol @@ -0,0 +1,5 @@ +contract C { + uint[(1,2)] a15; +} +// ---- +// TypeError: (22-27): Invalid array length, expected integer literal or constant expression. diff --git a/test/libsolidity/syntaxTests/array/no_array_pop.sol b/test/libsolidity/syntaxTests/array/no_array_pop.sol new file mode 100644 index 00000000..44e54ad2 --- /dev/null +++ b/test/libsolidity/syntaxTests/array/no_array_pop.sol @@ -0,0 +1,8 @@ +contract C { + uint data; + function test() public { + data.pop(); + } +} +// ---- +// TypeError: (63-71): Member "pop" not found or not visible after argument-dependent lookup in uint256 diff --git a/test/libsolidity/syntaxTests/array/static_storage_array_pop.sol b/test/libsolidity/syntaxTests/array/static_storage_array_pop.sol new file mode 100644 index 00000000..0af171ad --- /dev/null +++ b/test/libsolidity/syntaxTests/array/static_storage_array_pop.sol @@ -0,0 +1,8 @@ +contract C { + uint[3] data; + function test() public { + data.pop(); + } +} +// ---- +// TypeError: (66-74): Member "pop" not found or not visible after argument-dependent lookup in uint256[3] storage ref diff --git a/test/libsolidity/syntaxTests/array/string_pop.sol b/test/libsolidity/syntaxTests/array/string_pop.sol new file mode 100644 index 00000000..2a46d0c3 --- /dev/null +++ b/test/libsolidity/syntaxTests/array/string_pop.sol @@ -0,0 +1,8 @@ +contract C { + string data; + function test() public { + data.pop(); + } +} +// ---- +// TypeError: (65-73): Member "pop" not found or not visible after argument-dependent lookup in string storage ref diff --git a/test/libsolidity/syntaxTests/arrayLength/array_length_cannot_be_constant_function_parameter.sol b/test/libsolidity/syntaxTests/arrayLength/array_length_cannot_be_constant_function_parameter.sol deleted file mode 100644 index 11d40f26..00000000 --- a/test/libsolidity/syntaxTests/arrayLength/array_length_cannot_be_constant_function_parameter.sol +++ /dev/null @@ -1,7 +0,0 @@ -contract C { - function f(uint constant LEN) { - uint[LEN] a; - } -} -// ---- -// TypeError: (62-65): Invalid array length, expected integer literal or constant expression. diff --git a/test/libsolidity/syntaxTests/arrayLength/can_be_constant_in_function.sol b/test/libsolidity/syntaxTests/arrayLength/can_be_constant_in_function.sol deleted file mode 100644 index 92536dd5..00000000 --- a/test/libsolidity/syntaxTests/arrayLength/can_be_constant_in_function.sol +++ /dev/null @@ -1,8 +0,0 @@ -contract C { - uint constant LEN = 10; - function f() public pure { - uint[LEN] memory a; - a; - } -} -// ---- diff --git a/test/libsolidity/syntaxTests/arrayLength/can_be_constant_in_struct.sol b/test/libsolidity/syntaxTests/arrayLength/can_be_constant_in_struct.sol deleted file mode 100644 index 89e174f2..00000000 --- a/test/libsolidity/syntaxTests/arrayLength/can_be_constant_in_struct.sol +++ /dev/null @@ -1,7 +0,0 @@ -contract C { - uint constant LEN = 10; - struct Test { - uint[LEN] ids; - } -} -// ---- diff --git a/test/libsolidity/syntaxTests/arrayLength/can_be_recursive_constant.sol b/test/libsolidity/syntaxTests/arrayLength/can_be_recursive_constant.sol deleted file mode 100644 index 6810a9d6..00000000 --- a/test/libsolidity/syntaxTests/arrayLength/can_be_recursive_constant.sol +++ /dev/null @@ -1,6 +0,0 @@ -contract C { - uint constant L = 5; - uint constant LEN = L + 4 * L; - uint[LEN] ids; -} -// ---- diff --git a/test/libsolidity/syntaxTests/arrayLength/cannot_be_function.sol b/test/libsolidity/syntaxTests/arrayLength/cannot_be_function.sol deleted file mode 100644 index ac3abc4c..00000000 --- a/test/libsolidity/syntaxTests/arrayLength/cannot_be_function.sol +++ /dev/null @@ -1,6 +0,0 @@ -contract C { - function f() {} - uint[f] ids; -} -// ---- -// TypeError: (42-43): Invalid array length, expected integer literal or constant expression. diff --git a/test/libsolidity/syntaxTests/arrayLength/cannot_be_function_call.sol b/test/libsolidity/syntaxTests/arrayLength/cannot_be_function_call.sol deleted file mode 100644 index a6863955..00000000 --- a/test/libsolidity/syntaxTests/arrayLength/cannot_be_function_call.sol +++ /dev/null @@ -1,7 +0,0 @@ -contract C { - function f(uint x) {} - uint constant LEN = f(); - uint[LEN] ids; -} -// ---- -// TypeError: (77-80): Invalid array length, expected integer literal or constant expression. diff --git a/test/libsolidity/syntaxTests/arrayLength/complex_cyclic_constant.sol b/test/libsolidity/syntaxTests/arrayLength/complex_cyclic_constant.sol deleted file mode 100644 index 254f9f02..00000000 --- a/test/libsolidity/syntaxTests/arrayLength/complex_cyclic_constant.sol +++ /dev/null @@ -1,10 +0,0 @@ -contract C { - uint constant L2 = LEN - 10; - uint constant L1 = L2 / 10; - uint constant LEN = 10 + L1 * 5; - function f() { - uint[LEN] a; - } -} -// ---- -// TypeError: (36-39): Cyclic constant definition (or maximum recursion depth exhausted). diff --git a/test/libsolidity/syntaxTests/arrayLength/const_cannot_be_fractional.sol b/test/libsolidity/syntaxTests/arrayLength/const_cannot_be_fractional.sol deleted file mode 100644 index 397bbbcd..00000000 --- a/test/libsolidity/syntaxTests/arrayLength/const_cannot_be_fractional.sol +++ /dev/null @@ -1,6 +0,0 @@ -contract C { - fixed constant L = 10.5; - uint[L] ids; -} -// ---- -// TypeError: (51-52): Array with fractional length specified. diff --git a/test/libsolidity/syntaxTests/arrayLength/constant_var.sol b/test/libsolidity/syntaxTests/arrayLength/constant_var.sol deleted file mode 100644 index 41750250..00000000 --- a/test/libsolidity/syntaxTests/arrayLength/constant_var.sol +++ /dev/null @@ -1,5 +0,0 @@ -contract C { - uint constant LEN = 10; - uint[LEN] ids; -} -// ---- \ No newline at end of file diff --git a/test/libsolidity/syntaxTests/arrayLength/cyclic_constant.sol b/test/libsolidity/syntaxTests/arrayLength/cyclic_constant.sol deleted file mode 100644 index 91ba9045..00000000 --- a/test/libsolidity/syntaxTests/arrayLength/cyclic_constant.sol +++ /dev/null @@ -1,8 +0,0 @@ -contract C { - uint constant LEN = LEN; - function f() { - uint[LEN] a; - } -} -// ---- -// TypeError: (37-40): Cyclic constant definition (or maximum recursion depth exhausted). diff --git a/test/libsolidity/syntaxTests/arrayLength/inline_array.sol b/test/libsolidity/syntaxTests/arrayLength/inline_array.sol deleted file mode 100644 index a30745d3..00000000 --- a/test/libsolidity/syntaxTests/arrayLength/inline_array.sol +++ /dev/null @@ -1,5 +0,0 @@ -contract C { - uint[[2]] a15; -} -// ---- -// TypeError: (22-25): Invalid array length, expected integer literal or constant expression. diff --git a/test/libsolidity/syntaxTests/arrayLength/invalid_expression_1.sol b/test/libsolidity/syntaxTests/arrayLength/invalid_expression_1.sol deleted file mode 100644 index c92861eb..00000000 --- a/test/libsolidity/syntaxTests/arrayLength/invalid_expression_1.sol +++ /dev/null @@ -1,5 +0,0 @@ -contract C { - uint[-true] ids; -} -// ---- -// TypeError: (22-27): Invalid array length, expected integer literal or constant expression. diff --git a/test/libsolidity/syntaxTests/arrayLength/invalid_expression_2.sol b/test/libsolidity/syntaxTests/arrayLength/invalid_expression_2.sol deleted file mode 100644 index 92e3c3cf..00000000 --- a/test/libsolidity/syntaxTests/arrayLength/invalid_expression_2.sol +++ /dev/null @@ -1,5 +0,0 @@ -contract C { - uint[true/1] ids; -} -// ---- -// TypeError: (22-28): Invalid array length, expected integer literal or constant expression. diff --git a/test/libsolidity/syntaxTests/arrayLength/invalid_expression_3.sol b/test/libsolidity/syntaxTests/arrayLength/invalid_expression_3.sol deleted file mode 100644 index 26add45c..00000000 --- a/test/libsolidity/syntaxTests/arrayLength/invalid_expression_3.sol +++ /dev/null @@ -1,5 +0,0 @@ -contract C { - uint[1/true] ids; -} -// ---- -// TypeError: (22-28): Invalid array length, expected integer literal or constant expression. diff --git a/test/libsolidity/syntaxTests/arrayLength/invalid_expression_4.sol b/test/libsolidity/syntaxTests/arrayLength/invalid_expression_4.sol deleted file mode 100644 index a0d58f4a..00000000 --- a/test/libsolidity/syntaxTests/arrayLength/invalid_expression_4.sol +++ /dev/null @@ -1,5 +0,0 @@ -contract C { - uint[1.111111E1111111111111] ids; -} -// ---- -// TypeError: (22-44): Invalid array length, expected integer literal or constant expression. diff --git a/test/libsolidity/syntaxTests/arrayLength/invalid_expression_5.sol b/test/libsolidity/syntaxTests/arrayLength/invalid_expression_5.sol deleted file mode 100644 index 38a80867..00000000 --- a/test/libsolidity/syntaxTests/arrayLength/invalid_expression_5.sol +++ /dev/null @@ -1,5 +0,0 @@ -contract C { - uint[3/0] ids; -} -// ---- -// TypeError: (22-25): Operator / not compatible with types int_const 3 and int_const 0 diff --git a/test/libsolidity/syntaxTests/arrayLength/non_integer_constant_var.sol b/test/libsolidity/syntaxTests/arrayLength/non_integer_constant_var.sol deleted file mode 100644 index 7a853a34..00000000 --- a/test/libsolidity/syntaxTests/arrayLength/non_integer_constant_var.sol +++ /dev/null @@ -1,6 +0,0 @@ -contract C { - bool constant LEN = true; - uint[LEN] ids; -} -// ---- -// TypeError: (52-55): Invalid array length, expected integer literal or constant expression. diff --git a/test/libsolidity/syntaxTests/arrayLength/not_convertible_to_integer.sol b/test/libsolidity/syntaxTests/arrayLength/not_convertible_to_integer.sol deleted file mode 100644 index b44ccfe9..00000000 --- a/test/libsolidity/syntaxTests/arrayLength/not_convertible_to_integer.sol +++ /dev/null @@ -1,5 +0,0 @@ -contract C { - uint[true] ids; -} -// ---- -// TypeError: (22-26): Invalid array length, expected integer literal or constant expression. diff --git a/test/libsolidity/syntaxTests/arrayLength/parentheses.sol b/test/libsolidity/syntaxTests/arrayLength/parentheses.sol deleted file mode 100644 index 40f55ad6..00000000 --- a/test/libsolidity/syntaxTests/arrayLength/parentheses.sol +++ /dev/null @@ -1,25 +0,0 @@ -contract C { - uint constant L1 = (2); - uint constant L2 = ((2)); - uint constant L3 = ((((2)))); - uint constant L4 = (2 + 1); - uint constant L5 = ((2 + 1)); - uint constant L6 = (((2) + ((1)))); - uint constant L7 = (2 + 1) / 1; - uint constant L8 = (2 + ((1))) / (1); - uint[L1] a1; - uint[L2] a2; - uint[L3] a3; - uint[L4] a4; - uint[L5] a5; - uint[L6] a6; - uint[L7] a7; - uint[L8] a8; - uint[(2)] a9; - uint[(2 + 1)] a10; - uint[(2 + 1) + 1] a11; - uint[((2) + 1) + 1] a12; - uint[(2 + 1) + ((1))] a13; - uint[(((2) + 1)) + (((1)))] a14; - uint[((((2) + 1)) + (((1))))%1] a15; -} diff --git a/test/libsolidity/syntaxTests/arrayLength/pure_functions.sol b/test/libsolidity/syntaxTests/arrayLength/pure_functions.sol deleted file mode 100644 index b620db76..00000000 --- a/test/libsolidity/syntaxTests/arrayLength/pure_functions.sol +++ /dev/null @@ -1,6 +0,0 @@ -contract C { - uint constant LEN = keccak256(ripemd160(33)); - uint[LEN] ids; -} -// ---- -// TypeError: (72-75): Invalid array length, expected integer literal or constant expression. diff --git a/test/libsolidity/syntaxTests/arrayLength/too_large.sol b/test/libsolidity/syntaxTests/arrayLength/too_large.sol deleted file mode 100644 index c90a7494..00000000 --- a/test/libsolidity/syntaxTests/arrayLength/too_large.sol +++ /dev/null @@ -1,5 +0,0 @@ -contract C { - uint[8**90] ids; -} -// ---- -// TypeError: (22-27): Invalid array length, expected integer literal or constant expression. diff --git a/test/libsolidity/syntaxTests/arrayLength/tuples.sol b/test/libsolidity/syntaxTests/arrayLength/tuples.sol deleted file mode 100644 index bc10b3b5..00000000 --- a/test/libsolidity/syntaxTests/arrayLength/tuples.sol +++ /dev/null @@ -1,5 +0,0 @@ -contract C { - uint[(1,2)] a15; -} -// ---- -// TypeError: (22-27): Invalid array length, expected integer literal or constant expression. -- cgit v1.2.3 From fea0d116f7d95e9a39f0c80c5156cb3656b03ce0 Mon Sep 17 00:00:00 2001 From: Erik Kundt Date: Tue, 29 May 2018 11:25:13 +0200 Subject: Fixes assembly bug and adds tests to cover it. --- test/libsolidity/SolidityEndToEndTest.cpp | 68 ++++++++++++++++++++----------- 1 file changed, 45 insertions(+), 23 deletions(-) (limited to 'test') diff --git a/test/libsolidity/SolidityEndToEndTest.cpp b/test/libsolidity/SolidityEndToEndTest.cpp index b0ab15c8..f1fac396 100644 --- a/test/libsolidity/SolidityEndToEndTest.cpp +++ b/test/libsolidity/SolidityEndToEndTest.cpp @@ -5161,6 +5161,9 @@ BOOST_AUTO_TEST_CASE(array_pop_uint24_transition) { char const* sourceCode = R"( contract c { + uint256 a; + uint256 b; + uint256 c; uint24[] data; function test() public returns (uint24 x, uint24 y) { for (uint i = 1; i <= 30; i++) @@ -5185,6 +5188,9 @@ BOOST_AUTO_TEST_CASE(array_pop_array_transition) { char const* sourceCode = R"( contract c { + uint256 a; + uint256 b; + uint256 c; uint16[] inner = [1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15, 16]; uint16[][] data; function test() public returns (uint x, uint y, uint z) { @@ -5260,27 +5266,13 @@ BOOST_AUTO_TEST_CASE(byte_array_pop) ABI_CHECK(callContractFunction("test()"), encodeArgs(2, 1, 1)); } -BOOST_AUTO_TEST_CASE(byte_array_pop_long) -{ - char const* sourceCode = R"( - contract c { - bytes data; - function test() public returns (uint l) { - for (uint i = 0; i < 33; i++) - data.push(byte(i)); - data.pop(); - l = data.length; - } - } - )"; - compileAndRun(sourceCode); - ABI_CHECK(callContractFunction("test()"), encodeArgs(32)); -} - BOOST_AUTO_TEST_CASE(byte_array_pop_empty_exception) { char const* sourceCode = R"( contract c { + uint256 a; + uint256 b; + uint256 c; bytes data; function test() public returns (bool) { data.pop(); @@ -5312,22 +5304,52 @@ BOOST_AUTO_TEST_CASE(byte_array_pop_storage_empty) BOOST_CHECK(storageEmpty(m_contractAddress)); } -BOOST_AUTO_TEST_CASE(byte_array_pop_storage_empty_long) +BOOST_AUTO_TEST_CASE(byte_array_pop_long_storage_empty) { char const* sourceCode = R"( contract c { + uint256 a; + uint256 b; + uint256 c; bytes data; - function test() public returns (uint l) { - for (uint i = 0; i < 33; i++) + function test() public returns (bool) { + for (uint8 i = 0; i <= 40; i++) + data.push(byte(i+1)); + for (int8 j = 40; j >= 0; j--) { + require(data[uint8(j)] == byte(j+1)); + require(data.length == uint8(j+1)); + data.pop(); + } + return true; + } + } + )"; + compileAndRun(sourceCode); + ABI_CHECK(callContractFunction("test()"), encodeArgs(true)); + BOOST_CHECK(storageEmpty(m_contractAddress)); +} + +BOOST_AUTO_TEST_CASE(byte_array_pop_long_storage_empty_garbage_ref) +{ + char const* sourceCode = R"( + contract c { + uint256 a; + uint256 b; + bytes data; + function test() public { + for (uint8 i = 0; i <= 40; i++) data.push(3); - for (uint j = 0; j < 33; j++) + for (uint8 j = 0; j <= 40; j++) { + assembly { + mstore(0, "garbage") + } data.pop(); - l = data.length; + } } } )"; compileAndRun(sourceCode); - ABI_CHECK(callContractFunction("test()"), encodeArgs(0)); + ABI_CHECK(callContractFunction("test()"), encodeArgs()); BOOST_CHECK(storageEmpty(m_contractAddress)); } -- cgit v1.2.3