Browse Source

Merge pull request #2556 from arkpar/bc-test-fix

Fixed filltests
cl-refactor
Gav Wood 10 years ago
parent
commit
d1b3c9b811
  1. 2
      libethcore/BlockInfo.h
  2. 1
      libethereum/BlockChain.cpp
  3. 8
      test/TestHelper.cpp
  4. 2
      test/libethereum/ClientBase.cpp
  5. 34
      test/libethereum/blockchain.cpp
  6. 4
      test/libethereum/gaspricer.cpp

2
libethcore/BlockInfo.h

@ -146,7 +146,7 @@ public:
/// sha3 of the header only.
h256 const& hashWithout() const;
h256 const& hash() const { if (m_hash) return m_hash; throw NoHashRecorded(); }
h256 const& hash() const { if (m_hash) return m_hash; BOOST_THROW_EXCEPTION(NoHashRecorded()); }
void clear();
void noteDirty() const { m_hashWithout = m_boundary = m_hash = h256(); }

1
libethereum/BlockChain.cpp

@ -186,6 +186,7 @@ unsigned BlockChain::openDatabase(std::string const& _path, WithExisting _we)
bytes status = contents(extrasPath + "/minor");
unsigned lastMinor = c_minorProtocolVersion;
if (!status.empty())
DEV_IGNORE_EXCEPTIONS(lastMinor = (unsigned)RLP(status));
if (c_minorProtocolVersion != lastMinor)
{

8
test/TestHelper.cpp

@ -69,6 +69,7 @@ void mine(State& s, BlockChain const& _bc)
sealer->onSealGenerated([&](bytes const& sealedHeader){ sealed = sealedHeader; });
sealer->generateSeal(s.info());
sealed.waitNot({});
sealer.reset();
s.sealBlock(sealed);
}
@ -79,7 +80,8 @@ void mine(Ethash::BlockHeader& _bi)
sealer->onSealGenerated([&](bytes const& sealedHeader){ sealed = sealedHeader; });
sealer->generateSeal(_bi);
sealed.waitNot({});
_bi = Ethash::BlockHeader(sealed);
sealer.reset();
_bi = Ethash::BlockHeader(sealed, IgnoreSeal, h256{}, HeaderData);
}
}
@ -841,7 +843,7 @@ dev::eth::Ethash::BlockHeader constructHeader(
rlpStream << _parentHash << _sha3Uncles << _coinbaseAddress << _stateRoot << _transactionsRoot << _receiptsRoot << _logBloom
<< _difficulty << _number << _gasLimit << _gasUsed << _timestamp << _extraData << h256{} << Nonce{};
return Ethash::BlockHeader(rlpStream.out());
return Ethash::BlockHeader(rlpStream.out(), IgnoreSeal, h256{}, HeaderData);
}
void updateEthashSeal(dev::eth::Ethash::BlockHeader& _header, h256 const& _mixHash, dev::eth::Nonce const& _nonce)
@ -855,7 +857,7 @@ void updateEthashSeal(dev::eth::Ethash::BlockHeader& _header, h256 const& _mixHa
header << sourceRlp[i];
header << _mixHash << _nonce;
_header = Ethash::BlockHeader(header.out());
_header = Ethash::BlockHeader(header.out(), IgnoreSeal, h256{}, HeaderData);
}
namespace

2
test/libethereum/ClientBase.cpp

@ -140,7 +140,7 @@ BOOST_AUTO_TEST_CASE(blocks)
ETH_CHECK_EQUAL(expectedBlockInfoUncldeHash, _blockInfo.sha3Uncles());
};
Ethash::BlockHeader blockInfo((static_cast<FixedClient&>(_client)).bc().headerData(blockHash));
Ethash::BlockHeader blockInfo((static_cast<FixedClient&>(_client)).bc().headerData(blockHash), IgnoreSeal, h256{}, HeaderData);
compareBlockInfos(blockHeader, blockInfo);
// blockDetails

34
test/libethereum/blockchain.cpp

