Browse Source

started tests refactoring

cl-refactor
arkpar 9 years ago
committed by Gav Wood
parent
commit
3737590f22
  1. 3
      libethcore/Common.h
  2. 2
      libethereum/BlockChain.cpp
  3. 7
      libethereum/BlockChain.h
  4. 2
      libethereum/BlockQueue.cpp
  5. 3
      libethereum/Client.cpp
  6. 2
      mix/MixClient.cpp
  7. 2
      test/TestHelper.cpp
  8. 4
      test/libethcore/dagger.cpp
  9. 14
      test/libethereum/ClientBase.cpp
  10. 6
      test/libethereum/genesis.cpp
  11. 5
      test/libethereum/stateOriginal.cpp

3
libethcore/Common.h

@ -130,9 +130,10 @@ struct ImportRequirements
TransactionBasic = 8, ///< Check the basic structure of the transactions. TransactionBasic = 8, ///< Check the basic structure of the transactions.
UncleSeals = 16, ///< Check the basic structure of the uncles. UncleSeals = 16, ///< Check the basic structure of the uncles.
TransactionSignatures = 32, ///< Check the basic structure of the transactions. TransactionSignatures = 32, ///< Check the basic structure of the transactions.
Parent = 64, ///< Check parent block header
CheckUncles = UncleBasic | UncleSeals, ///< Check uncle seals CheckUncles = UncleBasic | UncleSeals, ///< Check uncle seals
CheckTransactions = TransactionBasic | TransactionSignatures, ///< Check transaction signatures CheckTransactions = TransactionBasic | TransactionSignatures, ///< Check transaction signatures
Default = ValidSeal | DontHave | CheckUncles | CheckTransactions, Everything = ValidSeal | DontHave | CheckUncles | CheckTransactions | Parent,
None = 0 None = 0
}; };
}; };

2
libethereum/BlockChain.cpp

@ -355,7 +355,7 @@ tuple<ImportRoute, bool, unsigned> BlockChain::sync(BlockQueue& _bq, OverlayDB c
// Nonce & uncle nonces already verified in verification thread at this point. // Nonce & uncle nonces already verified in verification thread at this point.
ImportRoute r; ImportRoute r;
DEV_TIMED_ABOVE("Block import " + toString(block.verified.info.number()), 500) 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; fresh += r.liveBlocks;
dead += r.deadBlocks; dead += r.deadBlocks;
goodTransactions += r.goodTranactions; goodTransactions += r.goodTranactions;

7
libethereum/BlockChain.h

@ -118,12 +118,12 @@ public:
/// Attempt to import the given block directly into the CanonBlockChain and sync with the state DB. /// 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. /// @returns the block hashes of any blocks that came into/went out of the canonical block chain.
std::pair<ImportResult, ImportRoute> attemptImport(bytes const& _block, OverlayDB const& _stateDB, ImportRequirements::value _ir = ImportRequirements::Default) noexcept; std::pair<ImportResult, ImportRoute> attemptImport(bytes const& _block, OverlayDB const& _stateDB, ImportRequirements::value _ir = ImportRequirements::Everything) noexcept;
/// Import block into disk-backed DB /// Import block into disk-backed DB
/// @returns the block hashes of any blocks that came into/went out of the canonical block chain. /// @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(bytes const& _block, OverlayDB const& _stateDB, ImportRequirements::value _ir = ImportRequirements::Everything);
ImportRoute import(VerifiedBlockRef const& _block, OverlayDB const& _db, ImportRequirements::value _ir = ImportRequirements::Default); 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). /// Returns true if the given block is known (though not necessarily a part of the canon chain).
bool isKnown(h256 const& _hash) const; bool isKnown(h256 const& _hash) const;
@ -391,6 +391,7 @@ public:
{ {
BlockHeader h(_block, (_ir & ImportRequirements::ValidSeal) ? Strictness::CheckEverything : Strictness::QuickNonce); BlockHeader h(_block, (_ir & ImportRequirements::ValidSeal) ? Strictness::CheckEverything : Strictness::QuickNonce);
h.verifyInternals(_block); h.verifyInternals(_block);
if ((_ir & ImportRequirements::Parent) != 0)
h.verifyParent(header(h.parentHash())); h.verifyParent(header(h.parentHash()));
res.info = static_cast<BlockInfo&>(h); res.info = static_cast<BlockInfo&>(h);
} }

