Changeset View
Changeset View
Standalone View
Standalone View
src/test/util/setup_common.cpp
Show First 20 Lines • Show All 106 Lines • ▼ Show 20 Lines | TestingSetup::TestingSetup(const std::string &chainName) | ||||
m_node.scheduler = std::make_unique<CScheduler>(); | m_node.scheduler = std::make_unique<CScheduler>(); | ||||
// We have to run a scheduler thread to prevent ActivateBestChain | // We have to run a scheduler thread to prevent ActivateBestChain | ||||
// from blocking due to queue overrun. | // from blocking due to queue overrun. | ||||
threadGroup.create_thread([&] { m_node.scheduler->serviceQueue(); }); | threadGroup.create_thread([&] { m_node.scheduler->serviceQueue(); }); | ||||
GetMainSignals().RegisterBackgroundSignalScheduler(*g_rpc_node->scheduler); | GetMainSignals().RegisterBackgroundSignalScheduler(*g_rpc_node->scheduler); | ||||
pblocktree.reset(new CBlockTreeDB(1 << 20, true)); | pblocktree.reset(new CBlockTreeDB(1 << 20, true)); | ||||
pcoinsdbview.reset(new CCoinsViewDB(1 << 23, true)); | g_chainstate = std::make_unique<CChainState>(); | ||||
pcoinsTip.reset(new CCoinsViewCache(pcoinsdbview.get())); | ::ChainstateActive().InitCoinsDB( | ||||
/* cache_size_bytes */ 1 << 23, /* in_memory */ true, | |||||
/* should_wipe */ false); | |||||
assert(!::ChainstateActive().CanFlushToDisk()); | |||||
::ChainstateActive().InitCoinsCache(); | |||||
assert(::ChainstateActive().CanFlushToDisk()); | |||||
if (!LoadGenesisBlock(chainparams)) { | if (!LoadGenesisBlock(chainparams)) { | ||||
throw std::runtime_error("LoadGenesisBlock failed."); | throw std::runtime_error("LoadGenesisBlock failed."); | ||||
} | } | ||||
{ | { | ||||
BlockValidationState state; | BlockValidationState state; | ||||
if (!ActivateBestChain(config, state)) { | if (!ActivateBestChain(config, state)) { | ||||
throw std::runtime_error(strprintf("ActivateBestChain failed. (%s)", | throw std::runtime_error(strprintf("ActivateBestChain failed. (%s)", | ||||
FormatStateMessage(state))); | FormatStateMessage(state))); | ||||
Show All 22 Lines | TestingSetup::~TestingSetup() { | ||||
GetMainSignals().FlushBackgroundCallbacks(); | GetMainSignals().FlushBackgroundCallbacks(); | ||||
GetMainSignals().UnregisterBackgroundSignalScheduler(); | GetMainSignals().UnregisterBackgroundSignalScheduler(); | ||||
g_rpc_node = nullptr; | g_rpc_node = nullptr; | ||||
m_node.connman.reset(); | m_node.connman.reset(); | ||||
m_node.banman.reset(); | m_node.banman.reset(); | ||||
m_node.mempool = nullptr; | m_node.mempool = nullptr; | ||||
m_node.scheduler.reset(); | m_node.scheduler.reset(); | ||||
UnloadBlockIndex(); | UnloadBlockIndex(); | ||||
pcoinsTip.reset(); | g_chainstate.reset(); | ||||
pcoinsdbview.reset(); | |||||
pblocktree.reset(); | pblocktree.reset(); | ||||
} | } | ||||
TestChain100Setup::TestChain100Setup() { | TestChain100Setup::TestChain100Setup() { | ||||
// Generate a 100-block chain: | // Generate a 100-block chain: | ||||
coinbaseKey.MakeNewKey(true); | coinbaseKey.MakeNewKey(true); | ||||
CScript scriptPubKey = CScript() << ToByteVector(coinbaseKey.GetPubKey()) | CScript scriptPubKey = CScript() << ToByteVector(coinbaseKey.GetPubKey()) | ||||
<< OP_CHECKSIG; | << OP_CHECKSIG; | ||||
▲ Show 20 Lines • Show All 169 Lines • Show Last 20 Lines |