From 3d199bf4d50206077c0d84122ff0ef70fc174d10 Mon Sep 17 00:00:00 2001 From: CJentzsch Date: Tue, 7 Apr 2015 16:56:27 +0200 Subject: [PATCH 01/15] remove wrong stateroot uncle header test --- bcUncleHeaderValiditiyFiller.json | 96 +------------------------------ 1 file changed, 1 insertion(+), 95 deletions(-) diff --git a/bcUncleHeaderValiditiyFiller.json b/bcUncleHeaderValiditiyFiller.json index 9725a3241..edcd298bc 100644 --- a/bcUncleHeaderValiditiyFiller.json +++ b/bcUncleHeaderValiditiyFiller.json @@ -656,101 +656,7 @@ ] }, - "wrongStateRoot" : { - "genesisBlockHeader" : { - "bloom" : "00000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000", - "coinbase" : "0x8888f1f195afa192cfee860698584c030f4c9db1", - "difficulty" : "231072", - "extraData" : "0x42", - "gasLimit" : "3141592", - "gasUsed" : "0", - "number" : "0", - "parentHash" : "0x0000000000000000000000000000000000000000000000000000000000000000", - "receiptTrie" : "0x56e81f171bcc55a6ff8345e692c0f86e5b48e01b996cadc001622fb5e363b421", - "stateRoot" : "0xf99eb1626cfa6db435c0836235942d7ccaa935f1ae247d3f1c21e495685f903a", - "timestamp" : "0x54c98c81", - "mixHash" : "0x56e81f171bcc55a6ff8345e692c0f86e5b48e01b996cadc001622fb5e363b421", - "nonce" : "0x0102030405060708", - "transactionsTrie" : "0x56e81f171bcc55a6ff8345e692c0f86e5b48e01b996cadc001622fb5e363b421", - "uncleHash" : "0x1dcc4de8dec75d7aab85b567b6ccd41ad312451b948a7413f0a142fd40d49347" - }, - "pre" : { - "a94f5374fce5edbc8e2a8697c15331677e6ebf0b" : { - "balance" : "10000000000000", - "nonce" : "0", - "code" : "", - "storage": {} - } - }, - "blocks" : [ - { - "transactions" : [ - { - "data" : "", - "gasLimit" : "314159", - "gasPrice" : "1", - "nonce" : "0", - "secretKey" : "45a915e4d060149eb4365960e6a7a45f334393093061116b197e3240065ff2d8", - "to" : "095e7baea6a6c7c4c2dfeb977efac326af552d87", - "value" : "10" - } - ], - "uncleHeaders" : [ - ] - }, - { - "transactions" : [ - { - "data" : "", - "gasLimit" : "314159", - "gasPrice" : "1", - "nonce" : "1", - "secretKey" : "45a915e4d060149eb4365960e6a7a45f334393093061116b197e3240065ff2d8", - "to" : "095e7baea6a6c7c4c2dfeb977efac326af552d87", - "value" : "10" - } - ], - "uncleHeaders" : [ - ] - }, - { - "transactions" : [ - { - "data" : "", - "gasLimit" : "314159", - "gasPrice" : "1", - "nonce" : "2", - "secretKey" : "45a915e4d060149eb4365960e6a7a45f334393093061116b197e3240065ff2d8", - "to" : "095e7baea6a6c7c4c2dfeb977efac326af552d87", - "value" : "10" - } - ], - "uncleHeaders" : [ - { - "overwriteAndRedoPoW" : "stateRoot", - "bloom" : "00000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000", - "coinbase" : "acde5374fce5edbc8e2a8697c15331677e6ebf0b", - "difficulty" : "230848", - "extraData" : "0x", - "gasLimit" : "4141592", - "gasUsed" : "150000", - "hash" : "9de9879b6a81d1b6c4993c63c90a3c9d1e775f14572694778e828bc64972ae04", - "mixHash" : "b557f905d29ed0fca99d65d0adcce698dee97cf72a13c7cd8d7a7826b8eee770", - "nonce" : "18a524c1790fa83b", - "number" : "2", - "parentHash" : "6134fc6b5d99ee03c4aab1592640f6f9dcbc850668d75d631aee34989b938fae", - "receiptTrie" : "56e81f171bcc55a6ff8345e692c0f86e5b48e01b996cadc001622fb5e363b421", - "stateRoot" : "bad40b30d613c35dad43e3693329e1b1ee6350f989cf46a288025a1cbfdab9cd", - "timestamp" : "1528353694", - "transactionsTrie" : "56e81f171bcc55a6ff8345e692c0f86e5b48e01b996cadc001622fb5e363b421", - "uncleHash" : "1dcc4de8dec75d7aab85b567b6ccd41ad312451b948a7413f0a142fd40d49347" - } - ] - } - ] - }, - - "timestampTooLow" : { + "timestampTooLow" : { "genesisBlockHeader" : { "bloom" : "00000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000", "coinbase" : "0x8888f1f195afa192cfee860698584c030f4c9db1", From ca1ac5df609f98c291feffc57dda6e22453ef030 Mon Sep 17 00:00:00 2001 From: subtly Date: Tue, 21 Apr 2015 05:31:33 -0400 Subject: [PATCH 02/15] update tests (v4 endpoint) From 78a03553431ea32c41586b3c573ba421e488c10b Mon Sep 17 00:00:00 2001 From: subtly Date: Tue, 21 Apr 2015 05:38:39 -0400 Subject: [PATCH 03/15] update net tests (v4 endpoint) From e8b0470eb6e6afa8aad96d3695145b339a7183fa Mon Sep 17 00:00:00 2001 From: subtly Date: Tue, 21 Apr 2015 06:13:31 -0400 Subject: [PATCH 04/15] update peer host test. support unspecified ip. From 685d08c41b4f3d6aa3dac31f185095bfeabaa402 Mon Sep 17 00:00:00 2001 From: subtly Date: Tue, 21 Apr 2015 18:13:45 -0400 Subject: [PATCH 05/15] more test updates (v4 endpoints. #1557, #1558) From ce6db27a5189b8178564c06a4abec92a7b73a732 Mon Sep 17 00:00:00 2001 From: subtly Date: Thu, 23 Apr 2015 03:04:35 +0100 Subject: [PATCH 06/15] handle new endpoint properties for ping From fb589c54acc8f7aa1da162f76b83e5958a9bdc13 Mon Sep 17 00:00:00 2001 From: subtly Date: Mon, 27 Apr 2015 14:17:30 +0100 Subject: [PATCH 07/15] encapsulate IP endpoint address as byte string From 1b0291c9ee1a3347ea8d668b548508e2bbcecf93 Mon Sep 17 00:00:00 2001 From: CJentzsch Date: Thu, 30 Apr 2015 17:34:06 +0200 Subject: [PATCH 08/15] add wallet test From ebef9d43d4b775699a5bfdb0823900cd925d8d1e Mon Sep 17 00:00:00 2001 From: CJentzsch Date: Sat, 2 May 2015 08:55:05 +0200 Subject: [PATCH 09/15] first wallet tests From b7432b8140891f3370d67aa57b9015eceff9c121 Mon Sep 17 00:00:00 2001 From: CJentzsch Date: Tue, 5 May 2015 08:00:33 +0200 Subject: [PATCH 10/15] tests for contract multiowned From 6bd430baa1580087b5640af1782cd060a0ea6862 Mon Sep 17 00:00:00 2001 From: CJentzsch Date: Tue, 5 May 2015 10:13:41 +0200 Subject: [PATCH 11/15] add day limit tests From dc0c5b74f95c95a14c66c8d6f931d13ae408ddf7 Mon Sep 17 00:00:00 2001 From: CJentzsch Date: Tue, 5 May 2015 11:01:06 +0200 Subject: [PATCH 12/15] finish wallet state tests From 75982d444f52e864e56daf6054c2f13835b3a961 Mon Sep 17 00:00:00 2001 From: CJentzsch Date: Tue, 5 May 2015 15:31:43 +0200 Subject: [PATCH 13/15] add bc wallet test From 60f335b40091231dde9e63b2b414e49aff8a7e5c Mon Sep 17 00:00:00 2001 From: chriseth Date: Wed, 6 May 2015 10:43:59 +0200 Subject: [PATCH 14/15] Structural gas estimator. --- GasMeter.cpp | 98 ++++++++++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 98 insertions(+) create mode 100644 GasMeter.cpp diff --git a/GasMeter.cpp b/GasMeter.cpp new file mode 100644 index 000000000..0ffe41712 --- /dev/null +++ b/GasMeter.cpp @@ -0,0 +1,98 @@ +/* + 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 2015 + * Unit tests for the gas estimator. + */ + +#include +#include +#include +#include + +using namespace std; +using namespace dev::eth; +using namespace dev::solidity; + +namespace dev +{ +namespace solidity +{ +namespace test +{ + +class GasMeterTestFramework: public ExecutionFramework +{ +public: + GasMeterTestFramework() { } + void compile(string const& _sourceCode) + { + 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})), + {&sourceUnit} + ); + } + +protected: + dev::solidity::CompilerStack m_compiler; + map m_gasCosts; +}; + +BOOST_FIXTURE_TEST_SUITE(GasMeterTests, GasMeterTestFramework) + +BOOST_AUTO_TEST_CASE(non_overlapping_filtered_costs) +{ + char const* sourceCode = R"( + contract test { + bytes x; + function f(uint a) returns (uint b) { + x.length = a; + for (; a < 200; ++a) { + x[a] = 9; + b = a * a; + } + return f(a - 1); + } + } + )"; + compile(sourceCode); + for (auto first = m_gasCosts.cbegin(); first != m_gasCosts.cend(); ++first) + { + auto second = first; + for (++second; second != m_gasCosts.cend(); ++second) + if (first->first->getLocation().intersects(second->first->getLocation())) + { + BOOST_CHECK_MESSAGE(false, "Source locations should not overlap!"); + SourceReferenceFormatter::printSourceLocation(cout, first->first->getLocation(), m_compiler.getScanner()); + SourceReferenceFormatter::printSourceLocation(cout, second->first->getLocation(), m_compiler.getScanner()); + } + } +} + +BOOST_AUTO_TEST_SUITE_END() + +} +} +} From d4cf0a54380e980dd850fca7ec45476fc652d353 Mon Sep 17 00:00:00 2001 From: CJentzsch Date: Thu, 7 May 2015 11:01:56 +0200 Subject: [PATCH 15/15] gasPrice 0 test