47 TestBlock genesis = TestBlockChain::defaultGenesisBlock();
54 std::stringstream buffer;
56 BOOST_REQUIRE(buffer.str().size() == 139);
57 buffer.str(std::string());
61 BOOST_ERROR(
"Failed test with Exception: " << diagnostic_information(_e));
63 catch (std::exception
const& _e)
65 BOOST_ERROR(
"Failed test with Exception: " << _e.what());
69 BOOST_ERROR(
"Exception thrown when trying to mine or import a block!");
75 TestBlock genesis = TestBlockChain::defaultGenesisBlock();
79 auto is_critical = []( std::exception
const& _e) {
return string(_e.what()).find(
"DatabaseAlreadyOpen") != string::npos; };
80 BOOST_CHECK_EXCEPTION(
BlockChain bc2(p, tempDirBlockchain.
path(), WithExisting::Verify), DatabaseAlreadyOpen, is_critical);
131 BOOST_ERROR(
"Failed test with Exception: " << diagnostic_information(_e));
133 catch (std::exception
const& _e)
135 BOOST_ERROR(
"Failed test with Exception: " << _e.what());
139 BOOST_ERROR(
"Exception thrown when trying to mine or import a block!");
158 uncleBlock2.
mine(bc);
168 BOOST_ERROR(
"Failed test with Exception: " << diagnostic_information(_e));
170 catch (std::exception
const& _e)
172 BOOST_ERROR(
"Failed test with Exception: " << _e.what());
176 BOOST_ERROR(
"Exception thrown when trying to mine or import a block!");
314 uncleBlockQueue.
import(&uncleBlock.
bytes(),
false);
315 this_thread::sleep_for(chrono::seconds(2));
321 pair<ImportResult, ImportRoute> importAttempt;
323 BOOST_REQUIRE(importAttempt.first == ImportResult::FutureTimeKnown);
325 auto is_critical = []( std::exception
const& _e) {
cnote << _e.what();
return true; };
326 BOOST_CHECK_EXCEPTION(bcRef.
insert(uncleBlock.
bytes(), uncleBlock.
receipts()), FutureTime, is_critical);
330 BOOST_ERROR(
"Failed test with Exception: " << diagnostic_information(_e));
332 catch (std::exception
const& _e)
334 BOOST_ERROR(
"Failed test with Exception: " << _e.what());
338 BOOST_ERROR(
"Exception thrown when trying to mine or import a block!");
366 pair<ImportResult, ImportRoute> importAttempt;
371 BOOST_REQUIRE(importAttempt.first == ImportResult::Success);
374 BOOST_REQUIRE(importAttempt.first == ImportResult::AlreadyKnown);
379 BOOST_REQUIRE(importAttempt.first == ImportResult::Malformed);
385 BOOST_ERROR(
"Failed test with Exception: " << diagnostic_information(_e));
387 catch (std::exception
const& _e)
389 BOOST_ERROR(
"Failed test with Exception: " << _e.what());
393 BOOST_ERROR(
"Exception thrown when trying to mine or import a block!");
419 auto is_critical = []( std::exception
const& _e) {
return string(_e.what()).find(
"InvalidBlockFormat") != string::npos; };
420 BOOST_CHECK_EXCEPTION(bcRef.
insert(bl.
blockData(), receiptRef), InvalidBlockFormat, is_critical);
421 auto is_critical2 = []( std::exception
const& _e) {
return string(_e.what()).find(
"InvalidReceiptsStateRoot") != string::npos; };
422 BOOST_CHECK_EXCEPTION(bcRef.
insert(block.
bytes(), receiptRef), InvalidReceiptsStateRoot, is_critical2);
424 BOOST_REQUIRE(bcRef.
number() == 0);
432 BOOST_ERROR(
"Unexpected Exception!");
437 BOOST_ERROR(
"Failed test with Exception: " << diagnostic_information(_e));
439 catch (std::exception
const& _e)
441 BOOST_ERROR(
"Failed test with Exception: " << _e.what());
445 BOOST_ERROR(
"Exception thrown when trying to mine or import a block!");
462 auto is_critical = []( std::exception
const& _e) {
cnote << _e.what();
return true; };
463 BOOST_CHECK_EXCEPTION(bcRef.
insert(block.
bytes(), block.
receipts()), AlreadyHaveBlock, is_critical);
467 BOOST_ERROR(
"Failed test with Exception: " << diagnostic_information(_e));
469 catch (std::exception
const& _e)
471 BOOST_ERROR(
"Failed test with Exception: " << _e.what());
475 BOOST_ERROR(
"Exception thrown when trying to mine or import a block!");
511 #if !defined(DISABLE_BROKEN_UNIT_TESTS_UNTIL_WE_FIX_THEM) 515 std::this_thread::sleep_for(std::chrono::seconds(10));
517 BOOST_CHECK_MESSAGE(bcRef.
number() == 3,
"Rescued Blockchain missing some blocks!");
521 BOOST_ERROR(
"Unexpected Exception!");
523 #endif // !defined(DISABLE_BROKEN_UNIT_TESTS_UNTIL_WE_FIX_THEM) 528 BOOST_ERROR(
"Failed test with Exception: " << diagnostic_information(_e));
530 catch (std::exception
const& _e)
532 BOOST_ERROR(
"Failed test with Exception: " << _e.what());
536 BOOST_ERROR(
"Exception thrown when trying to mine or import a block!");
563 stat = bcRef.
usage(
true);
569 BOOST_REQUIRE(stat.
memTotal() == 9235);
577 BOOST_ERROR(
"Failed test with Exception: " << diagnostic_information(_e));
579 catch (std::exception
const& _e)
581 BOOST_ERROR(
"Failed test with Exception: " << _e.what());
585 BOOST_ERROR(
"Exception thrown when trying to mine or import a block!");
bytes const & blockData() const
Get the complete current block, including valid nonce.
Statistics usage(bool _freshen=false) const
Adapted from code found on http://stackoverflow.com/questions/180947/base64-decode-snippet-in-c Origi...
std::pair< TransactionReceipts, bool > sync(BlockChain const &_bc, TransactionQueue &_tq, GasPricer const &_gp, unsigned _msTimeout=100)
Sync our transactions, killing those from the queue that we have and assimilating those that we don't...
Implements the blockchain database.
BlockChain const & interface() const
const char * what() const noexceptoverride
ImportResult import(bytesConstRef _block, bool _isOurs=false)
Import a block into the queue.
Block genesisBlock(OverlayDB const &_db) const
Get a pre-made genesis State object.
std::hash for asio::adress
BlockHeader const & blockHeader() const
QueueStatus blockStatus(h256 const &_h) const
Get some infomration on the given block's status regarding us.
unsigned memTransactionAddresses
static eth::Network s_sealEngineNetwork
OverlayDB const & db() const
TransactionReceipt const & receipt(unsigned _i) const
Get the transaction receipt for the transaction of the given index.
void updateNonce(TestBlockChain const &_bc)
std::vector< bytes > transactions(h256 const &_blockHash) const
Get all transactions from a block.
Active model of a block within the block chain.
TestBlock const & testGenesis() const
Base class for all exceptions.
unsigned number(h256 const &_hash) const
Get a number for the given hash (or the most recent mined if none given). Thread-safe.
BOOST_AUTO_TEST_CASE(output)
std::vector< byte > bytes
bytesConstRef receipts() const
void garbageCollect(bool _force=false)
Deallocate unused data.
bool addBlock(TestBlock const &_block)
void mine(TestBlockChain const &_bc)
TransactionQueue const & transactionQueue() const
State const & state() const
std::string const & genesisInfo(Network _n)
BlockChain & interfaceUnsafe() const
dev::bytes const & bytes() const
#define BOOST_FIXTURE_TEST_SUITE(a, b)
std::string const & path() const
void setChain(BlockChain const &_bc)
void setOnBad(std::function< void(Exception &)> _t)
Change the function that is called with a bad block.
#define BOOST_AUTO_TEST_SUITE_END()
void addTransaction(TestTransaction const &_tr)
void insert(bytes const &_block, bytesConstRef _receipts, bool _mustBeNew=true)
Import data into disk-backed DB.
std::tuple< ImportRoute, bool, unsigned > sync(BlockQueue &_bq, OverlayDB const &_stateDB, unsigned _max)
Sync the chain with any incoming blocks.
void onBad(Exception &_ex)
void rescue(OverlayDB const &_db)
Rescue the database.
temporary directory implementation It creates temporary directory in the given path.
void setBlockHeader(BlockHeader const &_header)
unsigned memTotal() const
Helper functions to work with json::spirit and test files.
AccountMap const & accountMap() const
std::pair< ImportResult, ImportRoute > attemptImport(bytes const &_block, OverlayDB const &_stateDB, bool _mutBeNew=true) noexcept
Attempt to import the given block directly into the BlockChain and sync with the state DB...