@ -23,6 +23,7 @@
#include <boost/filesystem.hpp>
#include <libdevcore/FileSystem.h>
#include <libdevcore/TransientDirectory.h>
#include <libethcore/Params.h>
#include <libethereum/CanonBlockChain.h>
#include <libethereum/TransactionQueue.h>
#include <test/TestHelper.h>
@ -127,13 +128,15 @@ void doBlockchainTests(json_spirit::mValue& _v, bool _fillin)
TransientDirectory td_stateDB, td_bc;
FullBlockChain<Ethash> bc(rlpGenesisBlock.out(), StateDefinition(), td_bc.path(), WithExisting::Kill);
State state(OverlayDB(State::openDB(td_stateDB.path(), h256{}, WithExisting::Kill)), BaseState::Empty);
trueState.setAddress(biGenesisBlock.coinbaseAddress());
state.setAddress(biGenesisBlock.coinbaseAddress());
importer.importState(o["pre"].get_obj(), state);
state.commit();
state.sync(bc);
for (size_t i = 1; i < importBlockNumber; i++) //0 block is genesis
{
BlockQueue uncleQueue;
uncleQueue.setChain(bc);
uncleList uncles = blockSets.at(i).second;
for (size_t j = 0; j < uncles.size(); j++)
uncleQueue.import(&uncles.at(j), false);
@ -162,6 +165,7 @@ void doBlockchainTests(json_spirit::mValue& _v, bool _fillin)
blObj["uncleHeaders"] = importUncles(blObj, vBiUncles, vBiBlocks, blockSets);
BlockQueue uncleBlockQueue;
uncleBlockQueue.setChain(bc);
uncleList uncleBlockQueueList;
cnote << "import uncle in blockQueue";
for (size_t i = 0; i < vBiUncles.size(); i++)
@ -207,7 +211,7 @@ void doBlockchainTests(json_spirit::mValue& _v, bool _fillin)
txList.push_back(txi);
blObj["transactions"] = writeTransactionsToJson(txList);
BlockHeader current_BlockHeader = state.info();
BlockHeader current_BlockHeader(state.blockData());
RLPStream uncleStream;
uncleStream.appendList(vBiUncles.size());
@ -666,19 +670,19 @@ void overwriteBlockHeader(BlockHeader& _header, mObject& _blObj)
if (ho.size() != 14)
{
BlockHeader tmp = constructHeader(
ho.count("parentHash") ? h256(ho["parentHash"].get_str()) : h256{},
ho.count("uncleHash") ? h256(ho["uncleHash"].get_str()) : EmptyListSHA3,
ho.count("coinbase") ? Address(ho["coinbase"].get_str()) : Address{},
ho.count("stateRoot") ? h256(ho["stateRoot"].get_str()): h256{},
ho.count("transactionsTrie") ? h256(ho["transactionsTrie"].get_str()) : EmptyTrie,
ho.count("receiptTrie") ? h256(ho["receiptTrie"].get_str()) : EmptyTrie,
ho.count("bloom") ? LogBloom(ho["bloom"].get_str()) : LogBloom{},
ho.count("difficulty") ? toInt(ho["difficulty"]) : u256(0),
ho.count("number") ? toInt(ho["number"]) : u256(0),
ho.count("gasLimit") ? toInt(ho["gasLimit"]) : u256(0),
ho.count("gasUsed") ? toInt(ho["gasUsed"]) : u256(0),
ho.count("timestamp") ? toInt(ho["timestamp"]) : u256(0),
ho.count("extraData") ? importByteArray(ho["extraData"].get_str()) : bytes{});
ho.count("parentHash") ? h256(ho["parentHash"].get_str()) : _header.parentHash(),
ho.count("uncleHash") ? h256(ho["uncleHash"].get_str()) : _header.sha3Uncles(),
ho.count("coinbase") ? Address(ho["coinbase"].get_str()) : _header.coinbaseAddress(),
ho.count("stateRoot") ? h256(ho["stateRoot"].get_str()): _header.stateRoot(),
ho.count("transactionsTrie") ? h256(ho["transactionsTrie"].get_str()) : _header.transactionsRoot(),
ho.count("receiptTrie") ? h256(ho["receiptTrie"].get_str()) : _header.receiptsRoot(),
ho.count("bloom") ? LogBloom(ho["bloom"].get_str()) : _header.logBloom(),
ho.count("difficulty") ? toInt(ho["difficulty"]) : _header.difficulty(),
ho.count("number") ? toInt(ho["number"]) : _header.number(),
ho.count("gasLimit") ? toInt(ho["gasLimit"]) : _header.gasLimit(),
ho.count("gasUsed") ? toInt(ho["gasUsed"]) : _header.gasUsed(),
ho.count("timestamp") ? toInt(ho["timestamp"]) : _header.timestamp(),
ho.count("extraData") ? importByteArray(ho["extraData"].get_str()) : _header.extraData());
// find new valid nonce
if (static_cast<BlockInfo>(tmp) != static_cast<BlockInfo>(_header) && tmp.difficulty())

4
test/libethereum/gaspricer.cpp

@ -21,7 +21,7 @@
#include <libtestutils/BlockChainLoader.h>
#include <libethcore/Ethash.h>
#include <libethereum/BlockChain.h>
#include <libethereum/CanonBlockChain.h>
#include <libethereum/GasPricer.h>
#include <libethereum/BasicGasPricer.h>
#include "../TestHelper.h"
@ -55,7 +55,7 @@ BOOST_AUTO_TEST_CASE(trivialGasPricer)
std::shared_ptr<dev::eth::GasPricer> gp(new TrivialGasPricer);
BOOST_CHECK_EQUAL(gp->ask(State()), 10 * szabo);
BOOST_CHECK_EQUAL(gp->bid(), 10 * szabo);
gp->update(FullBlockChain<Ethash>(bytes(), StateDefinition(), TransientDirectory().path(), WithExisting::Kill));
gp->update(CanonBlockChain<Ethash>(TransientDirectory().path(), WithExisting::Kill));
BOOST_CHECK_EQUAL(gp->ask(State()), 10 * szabo);
BOOST_CHECK_EQUAL(gp->bid(), 10 * szabo);
}

Loading…
Cancel
Save