From 763b544822778110eb23106060ffae5f3d0b6e95 Mon Sep 17 00:00:00 2001 From: Lefteris Karapetsas Date: Mon, 12 Oct 2015 09:57:18 +0200 Subject: Add a dynamic array push() test --- test/libsolidity/SolidityEndToEndTest.cpp | 17 +++++++++++++++++ 1 file changed, 17 insertions(+) (limited to 'test/libsolidity/SolidityEndToEndTest.cpp') diff --git a/test/libsolidity/SolidityEndToEndTest.cpp b/test/libsolidity/SolidityEndToEndTest.cpp index 08f62963..b78ea8ec 100644 --- a/test/libsolidity/SolidityEndToEndTest.cpp +++ b/test/libsolidity/SolidityEndToEndTest.cpp @@ -3452,6 +3452,7 @@ BOOST_AUTO_TEST_CASE(array_copy_target_leftover2) asString(fromHex("0000000000000000")) )); } + BOOST_AUTO_TEST_CASE(array_copy_storage_storage_struct) { char const* sourceCode = R"( @@ -3476,6 +3477,22 @@ BOOST_AUTO_TEST_CASE(array_copy_storage_storage_struct) BOOST_CHECK(m_state.storage(m_contractAddress).empty()); } +BOOST_AUTO_TEST_CASE(array_push) +{ + char const* sourceCode = R"( + contract c { + int[] data; + function test() returns (uint) { + data.push(5); + data.push(4); + return data.push(3); + } + } + )"; + compileAndRun(sourceCode); + BOOST_CHECK(callContractFunction("test()") == encodeArgs(3)); +} + BOOST_AUTO_TEST_CASE(external_array_args) { char const* sourceCode = R"( -- cgit From a521843f6b0bf019a19d9a377f4bbbc473083151 Mon Sep 17 00:00:00 2001 From: Lefteris Karapetsas Date: Tue, 13 Oct 2015 16:55:59 +0200 Subject: Implement Dynamic array push and fix test Still a work in progress. There is a disturbance in the stack at the moment and that's why there are some cout statements left for debugging. --- test/libsolidity/SolidityEndToEndTest.cpp | 11 +++++++---- 1 file changed, 7 insertions(+), 4 deletions(-) (limited to 'test/libsolidity/SolidityEndToEndTest.cpp') diff --git a/test/libsolidity/SolidityEndToEndTest.cpp b/test/libsolidity/SolidityEndToEndTest.cpp index b78ea8ec..7ae97db2 100644 --- a/test/libsolidity/SolidityEndToEndTest.cpp +++ b/test/libsolidity/SolidityEndToEndTest.cpp @@ -3481,16 +3481,19 @@ BOOST_AUTO_TEST_CASE(array_push) { char const* sourceCode = R"( contract c { - int[] data; - function test() returns (uint) { + uint[] data; + function test() returns (uint x, uint y, uint z, uint l) { data.push(5); + x = data[0]; data.push(4); - return data.push(3); + y = data[1]; + l = data.push(3); + z = data[2]; } } )"; compileAndRun(sourceCode); - BOOST_CHECK(callContractFunction("test()") == encodeArgs(3)); + BOOST_CHECK(callContractFunction("test()") == encodeArgs(5, 4, 3, 2)); } BOOST_AUTO_TEST_CASE(external_array_args) -- cgit From 9224c1f7128f92f47ddf3feaf83b57d6d98e0a04 Mon Sep 17 00:00:00 2001 From: Lefteris Karapetsas Date: Thu, 15 Oct 2015 13:54:59 +0200 Subject: Working implementation of arraypush ByteArrayPush() gets a test but is ignored for now, since there are still some issues with its implementation --- test/libsolidity/SolidityEndToEndTest.cpp | 23 +++++++++++++++++++++-- 1 file changed, 21 insertions(+), 2 deletions(-) (limited to 'test/libsolidity/SolidityEndToEndTest.cpp') diff --git a/test/libsolidity/SolidityEndToEndTest.cpp b/test/libsolidity/SolidityEndToEndTest.cpp index 7ae97db2..96a426dd 100644 --- a/test/libsolidity/SolidityEndToEndTest.cpp +++ b/test/libsolidity/SolidityEndToEndTest.cpp @@ -3493,9 +3493,28 @@ BOOST_AUTO_TEST_CASE(array_push) } )"; compileAndRun(sourceCode); - BOOST_CHECK(callContractFunction("test()") == encodeArgs(5, 4, 3, 2)); + BOOST_CHECK(callContractFunction("test()") == encodeArgs(5, 4, 3, 3)); } - +#if 0 // reactivate once ByteArrayPush is properly implemented +BOOST_AUTO_TEST_CASE(byte_array_push) +{ + char const* sourceCode = R"( + contract c { + bytes data; + function test() returns (byte x, byte y, byte z, uint l) { + data.push(5); + x = data[0]; + data.push(4); + y = data[1]; + l = data.push(3); + z = data[2]; + } + } + )"; + compileAndRun(sourceCode); + BOOST_CHECK(callContractFunction("test()") == encodeArgs(5, 4, 3, 3)); +} +#endif BOOST_AUTO_TEST_CASE(external_array_args) { char const* sourceCode = R"( -- cgit From a823de2d5863efb45e6d0a9d11e41f511687b831 Mon Sep 17 00:00:00 2001 From: Lefteris Karapetsas Date: Thu, 15 Oct 2015 14:37:11 +0200 Subject: push() for byte arrays also properly implemented --- test/libsolidity/SolidityEndToEndTest.cpp | 19 ++++++++++--------- 1 file changed, 10 insertions(+), 9 deletions(-) (limited to 'test/libsolidity/SolidityEndToEndTest.cpp') diff --git a/test/libsolidity/SolidityEndToEndTest.cpp b/test/libsolidity/SolidityEndToEndTest.cpp index 96a426dd..c71c9a58 100644 --- a/test/libsolidity/SolidityEndToEndTest.cpp +++ b/test/libsolidity/SolidityEndToEndTest.cpp @@ -3495,26 +3495,27 @@ BOOST_AUTO_TEST_CASE(array_push) compileAndRun(sourceCode); BOOST_CHECK(callContractFunction("test()") == encodeArgs(5, 4, 3, 3)); } -#if 0 // reactivate once ByteArrayPush is properly implemented + BOOST_AUTO_TEST_CASE(byte_array_push) { char const* sourceCode = R"( contract c { bytes data; - function test() returns (byte x, byte y, byte z, uint l) { - data.push(5); - x = data[0]; + function test() returns (bool x) { + if (data.push(5) != 1) return true; + if (data[0] != 5) return true; data.push(4); - y = data[1]; - l = data.push(3); - z = data[2]; + if (data[1] != 4) return true; + uint l = data.push(3); + if (data[2] != 3) return true; + if (l != 3) return true; } } )"; compileAndRun(sourceCode); - BOOST_CHECK(callContractFunction("test()") == encodeArgs(5, 4, 3, 3)); + BOOST_CHECK(callContractFunction("test()") == encodeArgs(false)); } -#endif + BOOST_AUTO_TEST_CASE(external_array_args) { char const* sourceCode = R"( -- cgit