From 5d2a36ee0f1ba5ea75257988e3a820923f1f9221 Mon Sep 17 00:00:00 2001 From: arkpar Date: Thu, 16 Jul 2015 18:11:08 +0200 Subject: [PATCH] started tests refactoring --- libethcore/Common.h | 3 ++- libethereum/BlockChain.cpp | 2 +- libethereum/BlockChain.h | 9 +++++---- libethereum/BlockQueue.cpp | 2 +- libethereum/Client.cpp | 3 +-- mix/MixClient.cpp | 2 +- test/TestHelper.cpp | 2 +- test/libethcore/dagger.cpp | 4 ++-- test/libethereum/ClientBase.cpp | 14 +++++++------- test/libethereum/genesis.cpp | 6 +++--- test/libethereum/stateOriginal.cpp | 5 +++-- 11 files changed, 27 insertions(+), 25 deletions(-) diff --git a/libethcore/Common.h b/libethcore/Common.h index 5c0a0cc79..116e1d5ed 100644 --- a/libethcore/Common.h +++ b/libethcore/Common.h @@ -130,9 +130,10 @@ struct ImportRequirements TransactionBasic = 8, ///< Check the basic structure of the transactions. UncleSeals = 16, ///< Check the basic structure of the uncles. TransactionSignatures = 32, ///< Check the basic structure of the transactions. + Parent = 64, ///< Check parent block header CheckUncles = UncleBasic | UncleSeals, ///< Check uncle seals CheckTransactions = TransactionBasic | TransactionSignatures, ///< Check transaction signatures - Default = ValidSeal | DontHave | CheckUncles | CheckTransactions, + Everything = ValidSeal | DontHave | CheckUncles | CheckTransactions | Parent, None = 0 }; }; diff --git a/libethereum/BlockChain.cpp b/libethereum/BlockChain.cpp index 03ab1b46a..8a654fa51 100644 --- a/libethereum/BlockChain.cpp +++ b/libethereum/BlockChain.cpp @@ -355,7 +355,7 @@ tuple BlockChain::sync(BlockQueue& _bq, OverlayDB c // Nonce & uncle nonces already verified in verification thread at this point. ImportRoute r; DEV_TIMED_ABOVE("Block import " + toString(block.verified.info.number()), 500) - r = import(block.verified, _stateDB, ImportRequirements::Default & ~ImportRequirements::ValidSeal & ~ImportRequirements::CheckUncles); + r = import(block.verified, _stateDB, ImportRequirements::Everything & ~ImportRequirements::ValidSeal & ~ImportRequirements::CheckUncles); fresh += r.liveBlocks; dead += r.deadBlocks; goodTransactions += r.goodTranactions; diff --git a/libethereum/BlockChain.h b/libethereum/BlockChain.h index 3ff85c8a6..811da8609 100644 --- a/libethereum/BlockChain.h +++ b/libethereum/BlockChain.h @@ -118,12 +118,12 @@ public: /// Attempt to import the given block directly into the CanonBlockChain and sync with the state DB. /// @returns the block hashes of any blocks that came into/went out of the canonical block chain. - std::pair attemptImport(bytes const& _block, OverlayDB const& _stateDB, ImportRequirements::value _ir = ImportRequirements::Default) noexcept; + std::pair attemptImport(bytes const& _block, OverlayDB const& _stateDB, ImportRequirements::value _ir = ImportRequirements::Everything) noexcept; /// Import block into disk-backed DB /// @returns the block hashes of any blocks that came into/went out of the canonical block chain. - ImportRoute import(bytes const& _block, OverlayDB const& _stateDB, ImportRequirements::value _ir = ImportRequirements::Default); - ImportRoute import(VerifiedBlockRef const& _block, OverlayDB const& _db, ImportRequirements::value _ir = ImportRequirements::Default); + ImportRoute import(bytes const& _block, OverlayDB const& _stateDB, ImportRequirements::value _ir = ImportRequirements::Everything); + ImportRoute import(VerifiedBlockRef const& _block, OverlayDB const& _db, ImportRequirements::value _ir = ImportRequirements::Everything); /// Returns true if the given block is known (though not necessarily a part of the canon chain). bool isKnown(h256 const& _hash) const; @@ -391,7 +391,8 @@ public: { BlockHeader h(_block, (_ir & ImportRequirements::ValidSeal) ? Strictness::CheckEverything : Strictness::QuickNonce); h.verifyInternals(_block); - h.verifyParent(header(h.parentHash())); + if ((_ir & ImportRequirements::Parent) != 0) + h.verifyParent(header(h.parentHash())); res.info = static_cast(h); } catch (Exception& ex) diff --git a/libethereum/BlockQueue.cpp b/libethereum/BlockQueue.cpp index c9ee4c1cf..d0ca34b1c 100644 --- a/libethereum/BlockQueue.cpp +++ b/libethereum/BlockQueue.cpp @@ -110,7 +110,7 @@ void BlockQueue::verifierBody() swap(work.block, res.blockData); try { - res.verified = m_bc->verifyBlock(&res.blockData, m_onBad, CheckEverything); + res.verified = m_bc->verifyBlock(&res.blockData, m_onBad, ImportRequirements::Everything & ~ImportRequirements::Parent); } catch (...) { diff --git a/libethereum/Client.cpp b/libethereum/Client.cpp index 357926d03..d43f240b7 100644 --- a/libethereum/Client.cpp +++ b/libethereum/Client.cpp @@ -84,10 +84,9 @@ void Client::init(p2p::Host* _extNet, std::string const& _dbPath, WithExisting _ // TODO: consider returning the upgrade mechanism here. will delaying the opening of the blockchain database // until after the construction. m_stateDB = State::openDB(_dbPath, bc().genesisHash(), _forceAction); - m_preMine = State(m_stateDB); - m_postMine = State(m_stateDB); // LAZY. TODO: move genesis state construction/commiting to stateDB openning and have this just take the root from the genesis block. m_preMine = bc().genesisState(m_stateDB); + m_postMine = m_preMine; m_bq.setChain(bc()); diff --git a/mix/MixClient.cpp b/mix/MixClient.cpp index eef6ad6ec..67f2a2507 100644 --- a/mix/MixClient.cpp +++ b/mix/MixClient.cpp @@ -279,7 +279,7 @@ void MixClient::mine() RLPStream header; h.streamRLP(header); m_state.sealBlock(header.out()); - bc().import(m_state.blockData(), m_state.db(), ImportRequirements::Default & ~ImportRequirements::ValidSeal); + bc().import(m_state.blockData(), m_state.db(), ImportRequirements::Everything & ~ImportRequirements::ValidSeal); m_state.sync(bc()); m_startState = m_state; } diff --git a/test/TestHelper.cpp b/test/TestHelper.cpp index bae980a7e..30f323369 100644 --- a/test/TestHelper.cpp +++ b/test/TestHelper.cpp @@ -63,7 +63,7 @@ void connectClients(Client& c1, Client& c2) void mine(State& s, BlockChain const& _bc) { s.commitToMine(_bc); - GenericFarm f; + GenericFarm f; bool completed = false; f.onSolutionFound([&](ProofOfWork::Solution sol) { diff --git a/test/libethcore/dagger.cpp b/test/libethcore/dagger.cpp index 061b5ae79..8d4cba933 100644 --- a/test/libethcore/dagger.cpp +++ b/test/libethcore/dagger.cpp @@ -54,10 +54,10 @@ BOOST_AUTO_TEST_CASE(basic_test) cnote << i.first; js::mObject& o = i.second.get_obj(); vector> ss; - BlockInfo header = BlockInfo::fromHeader(fromHex(o["header"].get_str()), CheckNothing); + Ethash::BlockHeader header(fromHex(o["header"].get_str()), CheckNothing); h256 headerHash(o["header_hash"].get_str()); Nonce nonce(o["nonce"].get_str()); - BOOST_REQUIRE_EQUAL(headerHash, header.headerHash(WithoutNonce)); + BOOST_REQUIRE_EQUAL(headerHash, header.hashWithout()); BOOST_REQUIRE_EQUAL(nonce, header.nonce); unsigned cacheSize(o["cache_size"].get_int()); diff --git a/test/libethereum/ClientBase.cpp b/test/libethereum/ClientBase.cpp index 7dbc5c91e..a426ff53f 100644 --- a/test/libethereum/ClientBase.cpp +++ b/test/libethereum/ClientBase.cpp @@ -119,21 +119,21 @@ BOOST_AUTO_TEST_CASE(blocks) h256 expectedBlockInfoUncldeHash = h256(fromHex(_b["uncleHash"].asString())); ETH_CHECK_EQUAL(expectedBlockInfoBloom, _blockInfo.logBloom()); ETH_CHECK_EQUAL(expectedBlockInfoCoinbase, _blockInfo.coinbaseAddress()); - ETH_CHECK_EQUAL(expectedBlockInfoDifficulty, _blockInfo.difficulty); + ETH_CHECK_EQUAL(expectedBlockInfoDifficulty, _blockInfo.difficulty()); ETH_CHECK_EQUAL_COLLECTIONS( expectedBlockInfoExtraData.begin(), expectedBlockInfoExtraData.end(), _blockInfo.extraData().begin(), _blockInfo.extraData().end() ); - ETH_CHECK_EQUAL(expectedBlockInfoGasLimit, _blockInfo.gasLimit); - ETH_CHECK_EQUAL(expectedBlockInfoGasUsed, _blockInfo.gasUsed); + ETH_CHECK_EQUAL(expectedBlockInfoGasLimit, _blockInfo.gasLimit()); + ETH_CHECK_EQUAL(expectedBlockInfoGasUsed, _blockInfo.gasUsed()); ETH_CHECK_EQUAL(expectedBlockInfoHash, _blockInfo.hash()); - ETH_CHECK_EQUAL(expectedBlockInfoMixHash, _blockInfo.mixHash); - ETH_CHECK_EQUAL(expectedBlockInfoNonce, _blockInfo.nonce); - ETH_CHECK_EQUAL(expectedBlockInfoNumber, _blockInfo.number); + ETH_CHECK_EQUAL(expectedBlockInfoMixHash, _blockInfo.mixHash()); + ETH_CHECK_EQUAL(expectedBlockInfoNonce, _blockInfo.nonce()); + ETH_CHECK_EQUAL(expectedBlockInfoNumber, _blockInfo.number()); ETH_CHECK_EQUAL(expectedBlockInfoParentHash, _blockInfo.parentHash()); - ETH_CHECK_EQUAL(expectedBlockInfoReceiptsRoot, _blockInfo..receiptsRoot()); + ETH_CHECK_EQUAL(expectedBlockInfoReceiptsRoot, _blockInfo.receiptsRoot()); ETH_CHECK_EQUAL(expectedBlockInfoTimestamp, _blockInfo.timestamp()); ETH_CHECK_EQUAL(expectedBlockInfoTransactionsRoot, _blockInfo.transactionsRoot()); ETH_CHECK_EQUAL(expectedBlockInfoUncldeHash, _blockInfo.sha3Uncles()); diff --git a/test/libethereum/genesis.cpp b/test/libethereum/genesis.cpp index 2d5a2faa6..39997572f 100644 --- a/test/libethereum/genesis.cpp +++ b/test/libethereum/genesis.cpp @@ -60,9 +60,9 @@ BOOST_AUTO_TEST_CASE(genesis_tests) js::mObject o = v.get_obj(); - BOOST_CHECK_EQUAL(CanonBlockChain::genesis().stateRoot(), h256(o["genesis_state_root"].get_str())); - BOOST_CHECK_EQUAL(toHex(CanonBlockChain::createGenesisBlock()), toHex(fromHex(o["genesis_rlp_hex"].get_str()))); - BOOST_CHECK_EQUAL(BlockInfo::headerHash(CanonBlockChain::createGenesisBlock()), h256(o["genesis_hash"].get_str())); + BOOST_CHECK_EQUAL(CanonBlockChain::genesis().stateRoot(), h256(o["genesis_state_root"].get_str())); + BOOST_CHECK_EQUAL(toHex(CanonBlockChain::createGenesisBlock()), toHex(fromHex(o["genesis_rlp_hex"].get_str()))); + BOOST_CHECK_EQUAL(Ethash::BlockHeader(CanonBlockChain::createGenesisBlock()).hashWithout(), h256(o["genesis_hash"].get_str())); } BOOST_AUTO_TEST_SUITE_END() diff --git a/test/libethereum/stateOriginal.cpp b/test/libethereum/stateOriginal.cpp index e3f8ac29f..163c89e50 100644 --- a/test/libethereum/stateOriginal.cpp +++ b/test/libethereum/stateOriginal.cpp @@ -25,6 +25,7 @@ #include #include #include +#include #include #include @@ -59,8 +60,8 @@ BOOST_AUTO_TEST_CASE(Complex) Defaults::setDBPath(boost::filesystem::temp_directory_path().string() + "/" + toString(chrono::system_clock::now().time_since_epoch().count())); - OverlayDB stateDB = State::openDB(); - CanonBlockChain bc; + OverlayDB stateDB = State::openDB(h256()); + CanonBlockChain bc; cout << bc; State s = bc.genesisState(stateDB);