From c7facd6d37d53d6f49e482011c58f34413856236 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Pawe=C5=82=20Bylica?= Date: Sun, 17 May 2015 23:03:39 +0200 Subject: [PATCH 01/64] Little improved base64 implementation. Global variable type changed from dynamic constructed std::string to constant char array. Truncating conversion eliminated (no MSVC warning). Unit tests added. From a3c4b5cd032915a67c8f6c27a412e902c3cc8c07 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Pawe=C5=82=20Bylica?= Date: Wed, 20 May 2015 19:10:55 +0200 Subject: [PATCH 02/64] One more unit test for base64 encoding. From ec76302b85b2715e19e02317d90ee4a6d63e8470 Mon Sep 17 00:00:00 2001 From: chriseth Date: Fri, 22 May 2015 09:33:57 +0200 Subject: [PATCH 03/64] Path gas meter. --- libsolidity/GasMeter.cpp | 70 ++++++++++++++++++++++++++++++++++++---- 1 file changed, 64 insertions(+), 6 deletions(-) diff --git a/libsolidity/GasMeter.cpp b/libsolidity/GasMeter.cpp index 43eb3f956..2508399ff 100644 --- a/libsolidity/GasMeter.cpp +++ b/libsolidity/GasMeter.cpp @@ -23,6 +23,7 @@ #include #include #include +#include #include #include #include @@ -57,20 +58,38 @@ public: ); } - void testCreationTimeGas(string const& _sourceCode, string const& _contractName = "") + void testCreationTimeGas(string const& _sourceCode) { compileAndRun(_sourceCode); auto state = make_shared(); - GasMeter meter(state); - GasMeter::GasConsumption gas; - for (AssemblyItem const& item: *m_compiler.getAssemblyItems(_contractName)) - gas += meter.estimateMax(item); - u256 bytecodeSize(m_compiler.getRuntimeBytecode(_contractName).size()); + PathGasMeter meter(*m_compiler.getAssemblyItems()); + GasMeter::GasConsumption gas = meter.estimateMax(0, state); + u256 bytecodeSize(m_compiler.getRuntimeBytecode().size()); gas += bytecodeSize * c_createDataGas; BOOST_REQUIRE(!gas.isInfinite); BOOST_CHECK(gas.value == m_gasUsed); } + void testRunTimeGas(std::string const& _sig, vector _argumentVariants) + { + u256 gasUsed = 0; + FixedHash<4> hash(dev::sha3(_sig)); + for (bytes const& arguments: _argumentVariants) + { + sendMessage(hash.asBytes() + arguments, false, 0); + gasUsed = max(gasUsed, m_gasUsed); + } + + auto state = make_shared(); + //TODO modify state to include function hash in calldata + PathGasMeter meter(*m_compiler.getRuntimeAssemblyItems()); + GasMeter::GasConsumption gas = meter.estimateMax(0, state); + cout << "VM: " << gasUsed << endl; + cout << "est: " << gas << endl; + BOOST_REQUIRE(!gas.isInfinite); + BOOST_CHECK(gas.value == m_gasUsed); + } + protected: map m_gasCosts; }; @@ -149,6 +168,45 @@ BOOST_AUTO_TEST_CASE(updating_store) testCreationTimeGas(sourceCode); } +BOOST_AUTO_TEST_CASE(branches) +{ + char const* sourceCode = R"( + contract test { + uint data; + uint data2; + function f(uint x) { + if (x > 7) + data2 = 1; + else + data = 1; + } + } + )"; + testCreationTimeGas(sourceCode); + testRunTimeGas("f(uint256)", vector{encodeArgs(2), encodeArgs(8)}); +} + +BOOST_AUTO_TEST_CASE(function_calls) +{ + char const* sourceCode = R"( + contract test { + uint data; + uint data2; + function f(uint x) { + if (x > 7) + data2 = g(x**8) + 1; + else + data = 1; + } + function g(uint x) internal returns (uint) { + return data2; + } + } + )"; + testCreationTimeGas(sourceCode); + testRunTimeGas("f(uint256)", vector{encodeArgs(2), encodeArgs(8)}); +} + BOOST_AUTO_TEST_SUITE_END() } From 964bcd6b857c48d084ac2cfe0cd395939da570f0 Mon Sep 17 00:00:00 2001 From: chriseth Date: Fri, 22 May 2015 10:48:54 +0200 Subject: [PATCH 04/64] Functional gas estimator. --- libsolidity/GasMeter.cpp | 41 ++++++++++++++++++++++++++++++---------- 1 file changed, 31 insertions(+), 10 deletions(-) diff --git a/libsolidity/GasMeter.cpp b/libsolidity/GasMeter.cpp index 2508399ff..c09849c00 100644 --- a/libsolidity/GasMeter.cpp +++ b/libsolidity/GasMeter.cpp @@ -25,7 +25,7 @@ #include #include #include -#include +#include #include using namespace std; @@ -48,12 +48,11 @@ public: m_compiler.setSource(_sourceCode); ETH_TEST_REQUIRE_NO_THROW(m_compiler.compile(), "Compiling contract failed"); - StructuralGasEstimator estimator; AssemblyItems const* items = m_compiler.getRuntimeAssemblyItems(""); ASTNode const& sourceUnit = m_compiler.getAST(); BOOST_REQUIRE(items != nullptr); - m_gasCosts = estimator.breakToStatementLevel( - estimator.performEstimation(*items, vector({&sourceUnit})), + m_gasCosts = GasEstimator::breakToStatementLevel( + GasEstimator::structuralEstimation(*items, vector({&sourceUnit})), {&sourceUnit} ); } @@ -70,6 +69,8 @@ public: BOOST_CHECK(gas.value == m_gasUsed); } + /// Compares the gas computed by PathGasMeter for the given signature (but unknown arguments) + /// against the actual gas usage computed by the VM on the given set of argument variants. void testRunTimeGas(std::string const& _sig, vector _argumentVariants) { u256 gasUsed = 0; @@ -80,12 +81,10 @@ public: gasUsed = max(gasUsed, m_gasUsed); } - auto state = make_shared(); - //TODO modify state to include function hash in calldata - PathGasMeter meter(*m_compiler.getRuntimeAssemblyItems()); - GasMeter::GasConsumption gas = meter.estimateMax(0, state); - cout << "VM: " << gasUsed << endl; - cout << "est: " << gas << endl; + GasMeter::GasConsumption gas = GasEstimator::functionalEstimation( + *m_compiler.getRuntimeAssemblyItems(), + _sig + ); BOOST_REQUIRE(!gas.isInfinite); BOOST_CHECK(gas.value == m_gasUsed); } @@ -207,6 +206,28 @@ BOOST_AUTO_TEST_CASE(function_calls) testRunTimeGas("f(uint256)", vector{encodeArgs(2), encodeArgs(8)}); } +BOOST_AUTO_TEST_CASE(multiple_external_functions) +{ + char const* sourceCode = R"( + contract test { + uint data; + uint data2; + function f(uint x) { + if (x > 7) + data2 = g(x**8) + 1; + else + data = 1; + } + function g(uint x) returns (uint) { + return data2; + } + } + )"; + testCreationTimeGas(sourceCode); + testRunTimeGas("f(uint256)", vector{encodeArgs(2), encodeArgs(8)}); + testRunTimeGas("g(uint256)", vector{encodeArgs(2)}); +} + BOOST_AUTO_TEST_SUITE_END() } From 3bbd4ba4e29a6fc7f72dc64dd6c908ad5a572eff Mon Sep 17 00:00:00 2001 From: CJentzsch Date: Fri, 22 May 2015 08:30:04 +0200 Subject: [PATCH 05/64] update wallet tests From 4c7d0bd5e80c7888d2ed2e565ee5ef466af67ac5 Mon Sep 17 00:00:00 2001 From: CJentzsch Date: Fri, 22 May 2015 18:02:22 +0200 Subject: [PATCH 06/64] update and expand wallet tests From 2e907bcf9248120bb7813df3438d9e6932bce96d Mon Sep 17 00:00:00 2001 From: CJentzsch Date: Fri, 22 May 2015 18:30:21 +0200 Subject: [PATCH 07/64] test clearing pending transactions From 7781f4dd7b978e1860642d74c40a2cb89f0b60a3 Mon Sep 17 00:00:00 2001 From: CJentzsch Date: Tue, 26 May 2015 03:07:26 +0200 Subject: [PATCH 08/64] fix output memory for CALL From ba9806b94553dd45343538f40c0dcb0fdebbbd76 Mon Sep 17 00:00:00 2001 From: CJentzsch Date: Tue, 26 May 2015 03:14:39 +0200 Subject: [PATCH 09/64] more tests From c9640e58ce6af1930cadfa67725b64b035acf1fe Mon Sep 17 00:00:00 2001 From: lotrf3 Date: Tue, 26 May 2015 02:18:19 -0500 Subject: [PATCH 10/64] Added upnp support to Windows --- CMakeLists.txt | 1 + 1 file changed, 1 insertion(+) diff --git a/CMakeLists.txt b/CMakeLists.txt index 39a235c58..be24ea115 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -69,6 +69,7 @@ endforeach(file) file(GLOB HEADERS "*.h") add_executable(testeth ${SRC_LIST} ${HEADERS}) +target_link_libraries(testeth Iphlpapi) target_link_libraries(testeth ${Boost_UNIT_TEST_FRAMEWORK_LIBRARIES}) target_link_libraries(testeth ${CURL_LIBRARIES}) target_link_libraries(testeth ethereum) From 6d87100377632bb8acf98856b4ac15837318ea37 Mon Sep 17 00:00:00 2001 From: CJentzsch Date: Tue, 26 May 2015 10:53:49 +0200 Subject: [PATCH 11/64] style From fbc331bd354ba0d0703ff8923e3c8dbd14f7a246 Mon Sep 17 00:00:00 2001 From: chriseth Date: Tue, 26 May 2015 11:29:41 +0200 Subject: [PATCH 12/64] Removed redundant std. --- libsolidity/GasMeter.cpp | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/libsolidity/GasMeter.cpp b/libsolidity/GasMeter.cpp index c09849c00..5f4426548 100644 --- a/libsolidity/GasMeter.cpp +++ b/libsolidity/GasMeter.cpp @@ -71,7 +71,7 @@ public: /// Compares the gas computed by PathGasMeter for the given signature (but unknown arguments) /// against the actual gas usage computed by the VM on the given set of argument variants. - void testRunTimeGas(std::string const& _sig, vector _argumentVariants) + void testRunTimeGas(string const& _sig, vector _argumentVariants) { u256 gasUsed = 0; FixedHash<4> hash(dev::sha3(_sig)); From c3befb40285c2ab8049044a67ce6d95ed8a7af35 Mon Sep 17 00:00:00 2001 From: CJentzsch Date: Tue, 26 May 2015 12:51:33 +0200 Subject: [PATCH 13/64] update wallet tests From 45f1a44e0a7622d0c624c8ea2783690ba6b287ca Mon Sep 17 00:00:00 2001 From: CJentzsch Date: Tue, 26 May 2015 13:21:33 +0200 Subject: [PATCH 14/64] update wallet contract to latest changes From 0f510a40c6aba9452d831519a14603d4d4e018d2 Mon Sep 17 00:00:00 2001 From: CJentzsch Date: Tue, 26 May 2015 14:44:26 +0200 Subject: [PATCH 15/64] fix blockhashOutOfRange test From 6790177df1c34950cea818b527d997d1a5f94213 Mon Sep 17 00:00:00 2001 From: lotrf3 Date: Tue, 26 May 2015 14:09:15 -0500 Subject: [PATCH 16/64] Ensure dependencies are conditional on Windows --- CMakeLists.txt | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/CMakeLists.txt b/CMakeLists.txt index be24ea115..a3b3188a9 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -69,7 +69,9 @@ endforeach(file) file(GLOB HEADERS "*.h") add_executable(testeth ${SRC_LIST} ${HEADERS}) -target_link_libraries(testeth Iphlpapi) +if((WIN32) + target_link_libraries(testeth Iphlpapi) +endif() target_link_libraries(testeth ${Boost_UNIT_TEST_FRAMEWORK_LIBRARIES}) target_link_libraries(testeth ${CURL_LIBRARIES}) target_link_libraries(testeth ethereum) From 373a296314f5de477a5950baacbab6b371d6674b Mon Sep 17 00:00:00 2001 From: lotrf3 Date: Tue, 26 May 2015 14:24:58 -0500 Subject: [PATCH 17/64] Fix dumbest syntax error ever --- CMakeLists.txt | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/CMakeLists.txt b/CMakeLists.txt index a3b3188a9..69a3d51e7 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -69,7 +69,7 @@ endforeach(file) file(GLOB HEADERS "*.h") add_executable(testeth ${SRC_LIST} ${HEADERS}) -if((WIN32) +if(WIN32) target_link_libraries(testeth Iphlpapi) endif() target_link_libraries(testeth ${Boost_UNIT_TEST_FRAMEWORK_LIBRARIES}) From ad91bcec934e54fcd0c3acb7ebd4b2b6c86a7f39 Mon Sep 17 00:00:00 2001 From: ethdev zug Date: Wed, 27 May 2015 00:46:45 +0100 Subject: [PATCH 18/64] changes required to make miniupnp working on windows --- CMakeLists.txt | 3 --- 1 file changed, 3 deletions(-) diff --git a/CMakeLists.txt b/CMakeLists.txt index 69a3d51e7..39a235c58 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -69,9 +69,6 @@ endforeach(file) file(GLOB HEADERS "*.h") add_executable(testeth ${SRC_LIST} ${HEADERS}) -if(WIN32) - target_link_libraries(testeth Iphlpapi) -endif() target_link_libraries(testeth ${Boost_UNIT_TEST_FRAMEWORK_LIBRARIES}) target_link_libraries(testeth ${CURL_LIBRARIES}) target_link_libraries(testeth ethereum) From f3d95236517ee03176275aa41b44b181a9f1b46a Mon Sep 17 00:00:00 2001 From: chriseth Date: Thu, 28 May 2015 14:43:46 +0200 Subject: [PATCH 19/64] Allow duplicate code removal for loops. --- libsolidity/SolidityOptimizer.cpp | 32 +++++++++++++++++++++++++++++++ 1 file changed, 32 insertions(+) diff --git a/libsolidity/SolidityOptimizer.cpp b/libsolidity/SolidityOptimizer.cpp index 744fc48ae..827d8833a 100644 --- a/libsolidity/SolidityOptimizer.cpp +++ b/libsolidity/SolidityOptimizer.cpp @@ -1004,6 +1004,38 @@ BOOST_AUTO_TEST_CASE(block_deduplicator) BOOST_CHECK_EQUAL(pushTags.size(), 2); } +BOOST_AUTO_TEST_CASE(block_deduplicator_loops) +{ + AssemblyItems input{ + u256(0), + eth::Instruction::SLOAD, + AssemblyItem(PushTag, 1), + AssemblyItem(PushTag, 2), + eth::Instruction::JUMPI, + eth::Instruction::JUMP, + AssemblyItem(Tag, 1), + u256(5), + u256(6), + eth::Instruction::SSTORE, + AssemblyItem(PushTag, 1), + eth::Instruction::JUMP, + AssemblyItem(Tag, 2), + u256(5), + u256(6), + eth::Instruction::SSTORE, + AssemblyItem(PushTag, 2), + eth::Instruction::JUMP, + }; + BlockDeduplicator dedup(input); + dedup.deduplicate(); + + set pushTags; + for (AssemblyItem const& item: input) + if (item.type() == PushTag) + pushTags.insert(item.data()); + BOOST_CHECK_EQUAL(pushTags.size(), 1); +} + BOOST_AUTO_TEST_SUITE_END() } From 786b57b88483c2f44c2b7ed4117ea43febd7f42b Mon Sep 17 00:00:00 2001 From: chriseth Date: Thu, 28 May 2015 16:20:50 +0200 Subject: [PATCH 20/64] Re-introduce string type. --- libsolidity/SolidityABIJSON.cpp | 27 +++++++++++++++ libsolidity/SolidityNameAndTypeResolution.cpp | 33 +++++++++++++++++++ 2 files changed, 60 insertions(+) diff --git a/libsolidity/SolidityABIJSON.cpp b/libsolidity/SolidityABIJSON.cpp index f9bf78d0a..f7390dc93 100644 --- a/libsolidity/SolidityABIJSON.cpp +++ b/libsolidity/SolidityABIJSON.cpp @@ -568,6 +568,33 @@ BOOST_AUTO_TEST_CASE(return_param_in_abi) checkInterface(sourceCode, interface); } +BOOST_AUTO_TEST_CASE(strings_and_arrays) +{ + // bug #1801 + char const* sourceCode = R"( + contract test { + function f(string a, bytes b, uint[] c) external {} + } + )"; + + char const* interface = R"( + [ + { + "constant" : false, + "name": "f", + "inputs": [ + { "name": "a", "type": "string" }, + { "name": "b", "type": "bytes" }, + { "name": "c", "type": "uint256[]" } + ], + "outputs": [], + "type" : "function" + } + ] + )"; + checkInterface(sourceCode, interface); +} + BOOST_AUTO_TEST_SUITE_END() } diff --git a/libsolidity/SolidityNameAndTypeResolution.cpp b/libsolidity/SolidityNameAndTypeResolution.cpp index c52bbf9de..48404aaac 100644 --- a/libsolidity/SolidityNameAndTypeResolution.cpp +++ b/libsolidity/SolidityNameAndTypeResolution.cpp @@ -1783,6 +1783,39 @@ BOOST_AUTO_TEST_CASE(uninitialized_var) BOOST_CHECK_THROW(parseTextAndResolveNames(sourceCode), TypeError); } +BOOST_AUTO_TEST_CASE(string) +{ + char const* sourceCode = R"( + contract C { + string s; + function f(string x) external { s = x; } + } + )"; + BOOST_CHECK_NO_THROW(parseTextAndResolveNames(sourceCode)); +} + +BOOST_AUTO_TEST_CASE(string_index) +{ + char const* sourceCode = R"( + contract C { + string s; + function f() { var a = s[2]; } + } + )"; + BOOST_CHECK_THROW(parseTextAndResolveNames(sourceCode), TypeError); +} + +BOOST_AUTO_TEST_CASE(string_length) +{ + char const* sourceCode = R"( + contract C { + string s; + function f() { var a = s.length; } + } + )"; + BOOST_CHECK_THROW(parseTextAndResolveNames(sourceCode), TypeError); +} + BOOST_AUTO_TEST_SUITE_END() } From 7a4cf44d42798e05cf65f85c1685751b68921d94 Mon Sep 17 00:00:00 2001 From: CJentzsch Date: Tue, 26 May 2015 12:52:32 +0200 Subject: [PATCH 21/64] add creation transaction merge cleanup From e40b9c89a9cdf1d4de861fd52b8a6211e17e546d Mon Sep 17 00:00:00 2001 From: arkpar Date: Wed, 27 May 2015 16:22:14 +0200 Subject: [PATCH 22/64] GetBlockHashesByNumber packet From 45d70933f5f3b4259429075666c016af391d0a4f Mon Sep 17 00:00:00 2001 From: Vlad Gluhovsky Date: Thu, 28 May 2015 12:31:55 +0200 Subject: [PATCH 23/64] topic encryption with pbkdf2 From f040b94453db7cf01d1c8387f56c07e4125995b0 Mon Sep 17 00:00:00 2001 From: Vlad Gluhovsky Date: Fri, 29 May 2015 12:25:48 +0200 Subject: [PATCH 24/64] gamma generation algorithm changed From 830a8a530f0d3ce2106cd653f7ee7e671b1adc27 Mon Sep 17 00:00:00 2001 From: CJentzsch Date: Fri, 29 May 2015 12:44:05 +0200 Subject: [PATCH 25/64] add test for PC overflow in jump From 0e56b6969b756f98f926b257dd07205cd5d26bf7 Mon Sep 17 00:00:00 2001 From: CJentzsch Date: Fri, 29 May 2015 12:49:59 +0200 Subject: [PATCH 26/64] fix test From e60f2e075dea2257a3b99ad61ba59e4cc60e5eba Mon Sep 17 00:00:00 2001 From: CJentzsch Date: Fri, 29 May 2015 12:59:01 +0200 Subject: [PATCH 27/64] add similiar tests for jumpi From 536d6139b12f7af6546c825ecf49cb50ca378bbc Mon Sep 17 00:00:00 2001 From: CJentzsch Date: Fri, 29 May 2015 15:17:08 +0200 Subject: [PATCH 28/64] add JUMPDEST attack test with JUMP From 50fc81af2bf7d757e3cf66f0d868141e6c9937f3 Mon Sep 17 00:00:00 2001 From: CJentzsch Date: Mon, 1 Jun 2015 09:48:19 +0200 Subject: [PATCH 29/64] add ability to test uncle as brother From 8faadacae898ac64b7c66d311b270075401565c7 Mon Sep 17 00:00:00 2001 From: CJentzsch Date: Mon, 1 Jun 2015 09:50:39 +0200 Subject: [PATCH 30/64] add uncle is brother test From d8547ab7e9599ac1ea0f35f3a55a08ab47b5f31e Mon Sep 17 00:00:00 2001 From: Lefteris Karapetsas Date: Tue, 19 May 2015 16:55:43 +0200 Subject: [PATCH 31/64] Test for issue #1977 Test that reproduces issue #1977 and will fail on ArchLinux with Boost version: 1.58.0-1 gcc version: 4.9.2-4 From baab63f79b0ece13fe1c7e197f655e1d5213e562 Mon Sep 17 00:00:00 2001 From: Lefteris Karapetsas Date: Mon, 1 Jun 2015 10:40:17 +0200 Subject: [PATCH 32/64] Move the u256 test to external_dependencies tests --- CMakeLists.txt | 1 + 1 file changed, 1 insertion(+) diff --git a/CMakeLists.txt b/CMakeLists.txt index 39a235c58..0812a278a 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -19,6 +19,7 @@ endmacro() add_subdirectory(fuzzTesting) add_subdirectory(libdevcore) +add_subdirectory(libdevcore/external_dependencies) add_subdirectory(libdevcrypto) add_subdirectory(libethcore) add_subdirectory(libethereum) From c7b2bd42d9044c2e3f5a30a148dd514eda2026a4 Mon Sep 17 00:00:00 2001 From: Lefteris Karapetsas Date: Mon, 1 Jun 2015 11:09:38 +0200 Subject: [PATCH 33/64] Move external-dependencies test out of lifdevcore --- CMakeLists.txt | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/CMakeLists.txt b/CMakeLists.txt index 0812a278a..d39a5cca1 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -19,13 +19,13 @@ endmacro() add_subdirectory(fuzzTesting) add_subdirectory(libdevcore) -add_subdirectory(libdevcore/external_dependencies) add_subdirectory(libdevcrypto) add_subdirectory(libethcore) add_subdirectory(libethereum) add_subdirectory(libevm) add_subdirectory(libnatspec) add_subdirectory(libp2p) +add_subdirectory(external-dependencies) if (JSCONSOLE) add_subdirectory(libjsengine) From 8967476a8d5371e81e224ec284fb9100816242c7 Mon Sep 17 00:00:00 2001 From: Liana Husikyan Date: Fri, 15 May 2015 12:23:13 +0200 Subject: [PATCH 34/64] added error jump instead of STOP instraction in case of exception --- libsolidity/SolidityCompiler.cpp | 192 --------------------------- libsolidity/SolidityEndToEndTest.cpp | 1 + 2 files changed, 1 insertion(+), 192 deletions(-) delete mode 100644 libsolidity/SolidityCompiler.cpp diff --git a/libsolidity/SolidityCompiler.cpp b/libsolidity/SolidityCompiler.cpp deleted file mode 100644 index dda7847ed..000000000 --- a/libsolidity/SolidityCompiler.cpp +++ /dev/null @@ -1,192 +0,0 @@ -/* - This file is part of cpp-ethereum. - - cpp-ethereum is free software: you can redistribute it and/or modify - it under the terms of the GNU General Public License as published by - the Free Software Foundation, either version 3 of the License, or - (at your option) any later version. - - cpp-ethereum is distributed in the hope that it will be useful, - but WITHOUT ANY WARRANTY; without even the implied warranty of - MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the - GNU General Public License for more details. - - You should have received a copy of the GNU General Public License - along with cpp-ethereum. If not, see . -*/ -/** - * @author Christian - * @date 2014 - * Unit tests for the solidity compiler. - */ - -#include -#include -#include -#include -#include -#include -#include -#include -#include - -using namespace std; -using namespace dev::eth; - -namespace dev -{ -namespace solidity -{ -namespace test -{ - -namespace -{ - -bytes compileContract(const string& _sourceCode) -{ - Parser parser; - ASTPointer sourceUnit; - BOOST_REQUIRE_NO_THROW(sourceUnit = parser.parse(make_shared(CharStream(_sourceCode)))); - NameAndTypeResolver resolver({}); - resolver.registerDeclarations(*sourceUnit); - for (ASTPointer const& node: sourceUnit->getNodes()) - if (ContractDefinition* contract = dynamic_cast(node.get())) - { - BOOST_REQUIRE_NO_THROW(resolver.resolveNamesAndTypes(*contract)); - } - for (ASTPointer const& node: sourceUnit->getNodes()) - if (ContractDefinition* contract = dynamic_cast(node.get())) - { - BOOST_REQUIRE_NO_THROW(resolver.checkTypeRequirements(*contract)); - } - for (ASTPointer const& node: sourceUnit->getNodes()) - if (ContractDefinition* contract = dynamic_cast(node.get())) - { - Compiler compiler; - compiler.compileContract(*contract, map{}); - - // debug - //compiler.streamAssembly(cout); - return compiler.getAssembledBytecode(); - } - BOOST_FAIL("No contract found in source."); - return bytes(); -} - -/// Checks that @a _compiledCode is present starting from offset @a _offset in @a _expectation. -/// This is necessary since the compiler will add boilerplate add the beginning that is not -/// tested here. -void checkCodePresentAt(bytes const& _compiledCode, bytes const& _expectation, unsigned _offset) -{ - BOOST_REQUIRE(_compiledCode.size() >= _offset + _expectation.size()); - auto checkStart = _compiledCode.begin() + _offset; - BOOST_CHECK_EQUAL_COLLECTIONS(checkStart, checkStart + _expectation.size(), - _expectation.begin(), _expectation.end()); -} - -} // end anonymous namespace - -BOOST_AUTO_TEST_SUITE(SolidityCompiler) - -BOOST_AUTO_TEST_CASE(smoke_test) -{ - char const* sourceCode = "contract test {\n" - " function f() { var x = 2; }\n" - "}\n"; - bytes code = compileContract(sourceCode); - - unsigned boilerplateSize = 73; - bytes expectation({byte(Instruction::JUMPDEST), - byte(Instruction::PUSH1), 0x0, // initialize local variable x - byte(Instruction::PUSH1), 0x2, - byte(Instruction::SWAP1), - byte(Instruction::POP), - byte(Instruction::JUMPDEST), - byte(Instruction::POP), - byte(Instruction::JUMP)}); - checkCodePresentAt(code, expectation, boilerplateSize); -} - -BOOST_AUTO_TEST_CASE(ifStatement) -{ - char const* sourceCode = "contract test {\n" - " function f() { bool x; if (x) 77; else if (!x) 78; else 79; }" - "}\n"; - bytes code = compileContract(sourceCode); - unsigned shift = 60; - unsigned boilerplateSize = 73; - bytes expectation({ - byte(Instruction::JUMPDEST), - byte(Instruction::PUSH1), 0x0, - byte(Instruction::DUP1), - byte(Instruction::ISZERO), - byte(Instruction::PUSH1), byte(0x0f + shift), // "false" target - byte(Instruction::JUMPI), - // "if" body - byte(Instruction::PUSH1), 0x4d, - byte(Instruction::POP), - byte(Instruction::PUSH1), byte(0x21 + shift), - byte(Instruction::JUMP), - // new check "else if" condition - byte(Instruction::JUMPDEST), - byte(Instruction::DUP1), - byte(Instruction::ISZERO), - byte(Instruction::ISZERO), - byte(Instruction::PUSH1), byte(0x1c + shift), - byte(Instruction::JUMPI), - // "else if" body - byte(Instruction::PUSH1), 0x4e, - byte(Instruction::POP), - byte(Instruction::PUSH1), byte(0x20 + shift), - byte(Instruction::JUMP), - // "else" body - byte(Instruction::JUMPDEST), - byte(Instruction::PUSH1), 0x4f, - byte(Instruction::POP), - }); - checkCodePresentAt(code, expectation, boilerplateSize); -} - -BOOST_AUTO_TEST_CASE(loops) -{ - char const* sourceCode = "contract test {\n" - " function f() { while(true){1;break;2;continue;3;return;4;} }" - "}\n"; - bytes code = compileContract(sourceCode); - unsigned shift = 60; - unsigned boilerplateSize = 73; - bytes expectation({byte(Instruction::JUMPDEST), - byte(Instruction::JUMPDEST), - byte(Instruction::PUSH1), 0x1, - byte(Instruction::ISZERO), - byte(Instruction::PUSH1), byte(0x21 + shift), - byte(Instruction::JUMPI), - byte(Instruction::PUSH1), 0x1, - byte(Instruction::POP), - byte(Instruction::PUSH1), byte(0x21 + shift), - byte(Instruction::JUMP), // break - byte(Instruction::PUSH1), 0x2, - byte(Instruction::POP), - byte(Instruction::PUSH1), byte(0x2 + shift), - byte(Instruction::JUMP), // continue - byte(Instruction::PUSH1), 0x3, - byte(Instruction::POP), - byte(Instruction::PUSH1), byte(0x22 + shift), - byte(Instruction::JUMP), // return - byte(Instruction::PUSH1), 0x4, - byte(Instruction::POP), - byte(Instruction::PUSH1), byte(0x2 + shift), - byte(Instruction::JUMP), - byte(Instruction::JUMPDEST), - byte(Instruction::JUMPDEST), - byte(Instruction::JUMP)}); - - checkCodePresentAt(code, expectation, boilerplateSize); -} - -BOOST_AUTO_TEST_SUITE_END() - -} -} -} // end namespaces diff --git a/libsolidity/SolidityEndToEndTest.cpp b/libsolidity/SolidityEndToEndTest.cpp index 503615a5a..f8d20d70f 100644 --- a/libsolidity/SolidityEndToEndTest.cpp +++ b/libsolidity/SolidityEndToEndTest.cpp @@ -1784,6 +1784,7 @@ BOOST_AUTO_TEST_CASE(contracts_as_addresses) } )"; compileAndRun(sourceCode, 20); + auto res = callContractFunction("getBalance()"); BOOST_REQUIRE(callContractFunction("getBalance()") == encodeArgs(u256(20 - 5), u256(5))); } From 042491e0ccae9600b6d513c9e9023d35c9184feb Mon Sep 17 00:00:00 2001 From: Liana Husikyan Date: Tue, 19 May 2015 14:55:12 +0200 Subject: [PATCH 35/64] added test to check evm exception --- libsolidity/SolidityEndToEndTest.cpp | 24 ++++++++++++++++++++++++ 1 file changed, 24 insertions(+) diff --git a/libsolidity/SolidityEndToEndTest.cpp b/libsolidity/SolidityEndToEndTest.cpp index f8d20d70f..faa5dad4d 100644 --- a/libsolidity/SolidityEndToEndTest.cpp +++ b/libsolidity/SolidityEndToEndTest.cpp @@ -4111,6 +4111,30 @@ BOOST_AUTO_TEST_CASE(struct_delete_struct_in_mapping) BOOST_CHECK(callContractFunction("deleteIt()") == encodeArgs(0)); } +BOOST_AUTO_TEST_CASE(evm_exceptions) +{ + char const* sourceCode = R"( + contract A { + uint[3] arr; + bool public test = false; + function getElement(uint i) returns (uint) + { + return arr[i]; + } + function testIt() returns (bool) + { + uint i = this.getElement(5); + test = true; + return true; + } + } + )"; + compileAndRun(sourceCode, 0, "A"); + BOOST_CHECK(callContractFunction("test()") == encodeArgs(false)); + BOOST_CHECK(callContractFunction("testIt()") == encodeArgs()); + BOOST_CHECK(callContractFunction("test()") == encodeArgs(false)); +} + BOOST_AUTO_TEST_SUITE_END() } From 4a2f18b41a9977045a7bd5e859f96715e7f27e84 Mon Sep 17 00:00:00 2001 From: Liana Husikyan Date: Thu, 21 May 2015 12:10:26 +0200 Subject: [PATCH 36/64] one more test to test the call of non-existed function Conflicts: test/libsolidity/SolidityEndToEndTest.cpp --- libsolidity/SolidityEndToEndTest.cpp | 28 +++++++++++++++++++++++++++- 1 file changed, 27 insertions(+), 1 deletion(-) diff --git a/libsolidity/SolidityEndToEndTest.cpp b/libsolidity/SolidityEndToEndTest.cpp index faa5dad4d..839ad7928 100644 --- a/libsolidity/SolidityEndToEndTest.cpp +++ b/libsolidity/SolidityEndToEndTest.cpp @@ -4111,7 +4111,7 @@ BOOST_AUTO_TEST_CASE(struct_delete_struct_in_mapping) BOOST_CHECK(callContractFunction("deleteIt()") == encodeArgs(0)); } -BOOST_AUTO_TEST_CASE(evm_exceptions) +BOOST_AUTO_TEST_CASE(evm_exceptions_out_of_band_access) { char const* sourceCode = R"( contract A { @@ -4135,6 +4135,32 @@ BOOST_AUTO_TEST_CASE(evm_exceptions) BOOST_CHECK(callContractFunction("test()") == encodeArgs(false)); } +BOOST_AUTO_TEST_CASE(evm_exceptions_when_calling_non_existing_function) +{ + char const* sourceCode = R"( + contract A { + uint public test = 0; + function badFunction() returns (uint) + { + this.call("123"); + test = 1; + return 2; + } + function testIt() returns (bool) + { + this.badFunction(); + test = 2; + return true; + } + } + )"; + compileAndRun(sourceCode, 0, "A"); + + BOOST_CHECK(callContractFunction("test()") == encodeArgs(0)); + BOOST_CHECK(callContractFunction("testIt()") == encodeArgs()); + BOOST_CHECK(callContractFunction("test()") == encodeArgs(0)); +} + BOOST_AUTO_TEST_SUITE_END() } From 82dc10d492d74fc1a9e07549f39d5ef2230822cc Mon Sep 17 00:00:00 2001 From: Liana Husikyan Date: Thu, 21 May 2015 13:02:24 +0200 Subject: [PATCH 37/64] test for exception in constructor --- libsolidity/SolidityEndToEndTest.cpp | 17 +++++++++++++++++ 1 file changed, 17 insertions(+) diff --git a/libsolidity/SolidityEndToEndTest.cpp b/libsolidity/SolidityEndToEndTest.cpp index 839ad7928..76952c676 100644 --- a/libsolidity/SolidityEndToEndTest.cpp +++ b/libsolidity/SolidityEndToEndTest.cpp @@ -4161,6 +4161,23 @@ BOOST_AUTO_TEST_CASE(evm_exceptions_when_calling_non_existing_function) BOOST_CHECK(callContractFunction("test()") == encodeArgs(0)); } +BOOST_AUTO_TEST_CASE(evm_exceptions_in_constructor) +{ + char const* sourceCode = R"( + contract A { + uint public test = 0; + function A() + { + this.call("123"); + test = 1; + } + } + )"; + compileAndRun(sourceCode, 0, "A"); + + BOOST_CHECK(callContractFunction("test()") == encodeArgs(1)); +} + BOOST_AUTO_TEST_SUITE_END() } From f1c042df8c66f13ba102bdfae03337c45173a248 Mon Sep 17 00:00:00 2001 From: Liana Husikyan Date: Thu, 21 May 2015 13:45:32 +0200 Subject: [PATCH 38/64] test for constructor (out of band exception) --- libsolidity/SolidityEndToEndTest.cpp | 22 ++++++++++++++++++++-- 1 file changed, 20 insertions(+), 2 deletions(-) diff --git a/libsolidity/SolidityEndToEndTest.cpp b/libsolidity/SolidityEndToEndTest.cpp index 76952c676..c150a488c 100644 --- a/libsolidity/SolidityEndToEndTest.cpp +++ b/libsolidity/SolidityEndToEndTest.cpp @@ -4161,7 +4161,7 @@ BOOST_AUTO_TEST_CASE(evm_exceptions_when_calling_non_existing_function) BOOST_CHECK(callContractFunction("test()") == encodeArgs(0)); } -BOOST_AUTO_TEST_CASE(evm_exceptions_in_constructor) +BOOST_AUTO_TEST_CASE(evm_exceptions_in_constructor_call_fail) { char const* sourceCode = R"( contract A { @@ -4169,7 +4169,25 @@ BOOST_AUTO_TEST_CASE(evm_exceptions_in_constructor) function A() { this.call("123"); - test = 1; + ++test; + } + } + )"; + compileAndRun(sourceCode, 0, "A"); + + BOOST_CHECK(callContractFunction("test()") == encodeArgs(1)); +} + +BOOST_AUTO_TEST_CASE(evm_exceptions_in_constructor_out_of_band) +{ + char const* sourceCode = R"( + contract A { + uint public test = 0; + uint[3] arr; + function A() + { + test = arr[5]; + ++test; } } )"; From fde4ed6bf60180d6212ec81f9ecbf630377087b3 Mon Sep 17 00:00:00 2001 From: Liana Husikyan Date: Fri, 22 May 2015 14:07:05 +0200 Subject: [PATCH 39/64] remove line for debugging --- libsolidity/SolidityEndToEndTest.cpp | 1 - 1 file changed, 1 deletion(-) diff --git a/libsolidity/SolidityEndToEndTest.cpp b/libsolidity/SolidityEndToEndTest.cpp index c150a488c..e4c5b47f1 100644 --- a/libsolidity/SolidityEndToEndTest.cpp +++ b/libsolidity/SolidityEndToEndTest.cpp @@ -1784,7 +1784,6 @@ BOOST_AUTO_TEST_CASE(contracts_as_addresses) } )"; compileAndRun(sourceCode, 20); - auto res = callContractFunction("getBalance()"); BOOST_REQUIRE(callContractFunction("getBalance()") == encodeArgs(u256(20 - 5), u256(5))); } From 19fb836bf6440db32c8a392618bb76d44ec90953 Mon Sep 17 00:00:00 2001 From: Liana Husikyan Date: Fri, 22 May 2015 17:48:38 +0200 Subject: [PATCH 40/64] modified the test --- libsolidity/SolidityEndToEndTest.cpp | 16 ++++++++++++---- 1 file changed, 12 insertions(+), 4 deletions(-) diff --git a/libsolidity/SolidityEndToEndTest.cpp b/libsolidity/SolidityEndToEndTest.cpp index e4c5b47f1..538174ab5 100644 --- a/libsolidity/SolidityEndToEndTest.cpp +++ b/libsolidity/SolidityEndToEndTest.cpp @@ -4164,24 +4164,32 @@ BOOST_AUTO_TEST_CASE(evm_exceptions_in_constructor_call_fail) { char const* sourceCode = R"( contract A { - uint public test = 0; function A() { this.call("123"); + + } + } + contract B { + uint public test = 1; + function testIt() + { + A a; ++test; } } )"; - compileAndRun(sourceCode, 0, "A"); + compileAndRun(sourceCode, 0, "B"); - BOOST_CHECK(callContractFunction("test()") == encodeArgs(1)); + BOOST_CHECK(callContractFunction("testIt()") == encodeArgs()); + BOOST_CHECK(callContractFunction("test()") == encodeArgs(2)); } BOOST_AUTO_TEST_CASE(evm_exceptions_in_constructor_out_of_band) { char const* sourceCode = R"( contract A { - uint public test = 0; + uint public test = 1; uint[3] arr; function A() { From 3ddae3209ed3ff8b7a4eae35a8984a7bb8d0ed58 Mon Sep 17 00:00:00 2001 From: Liana Husikyan Date: Tue, 26 May 2015 15:05:58 +0200 Subject: [PATCH 41/64] special handle of send --- libsolidity/SolidityEndToEndTest.cpp | 1 - 1 file changed, 1 deletion(-) diff --git a/libsolidity/SolidityEndToEndTest.cpp b/libsolidity/SolidityEndToEndTest.cpp index 538174ab5..efebbb2f0 100644 --- a/libsolidity/SolidityEndToEndTest.cpp +++ b/libsolidity/SolidityEndToEndTest.cpp @@ -4167,7 +4167,6 @@ BOOST_AUTO_TEST_CASE(evm_exceptions_in_constructor_call_fail) function A() { this.call("123"); - } } contract B { From ca8104397dd20195e34e1b6933daef7f84e1d3ba Mon Sep 17 00:00:00 2001 From: Liana Husikyan Date: Thu, 28 May 2015 14:48:37 +0200 Subject: [PATCH 42/64] removed exception when function is not found --- libsolidity/SolidityEndToEndTest.cpp | 32 ++-------------------------- 1 file changed, 2 insertions(+), 30 deletions(-) diff --git a/libsolidity/SolidityEndToEndTest.cpp b/libsolidity/SolidityEndToEndTest.cpp index efebbb2f0..d2faaae08 100644 --- a/libsolidity/SolidityEndToEndTest.cpp +++ b/libsolidity/SolidityEndToEndTest.cpp @@ -4080,7 +4080,6 @@ BOOST_AUTO_TEST_CASE(struct_delete_member) } )"; compileAndRun(sourceCode, 0, "test"); - auto res = callContractFunction("deleteMember()"); BOOST_CHECK(callContractFunction("deleteMember()") == encodeArgs(0)); } @@ -4106,7 +4105,6 @@ BOOST_AUTO_TEST_CASE(struct_delete_struct_in_mapping) } )"; compileAndRun(sourceCode, 0, "test"); - auto res = callContractFunction("deleteIt()"); BOOST_CHECK(callContractFunction("deleteIt()") == encodeArgs(0)); } @@ -4134,32 +4132,6 @@ BOOST_AUTO_TEST_CASE(evm_exceptions_out_of_band_access) BOOST_CHECK(callContractFunction("test()") == encodeArgs(false)); } -BOOST_AUTO_TEST_CASE(evm_exceptions_when_calling_non_existing_function) -{ - char const* sourceCode = R"( - contract A { - uint public test = 0; - function badFunction() returns (uint) - { - this.call("123"); - test = 1; - return 2; - } - function testIt() returns (bool) - { - this.badFunction(); - test = 2; - return true; - } - } - )"; - compileAndRun(sourceCode, 0, "A"); - - BOOST_CHECK(callContractFunction("test()") == encodeArgs(0)); - BOOST_CHECK(callContractFunction("testIt()") == encodeArgs()); - BOOST_CHECK(callContractFunction("test()") == encodeArgs(0)); -} - BOOST_AUTO_TEST_CASE(evm_exceptions_in_constructor_call_fail) { char const* sourceCode = R"( @@ -4184,7 +4156,7 @@ BOOST_AUTO_TEST_CASE(evm_exceptions_in_constructor_call_fail) BOOST_CHECK(callContractFunction("test()") == encodeArgs(2)); } -BOOST_AUTO_TEST_CASE(evm_exceptions_in_constructor_out_of_band) +BOOST_AUTO_TEST_CASE(evm_exceptions_in_constructor_out_of_baund) { char const* sourceCode = R"( contract A { @@ -4199,7 +4171,7 @@ BOOST_AUTO_TEST_CASE(evm_exceptions_in_constructor_out_of_band) )"; compileAndRun(sourceCode, 0, "A"); - BOOST_CHECK(callContractFunction("test()") == encodeArgs(1)); + //BOOST_CHECK(m_output.empty()); todo } BOOST_AUTO_TEST_SUITE_END() From 47f0e847e549d6c4bb13cafcb90b49832531cedd Mon Sep 17 00:00:00 2001 From: Liana Husikyan Date: Fri, 29 May 2015 15:39:42 +0200 Subject: [PATCH 43/64] style fixes in test/libsolidity/solidityExecutionFramework.h fixed the test --- libsolidity/SolidityEndToEndTest.cpp | 4 +- libsolidity/solidityExecutionFramework.h | 263 ++++++++++++----------- 2 files changed, 141 insertions(+), 126 deletions(-) diff --git a/libsolidity/SolidityEndToEndTest.cpp b/libsolidity/SolidityEndToEndTest.cpp index d2faaae08..ef7b5c2a4 100644 --- a/libsolidity/SolidityEndToEndTest.cpp +++ b/libsolidity/SolidityEndToEndTest.cpp @@ -4169,9 +4169,7 @@ BOOST_AUTO_TEST_CASE(evm_exceptions_in_constructor_out_of_baund) } } )"; - compileAndRun(sourceCode, 0, "A"); - - //BOOST_CHECK(m_output.empty()); todo + BOOST_CHECK(execute(sourceCode, 0, "A").empty()); } BOOST_AUTO_TEST_SUITE_END() diff --git a/libsolidity/solidityExecutionFramework.h b/libsolidity/solidityExecutionFramework.h index fa25fb12c..2c70415eb 100644 --- a/libsolidity/solidityExecutionFramework.h +++ b/libsolidity/solidityExecutionFramework.h @@ -40,142 +40,159 @@ namespace test class ExecutionFramework { public: - ExecutionFramework() { g_logVerbosity = 0; } + ExecutionFramework() { g_logVerbosity = 0; } - bytes const& compileAndRun(std::string const& _sourceCode, u256 const& _value = 0, std::string const& _contractName = "") - { - m_compiler.reset(false, m_addStandardSources); - m_compiler.addSource("", _sourceCode); - ETH_TEST_REQUIRE_NO_THROW(m_compiler.compile(m_optimize), "Compiling contract failed"); + bytes const& execute(std::string const& _sourceCode, u256 const& _value = 0, std::string const& _contractName = "") + { + m_compiler.reset(false, m_addStandardSources); + m_compiler.addSource("", _sourceCode); + ETH_TEST_REQUIRE_NO_THROW(m_compiler.compile(m_optimize), "Compiling contract failed"); - bytes code = m_compiler.getBytecode(_contractName); - sendMessage(code, true, _value); - BOOST_REQUIRE(!m_output.empty()); - return m_output; - } + bytes code = m_compiler.getBytecode(_contractName); + sendMessage(code, true, _value); + return m_output; + } - template - bytes const& callContractFunctionWithValue(std::string _sig, u256 const& _value, - Args const&... _arguments) - { - FixedHash<4> hash(dev::sha3(_sig)); - sendMessage(hash.asBytes() + encodeArgs(_arguments...), false, _value); - return m_output; - } + bytes const& compileAndRun(std::string const& _sourceCode, u256 const& _value = 0, std::string const& _contractName = "") + { + execute(_sourceCode, _value, _contractName); + BOOST_REQUIRE(!m_output.empty()); + return m_output; + } - template - bytes const& callContractFunction(std::string _sig, Args const&... _arguments) - { - return callContractFunctionWithValue(_sig, 0, _arguments...); - } + template + bytes const& callContractFunctionWithValue(std::string _sig, u256 const& _value, Args const&... _arguments) + { + FixedHash<4> hash(dev::sha3(_sig)); + sendMessage(hash.asBytes() + encodeArgs(_arguments...), false, _value); + return m_output; + } - template - void testSolidityAgainstCpp(std::string _sig, CppFunction const& _cppFunction, Args const&... _arguments) - { - bytes solidityResult = callContractFunction(_sig, _arguments...); - bytes cppResult = callCppAndEncodeResult(_cppFunction, _arguments...); - BOOST_CHECK_MESSAGE(solidityResult == cppResult, "Computed values do not match." - "\nSolidity: " + toHex(solidityResult) + "\nC++: " + toHex(cppResult)); - } + template + bytes const& callContractFunction(std::string _sig, Args const&... _arguments) + { + return callContractFunctionWithValue(_sig, 0, _arguments...); + } - template - void testSolidityAgainstCppOnRange(std::string _sig, CppFunction const& _cppFunction, - u256 const& _rangeStart, u256 const& _rangeEnd) - { - for (u256 argument = _rangeStart; argument < _rangeEnd; ++argument) - { - bytes solidityResult = callContractFunction(_sig, argument); - bytes cppResult = callCppAndEncodeResult(_cppFunction, argument); - BOOST_CHECK_MESSAGE(solidityResult == cppResult, "Computed values do not match." - "\nSolidity: " + toHex(solidityResult) + "\nC++: " + toHex(cppResult) + - "\nArgument: " + toHex(encode(argument))); - } - } + template + void testSolidityAgainstCpp(std::string _sig, CppFunction const& _cppFunction, Args const&... _arguments) + { + bytes solidityResult = callContractFunction(_sig, _arguments...); + bytes cppResult = callCppAndEncodeResult(_cppFunction, _arguments...); + BOOST_CHECK_MESSAGE( + solidityResult == cppResult, "Computed values do not match.\nSolidity: " + toHex(solidityResult) + "\nC++: " + toHex(cppResult)); + } - static bytes encode(bool _value) { return encode(byte(_value)); } - static bytes encode(int _value) { return encode(u256(_value)); } - static bytes encode(char const* _value) { return encode(std::string(_value)); } - static bytes encode(byte _value) { return bytes(31, 0) + bytes{_value}; } - static bytes encode(u256 const& _value) { return toBigEndian(_value); } - static bytes encode(h256 const& _value) { return _value.asBytes(); } - static bytes encode(bytes const& _value, bool _padLeft = true) - { - bytes padding = bytes((32 - _value.size() % 32) % 32, 0); - return _padLeft ? padding + _value : _value + padding; - } - static bytes encode(std::string const& _value) { return encode(asBytes(_value), false); } + template + void testSolidityAgainstCppOnRange( + std::string _sig, + CppFunction const& _cppFunction, + u256 const& _rangeStart, + u256 const& _rangeEnd + ) + { + for (u256 argument = _rangeStart; argument < _rangeEnd; ++argument) + { + bytes solidityResult = callContractFunction(_sig, argument); + bytes cppResult = callCppAndEncodeResult(_cppFunction, argument); + BOOST_CHECK_MESSAGE( + solidityResult == cppResult, + "Computed values do not match.\nSolidity: " + + toHex(solidityResult) + + "\nC++: " + + toHex(cppResult) + + "\nArgument: " + + toHex(encode(argument)) + ); + } + } - template - static bytes encodeArgs(FirstArg const& _firstArg, Args const&... _followingArgs) - { - return encode(_firstArg) + encodeArgs(_followingArgs...); - } - static bytes encodeArgs() - { - return bytes(); - } + static bytes encode(bool _value) { return encode(byte(_value)); } + static bytes encode(int _value) { return encode(u256(_value)); } + static bytes encode(char const* _value) { return encode(std::string(_value)); } + static bytes encode(byte _value) { return bytes(31, 0) + bytes{_value}; } + static bytes encode(u256 const& _value) { return toBigEndian(_value); } + static bytes encode(h256 const& _value) { return _value.asBytes(); } + static bytes encode(bytes const& _value, bool _padLeft = true) + { + bytes padding = bytes((32 - _value.size() % 32) % 32, 0); + return _padLeft ? padding + _value : _value + padding; + } + static bytes encode(std::string const& _value) { return encode(asBytes(_value), false); } + + template + static bytes encodeArgs(FirstArg const& _firstArg, Args const&... _followingArgs) + { + return encode(_firstArg) + encodeArgs(_followingArgs...); + } + static bytes encodeArgs() + { + return bytes(); + } private: - template - auto callCppAndEncodeResult(CppFunction const& _cppFunction, Args const&... _arguments) - -> typename std::enable_if::value, bytes>::type - { - _cppFunction(_arguments...); - return bytes(); - } - template - auto callCppAndEncodeResult(CppFunction const& _cppFunction, Args const&... _arguments) - -> typename std::enable_if::value, bytes>::type - { - return encode(_cppFunction(_arguments...)); - } + template + auto callCppAndEncodeResult(CppFunction const& _cppFunction, Args const&... _arguments) + -> typename std::enable_if::value, bytes>::type + { + _cppFunction(_arguments...); + return bytes(); + } + template + auto callCppAndEncodeResult(CppFunction const& _cppFunction, Args const&... _arguments) + -> typename std::enable_if::value, bytes>::type + { + return encode(_cppFunction(_arguments...)); + } protected: - void sendMessage(bytes const& _data, bool _isCreation, u256 const& _value = 0) - { - m_state.addBalance(m_sender, _value); // just in case - eth::Executive executive(m_state, eth::LastHashes(), 0); - eth::Transaction t = _isCreation ? eth::Transaction(_value, m_gasPrice, m_gas, _data, 0, KeyPair::create().sec()) - : eth::Transaction(_value, m_gasPrice, m_gas, m_contractAddress, _data, 0, KeyPair::create().sec()); - bytes transactionRLP = t.rlp(); - try - { - // this will throw since the transaction is invalid, but it should nevertheless store the transaction - executive.initialize(&transactionRLP); - executive.execute(); - } - catch (...) {} - if (_isCreation) - { - BOOST_REQUIRE(!executive.create(m_sender, _value, m_gasPrice, m_gas, &_data, m_sender)); - m_contractAddress = executive.newAddress(); - BOOST_REQUIRE(m_contractAddress); - BOOST_REQUIRE(m_state.addressHasCode(m_contractAddress)); - } - else - { - BOOST_REQUIRE(m_state.addressHasCode(m_contractAddress)); - BOOST_REQUIRE(!executive.call(m_contractAddress, m_contractAddress, m_sender, _value, m_gasPrice, &_data, m_gas, m_sender)); - } - BOOST_REQUIRE(executive.go()); - m_state.noteSending(m_sender); - executive.finalize(); - m_gasUsed = executive.gasUsed(); - m_output = executive.out().toVector(); - m_logs = executive.logs(); - } + void sendMessage(bytes const& _data, bool _isCreation, u256 const& _value = 0) + { + m_state.addBalance(m_sender, _value); // just in case + eth::Executive executive(m_state, eth::LastHashes(), 0); + eth::Transaction t = _isCreation ? eth::Transaction( + _value, m_gasPrice, m_gas, _data, 0, KeyPair::create().sec() + ) : eth::Transaction(_value, m_gasPrice, m_gas, m_contractAddress, _data, 0, KeyPair::create().sec()); - bool m_optimize = false; - bool m_addStandardSources = false; - dev::solidity::CompilerStack m_compiler; - Address m_sender; - Address m_contractAddress; - eth::State m_state; - u256 const m_gasPrice = 100 * eth::szabo; - u256 const m_gas = 100000000; - bytes m_output; - eth::LogEntries m_logs; - u256 m_gasUsed; + bytes transactionRLP = t.rlp(); + try + { + // this will throw since the transaction is invalid, but it should nevertheless store the transaction + executive.initialize(&transactionRLP); + executive.execute(); + } + catch (...) {} + if (_isCreation) + { + BOOST_REQUIRE(!executive.create(m_sender, _value, m_gasPrice, m_gas, &_data, m_sender)); + m_contractAddress = executive.newAddress(); + BOOST_REQUIRE(m_contractAddress); + BOOST_REQUIRE(m_state.addressHasCode(m_contractAddress)); + } + else + { + BOOST_REQUIRE(m_state.addressHasCode(m_contractAddress)); + BOOST_REQUIRE(!executive.call(m_contractAddress, m_contractAddress, m_sender, _value, m_gasPrice, &_data, m_gas, m_sender)); + } + BOOST_REQUIRE(executive.go()); + m_state.noteSending(m_sender); + executive.finalize(); + m_gasUsed = executive.gasUsed(); + m_output = executive.out().toVector(); + m_logs = executive.logs(); + } + + bool m_optimize = false; + bool m_addStandardSources = false; + dev::solidity::CompilerStack m_compiler; + Address m_sender; + Address m_contractAddress; + eth::State m_state; + u256 const m_gasPrice = 100 * eth::szabo; + u256 const m_gas = 100000000; + bytes m_output; + eth::LogEntries m_logs; + u256 m_gasUsed; }; } From 945418cc108f7abef4e03c6196a4e23245b1fec6 Mon Sep 17 00:00:00 2001 From: Liana Husikyan Date: Fri, 29 May 2015 18:38:57 +0200 Subject: [PATCH 44/64] style fixes --- libsolidity/SolidityEndToEndTest.cpp | 2 +- libsolidity/solidityExecutionFramework.h | 284 +++++++++++------------ 2 files changed, 142 insertions(+), 144 deletions(-) diff --git a/libsolidity/SolidityEndToEndTest.cpp b/libsolidity/SolidityEndToEndTest.cpp index ef7b5c2a4..db115b104 100644 --- a/libsolidity/SolidityEndToEndTest.cpp +++ b/libsolidity/SolidityEndToEndTest.cpp @@ -4145,7 +4145,7 @@ BOOST_AUTO_TEST_CASE(evm_exceptions_in_constructor_call_fail) uint public test = 1; function testIt() { - A a; + A a = new A(); ++test; } } diff --git a/libsolidity/solidityExecutionFramework.h b/libsolidity/solidityExecutionFramework.h index 2c70415eb..879667fde 100644 --- a/libsolidity/solidityExecutionFramework.h +++ b/libsolidity/solidityExecutionFramework.h @@ -40,159 +40,157 @@ namespace test class ExecutionFramework { public: - ExecutionFramework() { g_logVerbosity = 0; } + ExecutionFramework() { g_logVerbosity = 0; } - bytes const& execute(std::string const& _sourceCode, u256 const& _value = 0, std::string const& _contractName = "") - { - m_compiler.reset(false, m_addStandardSources); - m_compiler.addSource("", _sourceCode); - ETH_TEST_REQUIRE_NO_THROW(m_compiler.compile(m_optimize), "Compiling contract failed"); - - bytes code = m_compiler.getBytecode(_contractName); - sendMessage(code, true, _value); - return m_output; - } - - bytes const& compileAndRun(std::string const& _sourceCode, u256 const& _value = 0, std::string const& _contractName = "") - { - execute(_sourceCode, _value, _contractName); - BOOST_REQUIRE(!m_output.empty()); - return m_output; - } - - template - bytes const& callContractFunctionWithValue(std::string _sig, u256 const& _value, Args const&... _arguments) - { - FixedHash<4> hash(dev::sha3(_sig)); - sendMessage(hash.asBytes() + encodeArgs(_arguments...), false, _value); - return m_output; - } - - template - bytes const& callContractFunction(std::string _sig, Args const&... _arguments) - { - return callContractFunctionWithValue(_sig, 0, _arguments...); - } - - template - void testSolidityAgainstCpp(std::string _sig, CppFunction const& _cppFunction, Args const&... _arguments) - { - bytes solidityResult = callContractFunction(_sig, _arguments...); - bytes cppResult = callCppAndEncodeResult(_cppFunction, _arguments...); - BOOST_CHECK_MESSAGE( - solidityResult == cppResult, "Computed values do not match.\nSolidity: " + toHex(solidityResult) + "\nC++: " + toHex(cppResult)); - } - - template - void testSolidityAgainstCppOnRange( - std::string _sig, - CppFunction const& _cppFunction, - u256 const& _rangeStart, - u256 const& _rangeEnd - ) - { - for (u256 argument = _rangeStart; argument < _rangeEnd; ++argument) + bytes const& execute(std::string const& _sourceCode, u256 const& _value = 0, std::string const& _contractName = "") { - bytes solidityResult = callContractFunction(_sig, argument); - bytes cppResult = callCppAndEncodeResult(_cppFunction, argument); - BOOST_CHECK_MESSAGE( - solidityResult == cppResult, - "Computed values do not match.\nSolidity: " + - toHex(solidityResult) + - "\nC++: " + - toHex(cppResult) + - "\nArgument: " + - toHex(encode(argument)) - ); + m_compiler.reset(false, m_addStandardSources); + m_compiler.addSource("", _sourceCode); + ETH_TEST_REQUIRE_NO_THROW(m_compiler.compile(m_optimize), "Compiling contract failed"); + bytes code = m_compiler.getBytecode(_contractName); + sendMessage(code, true, _value); + return m_output; } - } - static bytes encode(bool _value) { return encode(byte(_value)); } - static bytes encode(int _value) { return encode(u256(_value)); } - static bytes encode(char const* _value) { return encode(std::string(_value)); } - static bytes encode(byte _value) { return bytes(31, 0) + bytes{_value}; } - static bytes encode(u256 const& _value) { return toBigEndian(_value); } - static bytes encode(h256 const& _value) { return _value.asBytes(); } - static bytes encode(bytes const& _value, bool _padLeft = true) - { - bytes padding = bytes((32 - _value.size() % 32) % 32, 0); - return _padLeft ? padding + _value : _value + padding; - } - static bytes encode(std::string const& _value) { return encode(asBytes(_value), false); } + bytes const& compileAndRun(std::string const& _sourceCode, u256 const& _value = 0, std::string const& _contractName = "") + { + execute(_sourceCode, _value, _contractName); + BOOST_REQUIRE(!m_output.empty()); + return m_output; + } - template - static bytes encodeArgs(FirstArg const& _firstArg, Args const&... _followingArgs) - { - return encode(_firstArg) + encodeArgs(_followingArgs...); - } - static bytes encodeArgs() - { - return bytes(); - } + template + bytes const& callContractFunctionWithValue(std::string _sig, u256 const& _value, Args const&... _arguments) + { + FixedHash<4> hash(dev::sha3(_sig)); + sendMessage(hash.asBytes() + encodeArgs(_arguments...), false, _value); + return m_output; + } + + template + bytes const& callContractFunction(std::string _sig, Args const&... _arguments) + { + return callContractFunctionWithValue(_sig, 0, _arguments...); + } + + template + void testSolidityAgainstCpp(std::string _sig, CppFunction const& _cppFunction, Args const&... _arguments) + { + bytes solidityResult = callContractFunction(_sig, _arguments...); + bytes cppResult = callCppAndEncodeResult(_cppFunction, _arguments...); + BOOST_CHECK_MESSAGE( + solidityResult == cppResult, + "Computed values do not match.\nSolidity: " + + toHex(solidityResult) + + "\nC++: " + + toHex(cppResult)); + } + + template + void testSolidityAgainstCppOnRange(std::string _sig, CppFunction const& _cppFunction, u256 const& _rangeStart, u256 const& _rangeEnd) + { + for (u256 argument = _rangeStart; argument < _rangeEnd; ++argument) + { + bytes solidityResult = callContractFunction(_sig, argument); + bytes cppResult = callCppAndEncodeResult(_cppFunction, argument); + BOOST_CHECK_MESSAGE( + solidityResult == cppResult, + "Computed values do not match.\nSolidity: " + + toHex(solidityResult) + + "\nC++: " + + toHex(cppResult) + + "\nArgument: " + + toHex(encode(argument)) + ); + } + } + + static bytes encode(bool _value) { return encode(byte(_value)); } + static bytes encode(int _value) { return encode(u256(_value)); } + static bytes encode(char const* _value) { return encode(std::string(_value)); } + static bytes encode(byte _value) { return bytes(31, 0) + bytes{_value}; } + static bytes encode(u256 const& _value) { return toBigEndian(_value); } + static bytes encode(h256 const& _value) { return _value.asBytes(); } + static bytes encode(bytes const& _value, bool _padLeft = true) + { + bytes padding = bytes((32 - _value.size() % 32) % 32, 0); + return _padLeft ? padding + _value : _value + padding; + } + static bytes encode(std::string const& _value) { return encode(asBytes(_value), false); } + + template + static bytes encodeArgs(FirstArg const& _firstArg, Args const&... _followingArgs) + { + return encode(_firstArg) + encodeArgs(_followingArgs...); + } + static bytes encodeArgs() + { + return bytes(); + } private: - template - auto callCppAndEncodeResult(CppFunction const& _cppFunction, Args const&... _arguments) - -> typename std::enable_if::value, bytes>::type - { - _cppFunction(_arguments...); - return bytes(); - } - template - auto callCppAndEncodeResult(CppFunction const& _cppFunction, Args const&... _arguments) - -> typename std::enable_if::value, bytes>::type - { - return encode(_cppFunction(_arguments...)); - } + template + auto callCppAndEncodeResult(CppFunction const& _cppFunction, Args const&... _arguments) + -> typename std::enable_if::value, bytes>::type + { + _cppFunction(_arguments...); + return bytes(); + } + template + auto callCppAndEncodeResult(CppFunction const& _cppFunction, Args const&... _arguments) + -> typename std::enable_if::value, bytes>::type + { + return encode(_cppFunction(_arguments...)); + } protected: - void sendMessage(bytes const& _data, bool _isCreation, u256 const& _value = 0) - { - m_state.addBalance(m_sender, _value); // just in case - eth::Executive executive(m_state, eth::LastHashes(), 0); - eth::Transaction t = _isCreation ? eth::Transaction( - _value, m_gasPrice, m_gas, _data, 0, KeyPair::create().sec() - ) : eth::Transaction(_value, m_gasPrice, m_gas, m_contractAddress, _data, 0, KeyPair::create().sec()); + void sendMessage(bytes const& _data, bool _isCreation, u256 const& _value = 0) + { + m_state.addBalance(m_sender, _value); // just in case + eth::Executive executive(m_state, eth::LastHashes(), 0); + eth::Transaction t = + _isCreation ? + eth::Transaction(_value, m_gasPrice, m_gas, _data, 0, KeyPair::create().sec()) : + eth::Transaction(_value, m_gasPrice, m_gas, m_contractAddress, _data, 0, KeyPair::create().sec()); + bytes transactionRLP = t.rlp(); + try + { + // this will throw since the transaction is invalid, but it should nevertheless store the transaction + executive.initialize(&transactionRLP); + executive.execute(); + } + catch (...) {} + if (_isCreation) + { + BOOST_REQUIRE(!executive.create(m_sender, _value, m_gasPrice, m_gas, &_data, m_sender)); + m_contractAddress = executive.newAddress(); + BOOST_REQUIRE(m_contractAddress); + BOOST_REQUIRE(m_state.addressHasCode(m_contractAddress)); + } + else + { + BOOST_REQUIRE(m_state.addressHasCode(m_contractAddress)); + BOOST_REQUIRE(!executive.call(m_contractAddress, m_contractAddress, m_sender, _value, m_gasPrice, &_data, m_gas, m_sender)); + } + BOOST_REQUIRE(executive.go()); + m_state.noteSending(m_sender); + executive.finalize(); + m_gasUsed = executive.gasUsed(); + m_output = executive.out().toVector(); + m_logs = executive.logs(); + } - bytes transactionRLP = t.rlp(); - try - { - // this will throw since the transaction is invalid, but it should nevertheless store the transaction - executive.initialize(&transactionRLP); - executive.execute(); - } - catch (...) {} - if (_isCreation) - { - BOOST_REQUIRE(!executive.create(m_sender, _value, m_gasPrice, m_gas, &_data, m_sender)); - m_contractAddress = executive.newAddress(); - BOOST_REQUIRE(m_contractAddress); - BOOST_REQUIRE(m_state.addressHasCode(m_contractAddress)); - } - else - { - BOOST_REQUIRE(m_state.addressHasCode(m_contractAddress)); - BOOST_REQUIRE(!executive.call(m_contractAddress, m_contractAddress, m_sender, _value, m_gasPrice, &_data, m_gas, m_sender)); - } - BOOST_REQUIRE(executive.go()); - m_state.noteSending(m_sender); - executive.finalize(); - m_gasUsed = executive.gasUsed(); - m_output = executive.out().toVector(); - m_logs = executive.logs(); - } - - bool m_optimize = false; - bool m_addStandardSources = false; - dev::solidity::CompilerStack m_compiler; - Address m_sender; - Address m_contractAddress; - eth::State m_state; - u256 const m_gasPrice = 100 * eth::szabo; - u256 const m_gas = 100000000; - bytes m_output; - eth::LogEntries m_logs; - u256 m_gasUsed; + bool m_optimize = false; + bool m_addStandardSources = false; + dev::solidity::CompilerStack m_compiler; + Address m_sender; + Address m_contractAddress; + eth::State m_state; + u256 const m_gasPrice = 100 * eth::szabo; + u256 const m_gas = 100000000; + bytes m_output; + eth::LogEntries m_logs; + u256 m_gasUsed; }; } From d863c8d088bd681762cbb4e3deb204e594108f81 Mon Sep 17 00:00:00 2001 From: Liana Husikyan Date: Mon, 1 Jun 2015 13:03:29 +0200 Subject: [PATCH 45/64] corrected intends in solidityExecutionFramwork.h --- libsolidity/solidityExecutionFramework.h | 276 +++++++++++------------ 1 file changed, 138 insertions(+), 138 deletions(-) diff --git a/libsolidity/solidityExecutionFramework.h b/libsolidity/solidityExecutionFramework.h index 879667fde..29f3c4710 100644 --- a/libsolidity/solidityExecutionFramework.h +++ b/libsolidity/solidityExecutionFramework.h @@ -40,157 +40,157 @@ namespace test class ExecutionFramework { public: - ExecutionFramework() { g_logVerbosity = 0; } +ExecutionFramework() { g_logVerbosity = 0; } - bytes const& execute(std::string const& _sourceCode, u256 const& _value = 0, std::string const& _contractName = "") - { - m_compiler.reset(false, m_addStandardSources); - m_compiler.addSource("", _sourceCode); - ETH_TEST_REQUIRE_NO_THROW(m_compiler.compile(m_optimize), "Compiling contract failed"); - bytes code = m_compiler.getBytecode(_contractName); - sendMessage(code, true, _value); - return m_output; - } + bytes const& execute(std::string const& _sourceCode, u256 const& _value = 0, std::string const& _contractName = "") + { + m_compiler.reset(false, m_addStandardSources); + m_compiler.addSource("", _sourceCode); + ETH_TEST_REQUIRE_NO_THROW(m_compiler.compile(m_optimize), "Compiling contract failed"); + bytes code = m_compiler.getBytecode(_contractName); + sendMessage(code, true, _value); + return m_output; + } - bytes const& compileAndRun(std::string const& _sourceCode, u256 const& _value = 0, std::string const& _contractName = "") - { - execute(_sourceCode, _value, _contractName); - BOOST_REQUIRE(!m_output.empty()); - return m_output; - } + bytes const& compileAndRun(std::string const& _sourceCode, u256 const& _value = 0, std::string const& _contractName = "") + { + execute(_sourceCode, _value, _contractName); + BOOST_REQUIRE(!m_output.empty()); + return m_output; + } - template - bytes const& callContractFunctionWithValue(std::string _sig, u256 const& _value, Args const&... _arguments) - { - FixedHash<4> hash(dev::sha3(_sig)); - sendMessage(hash.asBytes() + encodeArgs(_arguments...), false, _value); - return m_output; - } + template + bytes const& callContractFunctionWithValue(std::string _sig, u256 const& _value, Args const&... _arguments) + { + FixedHash<4> hash(dev::sha3(_sig)); + sendMessage(hash.asBytes() + encodeArgs(_arguments...), false, _value); + return m_output; + } - template - bytes const& callContractFunction(std::string _sig, Args const&... _arguments) - { - return callContractFunctionWithValue(_sig, 0, _arguments...); - } + template + bytes const& callContractFunction(std::string _sig, Args const&... _arguments) + { + return callContractFunctionWithValue(_sig, 0, _arguments...); + } - template - void testSolidityAgainstCpp(std::string _sig, CppFunction const& _cppFunction, Args const&... _arguments) - { - bytes solidityResult = callContractFunction(_sig, _arguments...); - bytes cppResult = callCppAndEncodeResult(_cppFunction, _arguments...); - BOOST_CHECK_MESSAGE( - solidityResult == cppResult, - "Computed values do not match.\nSolidity: " + - toHex(solidityResult) + - "\nC++: " + - toHex(cppResult)); - } + template + void testSolidityAgainstCpp(std::string _sig, CppFunction const& _cppFunction, Args const&... _arguments) + { + bytes solidityResult = callContractFunction(_sig, _arguments...); + bytes cppResult = callCppAndEncodeResult(_cppFunction, _arguments...); + BOOST_CHECK_MESSAGE( + solidityResult == cppResult, + "Computed values do not match.\nSolidity: " + + toHex(solidityResult) + + "\nC++: " + + toHex(cppResult)); + } - template - void testSolidityAgainstCppOnRange(std::string _sig, CppFunction const& _cppFunction, u256 const& _rangeStart, u256 const& _rangeEnd) - { - for (u256 argument = _rangeStart; argument < _rangeEnd; ++argument) - { - bytes solidityResult = callContractFunction(_sig, argument); - bytes cppResult = callCppAndEncodeResult(_cppFunction, argument); - BOOST_CHECK_MESSAGE( - solidityResult == cppResult, - "Computed values do not match.\nSolidity: " + - toHex(solidityResult) + - "\nC++: " + - toHex(cppResult) + - "\nArgument: " + - toHex(encode(argument)) - ); - } - } + template + void testSolidityAgainstCppOnRange(std::string _sig, CppFunction const& _cppFunction, u256 const& _rangeStart, u256 const& _rangeEnd) + { + for (u256 argument = _rangeStart; argument < _rangeEnd; ++argument) + { + bytes solidityResult = callContractFunction(_sig, argument); + bytes cppResult = callCppAndEncodeResult(_cppFunction, argument); + BOOST_CHECK_MESSAGE( + solidityResult == cppResult, + "Computed values do not match.\nSolidity: " + + toHex(solidityResult) + + "\nC++: " + + toHex(cppResult) + + "\nArgument: " + + toHex(encode(argument)) + ); + } + } - static bytes encode(bool _value) { return encode(byte(_value)); } - static bytes encode(int _value) { return encode(u256(_value)); } - static bytes encode(char const* _value) { return encode(std::string(_value)); } - static bytes encode(byte _value) { return bytes(31, 0) + bytes{_value}; } - static bytes encode(u256 const& _value) { return toBigEndian(_value); } - static bytes encode(h256 const& _value) { return _value.asBytes(); } - static bytes encode(bytes const& _value, bool _padLeft = true) - { - bytes padding = bytes((32 - _value.size() % 32) % 32, 0); - return _padLeft ? padding + _value : _value + padding; - } - static bytes encode(std::string const& _value) { return encode(asBytes(_value), false); } + static bytes encode(bool _value) { return encode(byte(_value)); } + static bytes encode(int _value) { return encode(u256(_value)); } + static bytes encode(char const* _value) { return encode(std::string(_value)); } + static bytes encode(byte _value) { return bytes(31, 0) + bytes{_value}; } + static bytes encode(u256 const& _value) { return toBigEndian(_value); } + static bytes encode(h256 const& _value) { return _value.asBytes(); } + static bytes encode(bytes const& _value, bool _padLeft = true) + { + bytes padding = bytes((32 - _value.size() % 32) % 32, 0); + return _padLeft ? padding + _value : _value + padding; + } + static bytes encode(std::string const& _value) { return encode(asBytes(_value), false); } - template - static bytes encodeArgs(FirstArg const& _firstArg, Args const&... _followingArgs) - { - return encode(_firstArg) + encodeArgs(_followingArgs...); - } - static bytes encodeArgs() - { - return bytes(); - } + template + static bytes encodeArgs(FirstArg const& _firstArg, Args const&... _followingArgs) + { + return encode(_firstArg) + encodeArgs(_followingArgs...); + } + static bytes encodeArgs() + { + return bytes(); + } private: - template - auto callCppAndEncodeResult(CppFunction const& _cppFunction, Args const&... _arguments) - -> typename std::enable_if::value, bytes>::type - { - _cppFunction(_arguments...); - return bytes(); - } - template - auto callCppAndEncodeResult(CppFunction const& _cppFunction, Args const&... _arguments) - -> typename std::enable_if::value, bytes>::type - { - return encode(_cppFunction(_arguments...)); - } + template + auto callCppAndEncodeResult(CppFunction const& _cppFunction, Args const&... _arguments) + -> typename std::enable_if::value, bytes>::type + { + _cppFunction(_arguments...); + return bytes(); + } + template + auto callCppAndEncodeResult(CppFunction const& _cppFunction, Args const&... _arguments) + -> typename std::enable_if::value, bytes>::type + { + return encode(_cppFunction(_arguments...)); + } protected: - void sendMessage(bytes const& _data, bool _isCreation, u256 const& _value = 0) - { - m_state.addBalance(m_sender, _value); // just in case - eth::Executive executive(m_state, eth::LastHashes(), 0); - eth::Transaction t = - _isCreation ? - eth::Transaction(_value, m_gasPrice, m_gas, _data, 0, KeyPair::create().sec()) : - eth::Transaction(_value, m_gasPrice, m_gas, m_contractAddress, _data, 0, KeyPair::create().sec()); - bytes transactionRLP = t.rlp(); - try - { - // this will throw since the transaction is invalid, but it should nevertheless store the transaction - executive.initialize(&transactionRLP); - executive.execute(); - } - catch (...) {} - if (_isCreation) - { - BOOST_REQUIRE(!executive.create(m_sender, _value, m_gasPrice, m_gas, &_data, m_sender)); - m_contractAddress = executive.newAddress(); - BOOST_REQUIRE(m_contractAddress); - BOOST_REQUIRE(m_state.addressHasCode(m_contractAddress)); - } - else - { - BOOST_REQUIRE(m_state.addressHasCode(m_contractAddress)); - BOOST_REQUIRE(!executive.call(m_contractAddress, m_contractAddress, m_sender, _value, m_gasPrice, &_data, m_gas, m_sender)); - } - BOOST_REQUIRE(executive.go()); - m_state.noteSending(m_sender); - executive.finalize(); - m_gasUsed = executive.gasUsed(); - m_output = executive.out().toVector(); - m_logs = executive.logs(); - } + void sendMessage(bytes const& _data, bool _isCreation, u256 const& _value = 0) + { + m_state.addBalance(m_sender, _value); // just in case + eth::Executive executive(m_state, eth::LastHashes(), 0); + eth::Transaction t = + _isCreation ? + eth::Transaction(_value, m_gasPrice, m_gas, _data, 0, KeyPair::create().sec()) : + eth::Transaction(_value, m_gasPrice, m_gas, m_contractAddress, _data, 0, KeyPair::create().sec()); + bytes transactionRLP = t.rlp(); + try + { + // this will throw since the transaction is invalid, but it should nevertheless store the transaction + executive.initialize(&transactionRLP); + executive.execute(); + } + catch (...) {} + if (_isCreation) + { + BOOST_REQUIRE(!executive.create(m_sender, _value, m_gasPrice, m_gas, &_data, m_sender)); + m_contractAddress = executive.newAddress(); + BOOST_REQUIRE(m_contractAddress); + BOOST_REQUIRE(m_state.addressHasCode(m_contractAddress)); + } + else + { + BOOST_REQUIRE(m_state.addressHasCode(m_contractAddress)); + BOOST_REQUIRE(!executive.call(m_contractAddress, m_contractAddress, m_sender, _value, m_gasPrice, &_data, m_gas, m_sender)); + } + BOOST_REQUIRE(executive.go()); + m_state.noteSending(m_sender); + executive.finalize(); + m_gasUsed = executive.gasUsed(); + m_output = executive.out().toVector(); + m_logs = executive.logs(); + } - bool m_optimize = false; - bool m_addStandardSources = false; - dev::solidity::CompilerStack m_compiler; - Address m_sender; - Address m_contractAddress; - eth::State m_state; - u256 const m_gasPrice = 100 * eth::szabo; - u256 const m_gas = 100000000; - bytes m_output; - eth::LogEntries m_logs; - u256 m_gasUsed; + bool m_optimize = false; + bool m_addStandardSources = false; + dev::solidity::CompilerStack m_compiler; + Address m_sender; + Address m_contractAddress; + eth::State m_state; + u256 const m_gasPrice = 100 * eth::szabo; + u256 const m_gas = 100000000; + bytes m_output; + eth::LogEntries m_logs; + u256 m_gasUsed; }; } From 4c9e1170b916fde1a7a1cab196c8c26957385e11 Mon Sep 17 00:00:00 2001 From: Dimitry Date: Mon, 1 Jun 2015 17:34:11 +0300 Subject: [PATCH 46/64] BlockWeight: uncle POW issue From c6a8938ed74b54b0351f30d8d4a3601c8d1eb871 Mon Sep 17 00:00:00 2001 From: Liana Husikyan Date: Mon, 1 Jun 2015 16:39:09 +0200 Subject: [PATCH 47/64] fixed CALL case. added exception --- libsolidity/solidityExecutionFramework.h | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/libsolidity/solidityExecutionFramework.h b/libsolidity/solidityExecutionFramework.h index 29f3c4710..ddbbb0161 100644 --- a/libsolidity/solidityExecutionFramework.h +++ b/libsolidity/solidityExecutionFramework.h @@ -40,7 +40,7 @@ namespace test class ExecutionFramework { public: -ExecutionFramework() { g_logVerbosity = 0; } + ExecutionFramework() { g_logVerbosity = 0; } bytes const& execute(std::string const& _sourceCode, u256 const& _value = 0, std::string const& _contractName = "") { From b810df04f0ebcc65ed7a57fa650d5bb090c8b31d Mon Sep 17 00:00:00 2001 From: Liana Husikyan Date: Mon, 1 Jun 2015 16:48:13 +0200 Subject: [PATCH 48/64] renamed the test framwork function. --- libsolidity/SolidityEndToEndTest.cpp | 2 +- libsolidity/solidityExecutionFramework.h | 4 ++-- 2 files changed, 3 insertions(+), 3 deletions(-) diff --git a/libsolidity/SolidityEndToEndTest.cpp b/libsolidity/SolidityEndToEndTest.cpp index db115b104..9f6f27d7d 100644 --- a/libsolidity/SolidityEndToEndTest.cpp +++ b/libsolidity/SolidityEndToEndTest.cpp @@ -4169,7 +4169,7 @@ BOOST_AUTO_TEST_CASE(evm_exceptions_in_constructor_out_of_baund) } } )"; - BOOST_CHECK(execute(sourceCode, 0, "A").empty()); + BOOST_CHECK(compileAndRunWthoutCheck(sourceCode, 0, "A").empty()); } BOOST_AUTO_TEST_SUITE_END() diff --git a/libsolidity/solidityExecutionFramework.h b/libsolidity/solidityExecutionFramework.h index ddbbb0161..c29257dd9 100644 --- a/libsolidity/solidityExecutionFramework.h +++ b/libsolidity/solidityExecutionFramework.h @@ -42,7 +42,7 @@ class ExecutionFramework public: ExecutionFramework() { g_logVerbosity = 0; } - bytes const& execute(std::string const& _sourceCode, u256 const& _value = 0, std::string const& _contractName = "") + bytes const& compileAndRunWthoutCheck(std::string const& _sourceCode, u256 const& _value = 0, std::string const& _contractName = "") { m_compiler.reset(false, m_addStandardSources); m_compiler.addSource("", _sourceCode); @@ -54,7 +54,7 @@ public: bytes const& compileAndRun(std::string const& _sourceCode, u256 const& _value = 0, std::string const& _contractName = "") { - execute(_sourceCode, _value, _contractName); + compileAndRunWthoutCheck(_sourceCode, _value, _contractName); BOOST_REQUIRE(!m_output.empty()); return m_output; } From 17841792d9b399db071cbb3e7f885122b9a2e321 Mon Sep 17 00:00:00 2001 From: winsvega Date: Thu, 21 May 2015 17:52:39 +0300 Subject: [PATCH 49/64] Random Code From ddcdf450f0431c8693c871d2500e95acc183179f Mon Sep 17 00:00:00 2001 From: winsvega Date: Fri, 22 May 2015 17:28:47 +0300 Subject: [PATCH 50/64] undo vmTest From dd4cda62bca4dccfdb5ceab90dc13b5e527fb559 Mon Sep 17 00:00:00 2001 From: winsvega Date: Fri, 22 May 2015 21:04:12 +0300 Subject: [PATCH 51/64] Random Codes With Probability From 5cfec260f797fe3568b17a77cfd9f0f646bd1ce2 Mon Sep 17 00:00:00 2001 From: Dimitry Date: Tue, 26 May 2015 16:27:22 +0300 Subject: [PATCH 52/64] Random test code --- TestHelper.cpp | 4 +++- TestHelper.h | 1 + 2 files changed, 4 insertions(+), 1 deletion(-) diff --git a/TestHelper.cpp b/TestHelper.cpp index 476d1ecf9..4836ce7f3 100644 --- a/TestHelper.cpp +++ b/TestHelper.cpp @@ -328,7 +328,7 @@ void ImportTest::exportTest(bytes const& _output, State const& _statePost) { // export output - m_TestObject["out"] = _output.size() > 4096 ? "#" + toString(_output.size()) : toHex(_output, 2, HexPrefix::Add); + m_TestObject["out"] = (_output.size() > 4096 && !Options::get().fulloutput) ? "#" + toString(_output.size()) : toHex(_output, 2, HexPrefix::Add); // export logs m_TestObject["logs"] = exportLog(_statePost.pending().size() ? _statePost.log(0) : LogEntries()); @@ -760,6 +760,8 @@ Options::Options() else singleTestName = std::move(name1); } + else if (arg == "--fulloutput") + fulloutput = true; } } diff --git a/TestHelper.h b/TestHelper.h index fc6c77fad..8f0c73bf3 100644 --- a/TestHelper.h +++ b/TestHelper.h @@ -184,6 +184,7 @@ public: bool stats = false; ///< Execution time stats std::string statsOutFile; ///< Stats output file. "out" for standard output bool checkState = false;///< Throw error when checking test states + bool fulloutput = false;///< Replace large output to just it's length /// Test selection /// @{ From efe141aaba90eb6a5aa06b045513a609f28a5839 Mon Sep 17 00:00:00 2001 From: Dimitry Date: Tue, 26 May 2015 16:51:29 +0300 Subject: [PATCH 53/64] Random Code: Style From 3bbef4fb328e3e48d637b9cd29aac4e65770e32f Mon Sep 17 00:00:00 2001 From: Dimitry Date: Tue, 26 May 2015 18:24:47 +0300 Subject: [PATCH 54/64] Random Code: fulloutput option + test --- TestHelper.cpp | 1 - 1 file changed, 1 deletion(-) diff --git a/TestHelper.cpp b/TestHelper.cpp index 4836ce7f3..5ace49e5d 100644 --- a/TestHelper.cpp +++ b/TestHelper.cpp @@ -771,7 +771,6 @@ Options const& Options::get() return instance; } - LastHashes lastHashes(u256 _currentBlockNumber) { LastHashes ret; From b1f91d1891f5233731d5530713a5c4296f3f6730 Mon Sep 17 00:00:00 2001 From: Dimitry Date: Wed, 27 May 2015 15:45:00 +0300 Subject: [PATCH 55/64] Random Code: exceptions when filling rnd StateTest From 8e25eb5842bc27d71feb4d20ba0a1129a88be783 Mon Sep 17 00:00:00 2001 From: Dimitry Date: Wed, 27 May 2015 22:51:53 +0300 Subject: [PATCH 56/64] Random Code: smart opcode fuzz From 5452c8f7e3f0161c6b8b580c19692ffce89b9008 Mon Sep 17 00:00:00 2001 From: Dimitry Date: Fri, 29 May 2015 17:06:11 +0300 Subject: [PATCH 57/64] Random Code: cath fill exceptions --- TestHelper.cpp | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/TestHelper.cpp b/TestHelper.cpp index 5ace49e5d..793e05652 100644 --- a/TestHelper.cpp +++ b/TestHelper.cpp @@ -588,7 +588,7 @@ void userDefinedTest(std::function doTests) oSingleTest[pos->first] = pos->second; json_spirit::mValue v_singleTest(oSingleTest); - doTests(v_singleTest, false); + doTests(v_singleTest, test::Options::get().fillTests); } catch (Exception const& _e) { From f415d712e687251178fbf3123977de899c415b5b Mon Sep 17 00:00:00 2001 From: Dimitry Date: Fri, 29 May 2015 17:33:24 +0300 Subject: [PATCH 58/64] Random code: style From 289760ccd97558f1516eba63feddd76bcdef3dad Mon Sep 17 00:00:00 2001 From: Dimitry Date: Mon, 1 Jun 2015 14:07:31 +0300 Subject: [PATCH 59/64] Random Code: build issues From 863799916a8905742e36bcb1ac63399c6fb70dba Mon Sep 17 00:00:00 2001 From: CJentzsch Date: Mon, 1 Jun 2015 16:51:48 +0200 Subject: [PATCH 60/64] add ambiguous push test From f47148bfdd236776853c1df65905c95612cf7ab8 Mon Sep 17 00:00:00 2001 From: CJentzsch Date: Mon, 1 Jun 2015 16:59:06 +0200 Subject: [PATCH 61/64] fix block chain tests creation From d32f1e4edce51cb288464ba9046da38a68483368 Mon Sep 17 00:00:00 2001 From: CJentzsch Date: Tue, 2 Jun 2015 09:34:27 +0200 Subject: [PATCH 62/64] add EqualUncleInTwoDifferentBlocks test Conflicts: test/libethereum/blockchain.cpp From c4dad409a9a5cffb25cc441c8830b0b3225d00f5 Mon Sep 17 00:00:00 2001 From: CJentzsch Date: Mon, 1 Jun 2015 21:48:06 +0200 Subject: [PATCH 63/64] fix bruncle test From 5614c5906f26a68996a845a7ef15e8b979e9c31a Mon Sep 17 00:00:00 2001 From: CJentzsch Date: Mon, 1 Jun 2015 22:27:24 +0200 Subject: [PATCH 64/64] style