Changeset View
Changeset View
Standalone View
Standalone View
src/test/util/setup_common.cpp
Show First 20 Lines • Show All 141 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(*m_node.scheduler); | GetMainSignals().RegisterBackgroundSignalScheduler(*m_node.scheduler); | ||||
pblocktree.reset(new CBlockTreeDB(1 << 20, true)); | pblocktree.reset(new CBlockTreeDB(1 << 20, true)); | ||||
g_chainstate = std::make_unique<CChainState>(); | g_chainman.InitializeChainstate(); | ||||
::ChainstateActive().InitCoinsDB( | ::ChainstateActive().InitCoinsDB( | ||||
/* cache_size_bytes */ 1 << 23, /* in_memory */ true, | /* cache_size_bytes */ 1 << 23, /* in_memory */ true, | ||||
/* should_wipe */ false); | /* should_wipe */ false); | ||||
assert(!::ChainstateActive().CanFlushToDisk()); | assert(!::ChainstateActive().CanFlushToDisk()); | ||||
::ChainstateActive().InitCoinsCache(); | ::ChainstateActive().InitCoinsCache(); | ||||
assert(::ChainstateActive().CanFlushToDisk()); | assert(::ChainstateActive().CanFlushToDisk()); | ||||
if (!LoadGenesisBlock(chainparams)) { | if (!LoadGenesisBlock(chainparams)) { | ||||
throw std::runtime_error("LoadGenesisBlock failed."); | throw std::runtime_error("LoadGenesisBlock failed."); | ||||
Show All 29 Lines | TestingSetup::~TestingSetup() { | ||||
threadGroup.join_all(); | threadGroup.join_all(); | ||||
GetMainSignals().FlushBackgroundCallbacks(); | GetMainSignals().FlushBackgroundCallbacks(); | ||||
GetMainSignals().UnregisterBackgroundSignalScheduler(); | GetMainSignals().UnregisterBackgroundSignalScheduler(); | ||||
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(); | ||||
g_chainstate.reset(); | g_chainman.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 |