aboutsummaryrefslogtreecommitdiffstats
path: root/test/libsolidity/SolidityEndToEndTest.cpp
diff options
context:
space:
mode:
Diffstat (limited to 'test/libsolidity/SolidityEndToEndTest.cpp')
-rw-r--r--test/libsolidity/SolidityEndToEndTest.cpp345
1 files changed, 325 insertions, 20 deletions
diff --git a/test/libsolidity/SolidityEndToEndTest.cpp b/test/libsolidity/SolidityEndToEndTest.cpp
index 40962294..b53a9294 100644
--- a/test/libsolidity/SolidityEndToEndTest.cpp
+++ b/test/libsolidity/SolidityEndToEndTest.cpp
@@ -5111,6 +5111,326 @@ 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 l) {
+ data.push(7);
+ x = data.push(3);
+ data.pop();
+ x = data.length;
+ data.pop();
+ l = data.length;
+ }
+ }
+ )";
+ compileAndRun(sourceCode);
+ 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 {
+ uint256 a;
+ uint256 b;
+ uint256 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 {
+ 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) {
+ 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"(
+ contract c {
+ uint[] data;
+ function test() public returns (bool) {
+ data.pop();
+ return true;
+ }
+ }
+ )";
+ compileAndRun(sourceCode);
+ ABI_CHECK(callContractFunction("test()"), encodeArgs());
+}
+
+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 {
+ 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(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();
+ return true;
+ }
+ }
+ )";
+ compileAndRun(sourceCode);
+ 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_long_storage_empty)
+{
+ char const* sourceCode = R"(
+ contract c {
+ uint256 a;
+ uint256 b;
+ uint256 c;
+ bytes data;
+ 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 (uint8 j = 0; j <= 40; j++) {
+ assembly {
+ mstore(0, "garbage")
+ }
+ data.pop();
+ }
+ }
+ }
+ )";
+ compileAndRun(sourceCode);
+ ABI_CHECK(callContractFunction("test()"), encodeArgs());
+ 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(array_pop_isolated)
+{
+ char const* sourceCode = R"(
+ // This tests that the compiler knows the correct size of the function on the stack.
+ contract c {
+ uint[] data;
+ function test() public returns (uint x) {
+ x = 2;
+ data.pop;
+ x = 3;
+ }
+ }
+ )";
+ compileAndRun(sourceCode);
+ ABI_CHECK(callContractFunction("test()"), encodeArgs(3));
+}
+
+BOOST_AUTO_TEST_CASE(byte_array_pop_isolated)
+{
+ char const* sourceCode = R"(
+ // This tests that the compiler knows the correct size of the function on the stack.
+ contract c {
+ bytes data;
+ function test() public returns (uint x) {
+ x = 2;
+ data.pop;
+ x = 3;
+ }
+ }
+ )";
+ compileAndRun(sourceCode);
+ ABI_CHECK(callContractFunction("test()"), encodeArgs(3));
+}
+
BOOST_AUTO_TEST_CASE(external_array_args)
{
char const* sourceCode = R"(
@@ -8299,15 +8619,15 @@ BOOST_AUTO_TEST_CASE(inline_array_return)
{
char const* sourceCode = R"(
contract C {
- uint8[] tester;
+ uint8[] tester;
function f() returns (uint8[5]) {
return ([1,2,3,4,5]);
}
function test() returns (uint8, uint8, uint8, uint8, uint8) {
- tester = f();
+ tester = f();
return (tester[0], tester[1], tester[2], tester[3], tester[4]);
}
-
+
}
)";
compileAndRun(sourceCode, 0, "C");
@@ -8331,13 +8651,13 @@ BOOST_AUTO_TEST_CASE(inline_array_singleton)
BOOST_AUTO_TEST_CASE(inline_long_string_return)
{
char const* sourceCode = R"(
- contract C {
+ contract C {
function f() returns (string) {
return (["somethingShort", "0123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789001234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678900123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789001234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890"][1]);
}
}
)";
-
+
string strLong = "0123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789001234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678900123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789001234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890";
compileAndRun(sourceCode, 0, "C");
ABI_CHECK(callContractFunction("f()"), encodeDyn(strLong));
@@ -11145,26 +11465,11 @@ BOOST_AUTO_TEST_CASE(keccak256_assembly)
=: ret
}
}
- function h() pure returns (bytes32 ret) {
- assembly {
- ret := sha3(0, 0)
- }
- }
- function i() pure returns (bytes32 ret) {
- assembly {
- 0
- 0
- sha3
- =: ret
- }
- }
}
)";
compileAndRun(sourceCode, 0, "C");
ABI_CHECK(callContractFunction("f()"), fromHex("0xc5d2460186f7233c927e7db2dcc703c0e500b653ca82273b7bfad8045d85a470"));
ABI_CHECK(callContractFunction("g()"), fromHex("0xc5d2460186f7233c927e7db2dcc703c0e500b653ca82273b7bfad8045d85a470"));
- ABI_CHECK(callContractFunction("h()"), fromHex("0xc5d2460186f7233c927e7db2dcc703c0e500b653ca82273b7bfad8045d85a470"));
- ABI_CHECK(callContractFunction("i()"), fromHex("0xc5d2460186f7233c927e7db2dcc703c0e500b653ca82273b7bfad8045d85a470"));
}
BOOST_AUTO_TEST_CASE(multi_modifiers)