Browse Source

BlockTests: restore corelibs and mining

cl-refactor
Dimitry 10 years ago
parent
commit
795521291a
  1. 2
      libethereum/Block.cpp
  2. 5
      libethereum/Block.h
  3. 2
      test/TestHelper.cpp
  4. 12
      test/libethereum/blockchain.cpp

2
libethereum/Block.cpp

@ -709,7 +709,7 @@ bool Block::sealBlock(bytesConstRef _header)
ret.appendRaw(m_currentTxs);
ret.appendRaw(m_currentUncles);
ret.swapOut(m_currentBytes);
m_currentBlock = Ethash::BlockHeader(_header, CheckNothing, h256(), HeaderData);
m_currentBlock = BlockInfo(_header, CheckNothing, h256(), HeaderData);
cnote << "Mined " << m_currentBlock.hash() << "(parent: " << m_currentBlock.parentHash() << ")";
// TODO: move into Sealer
StructuredLogger::minedNewBlock(

5
libethereum/Block.h

@ -29,7 +29,6 @@
#include <libdevcrypto/OverlayDB.h>
#include <libethcore/Exceptions.h>
#include <libethcore/BlockInfo.h>
#include <libethcore/Ethash.h>
#include <libethcore/Miner.h>
#include <libevm/ExtVMFace.h>
#include "Account.h"
@ -253,7 +252,7 @@ public:
bytes const& blockData() const { return m_currentBytes; }
/// Get the header information on the present block.
Ethash::BlockHeader const& info() const { return m_currentBlock; }
BlockInfo const& info() const { return m_currentBlock; }
private:
@ -289,7 +288,7 @@ private:
State m_precommit; ///< State at the point immediately prior to rewards.
BlockInfo m_previousBlock; ///< The previous block's information.
Ethash::BlockHeader m_currentBlock; ///< The current block's information.
BlockInfo m_currentBlock; ///< The current block's information.
bytes m_currentBytes; ///< The current block.
bool m_committedToMine = false; ///< Have we committed to mine on the present m_currentBlock?

2
test/TestHelper.cpp

@ -269,7 +269,7 @@ int ImportTest::compareStates(State const& _stateExpect, State const& _statePost
for (auto const& a: _stateExpect.addresses())
{
CHECK(_statePost.addressInUse(a.first), "Filling Test: " << a.first << " missing expected address!");
CHECK(_statePost.addressInUse(a.first), "Check State: " << a.first << " missing expected address!");
if (_statePost.addressInUse(a.first))
{
AccountMask addressOptions(true);

12
test/libethereum/blockchain.cpp

@ -73,7 +73,6 @@ void doBlockchainTests(json_spirit::mValue& _v, bool _fillin)
BlockHeader biGenesisBlock = constructBlock(o["genesisBlockHeader"].get_obj(), h256{});
State trueState(OverlayDB(State::openDB(tdStateDB.path(), h256{}, WithExisting::Kill)), BaseState::Empty);
Block trueBlock; //lastBlock of trueBlockchain
ImportTest::importState(o["pre"].get_obj(), trueState);
o["pre"] = fillJsonWithState(trueState); //convert all fields to hex
trueState.commit();
@ -218,7 +217,7 @@ void doBlockchainTests(json_spirit::mValue& _v, bool _fillin)
txList.push_back(txi);
blObj["transactions"] = writeTransactionsToJson(txList);
BlockHeader current_BlockHeader = block.info();
BlockHeader current_BlockHeader(block.blockData());
RLPStream uncleStream;
uncleStream.appendList(vBiUncles.size());
@ -263,7 +262,7 @@ void doBlockchainTests(json_spirit::mValue& _v, bool _fillin)
blObj["rlp"] = toHex(blockRLP.out(), 2, HexPrefix::Add);
if (sha3(RLP(block.blockData())[0].data()) != sha3(RLP(blockRLP.out())[0].data()))
{
{
cnote << "block header mismatch block.blockData() vs updated block.info()\n";
cnote << toHex(RLP(block.blockData())[0].data()) << "vs" << toHex(RLP(blockRLP.out())[0].data());
}
@ -284,7 +283,9 @@ void doBlockchainTests(json_spirit::mValue& _v, bool _fillin)
//attempt to import new block to the true blockchain
trueBc.sync(uncleBlockQueue, trueState.db(), 4);
trueBc.attemptImport(blockRLP.out(), trueState.db());
trueState = block.state();
if (block.blockData() == trueBc.block())
trueState = block.state();
blockSet newBlock;
newBlock.first = blockRLP.out();
@ -316,7 +317,8 @@ void doBlockchainTests(json_spirit::mValue& _v, bool _fillin)
AccountMaskMap expectStateMap;
State stateExpect(OverlayDB(), BaseState::Empty);
ImportTest::importState(o["expect"].get_obj(), stateExpect, expectStateMap);
ImportTest::compareStates(stateExpect, trueBlock.state(), expectStateMap, Options::get().checkState ? WhenError::Throw : WhenError::DontThrow);
if (ImportTest::compareStates(stateExpect, trueState, expectStateMap, Options::get().checkState ? WhenError::Throw : WhenError::DontThrow))
cerr << testname << endl;
o.erase(o.find("expect"));
}

Loading…
Cancel
Save