2
libethereum/BlockQueue.cpp

@ -110,7 +110,7 @@ void BlockQueue::verifierBody()
swap(work.block, res.blockData); swap(work.block, res.blockData);
try 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 (...) catch (...)
{ {

3
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 // TODO: consider returning the upgrade mechanism here. will delaying the opening of the blockchain database
// until after the construction. // until after the construction.
m_stateDB = State::openDB(_dbPath, bc().genesisHash(), _forceAction); 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. // 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_preMine = bc().genesisState(m_stateDB);
m_postMine = m_preMine;
m_bq.setChain(bc()); m_bq.setChain(bc());

2
mix/MixClient.cpp

@ -279,7 +279,7 @@ void MixClient::mine()
RLPStream header; RLPStream header;
h.streamRLP(header); h.streamRLP(header);
m_state.sealBlock(header.out()); 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_state.sync(bc());
m_startState = m_state; m_startState = m_state;
} }

2
test/TestHelper.cpp

@ -63,7 +63,7 @@ void connectClients(Client& c1, Client& c2)
void mine(State& s, BlockChain const& _bc) void mine(State& s, BlockChain const& _bc)
{ {
s.commitToMine(_bc); s.commitToMine(_bc);
GenericFarm<ProofOfWork> f; GenericFarm<Ethash> f;
bool completed = false; bool completed = false;
f.onSolutionFound([&](ProofOfWork::Solution sol) f.onSolutionFound([&](ProofOfWork::Solution sol)
{ {

4
test/libethcore/dagger.cpp

@ -54,10 +54,10 @@ BOOST_AUTO_TEST_CASE(basic_test)
cnote << i.first; cnote << i.first;
js::mObject& o = i.second.get_obj(); js::mObject& o = i.second.get_obj();
vector<pair<string, string>> ss; vector<pair<string, string>> 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()); h256 headerHash(o["header_hash"].get_str());
Nonce nonce(o["nonce"].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); BOOST_REQUIRE_EQUAL(nonce, header.nonce);
unsigned cacheSize(o["cache_size"].get_int()); unsigned cacheSize(o["cache_size"].get_int());

14
test/libethereum/ClientBase.cpp

@ -119,21 +119,21 @@ BOOST_AUTO_TEST_CASE(blocks)
h256 expectedBlockInfoUncldeHash = h256(fromHex(_b["uncleHash"].asString())); h256 expectedBlockInfoUncldeHash = h256(fromHex(_b["uncleHash"].asString()));
ETH_CHECK_EQUAL(expectedBlockInfoBloom, _blockInfo.logBloom()); ETH_CHECK_EQUAL(expectedBlockInfoBloom, _blockInfo.logBloom());
ETH_CHECK_EQUAL(expectedBlockInfoCoinbase, _blockInfo.coinbaseAddress()); ETH_CHECK_EQUAL(expectedBlockInfoCoinbase, _blockInfo.coinbaseAddress());
ETH_CHECK_EQUAL(expectedBlockInfoDifficulty, _blockInfo.difficulty); ETH_CHECK_EQUAL(expectedBlockInfoDifficulty, _blockInfo.difficulty());
ETH_CHECK_EQUAL_COLLECTIONS( ETH_CHECK_EQUAL_COLLECTIONS(
expectedBlockInfoExtraData.begin(), expectedBlockInfoExtraData.begin(),
expectedBlockInfoExtraData.end(), expectedBlockInfoExtraData.end(),
_blockInfo.extraData().begin(), _blockInfo.extraData().begin(),
_blockInfo.extraData().end() _blockInfo.extraData().end()
); );
ETH_CHECK_EQUAL(expectedBlockInfoGasLimit, _blockInfo.gasLimit); ETH_CHECK_EQUAL(expectedBlockInfoGasLimit, _blockInfo.gasLimit());
ETH_CHECK_EQUAL(expectedBlockInfoGasUsed, _blockInfo.gasUsed); ETH_CHECK_EQUAL(expectedBlockInfoGasUsed, _blockInfo.gasUsed());
ETH_CHECK_EQUAL(expectedBlockInfoHash, _blockInfo.hash()); ETH_CHECK_EQUAL(expectedBlockInfoHash, _blockInfo.hash());
ETH_CHECK_EQUAL(expectedBlockInfoMixHash, _blockInfo.mixHash); ETH_CHECK_EQUAL(expectedBlockInfoMixHash, _blockInfo.mixHash());
ETH_CHECK_EQUAL(expectedBlockInfoNonce, _blockInfo.nonce); ETH_CHECK_EQUAL(expectedBlockInfoNonce, _blockInfo.nonce());
ETH_CHECK_EQUAL(expectedBlockInfoNumber, _blockInfo.number); ETH_CHECK_EQUAL(expectedBlockInfoNumber, _blockInfo.number());
ETH_CHECK_EQUAL(expectedBlockInfoParentHash, _blockInfo.parentHash()); 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(expectedBlockInfoTimestamp, _blockInfo.timestamp());
ETH_CHECK_EQUAL(expectedBlockInfoTransactionsRoot, _blockInfo.transactionsRoot()); ETH_CHECK_EQUAL(expectedBlockInfoTransactionsRoot, _blockInfo.transactionsRoot());
ETH_CHECK_EQUAL(expectedBlockInfoUncldeHash, _blockInfo.sha3Uncles()); ETH_CHECK_EQUAL(expectedBlockInfoUncldeHash, _blockInfo.sha3Uncles());

6
test/libethereum/genesis.cpp

@ -60,9 +60,9 @@ BOOST_AUTO_TEST_CASE(genesis_tests)
js::mObject o = v.get_obj(); js::mObject o = v.get_obj();
BOOST_CHECK_EQUAL(CanonBlockChain::genesis().stateRoot(), h256(o["genesis_state_root"].get_str())); BOOST_CHECK_EQUAL(CanonBlockChain<Ethash>::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(toHex(CanonBlockChain<Ethash>::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(Ethash::BlockHeader(CanonBlockChain<Ethash>::createGenesisBlock()).hashWithout(), h256(o["genesis_hash"].get_str()));
} }
BOOST_AUTO_TEST_SUITE_END() BOOST_AUTO_TEST_SUITE_END()

5
test/libethereum/stateOriginal.cpp

@ -25,6 +25,7 @@
#include <libethereum/CanonBlockChain.h> #include <libethereum/CanonBlockChain.h>
#include <libethereum/State.h> #include <libethereum/State.h>
#include <libethcore/Farm.h> #include <libethcore/Farm.h>
#include <libethcore/BasicAuthority.h>
#include <libethereum/Defaults.h> #include <libethereum/Defaults.h>
#include <test/TestHelper.h> #include <test/TestHelper.h>
@ -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())); Defaults::setDBPath(boost::filesystem::temp_directory_path().string() + "/" + toString(chrono::system_clock::now().time_since_epoch().count()));
OverlayDB stateDB = State::openDB(); OverlayDB stateDB = State::openDB(h256());
CanonBlockChain bc; CanonBlockChain<BasicAuthority> bc;
cout << bc; cout << bc;
State s = bc.genesisState(stateDB); State s = bc.genesisState(stateDB);

Loading…
Cancel
Save