Changeset View
Changeset View
Standalone View
Standalone View
src/test/test_bitcoin.cpp
Show All 25 Lines | |||||
#include <txmempool.h> | #include <txmempool.h> | ||||
#include <ui_interface.h> | #include <ui_interface.h> | ||||
#include <validation.h> | #include <validation.h> | ||||
#include <memory> | #include <memory> | ||||
FastRandomContext g_insecure_rand_ctx; | FastRandomContext g_insecure_rand_ctx; | ||||
void CConnmanTest::AddNode(CNode &node) { | |||||
LOCK(g_connman->cs_vNodes); | |||||
g_connman->vNodes.push_back(&node); | |||||
} | |||||
void CConnmanTest::ClearNodes() { | |||||
LOCK(g_connman->cs_vNodes); | |||||
g_connman->vNodes.clear(); | |||||
} | |||||
std::ostream &operator<<(std::ostream &os, const uint256 &num) { | std::ostream &operator<<(std::ostream &os, const uint256 &num) { | ||||
os << num.ToString(); | os << num.ToString(); | ||||
return os; | return os; | ||||
} | } | ||||
BasicTestingSetup::BasicTestingSetup(const std::string &chainName) | BasicTestingSetup::BasicTestingSetup(const std::string &chainName) | ||||
: m_path_root(fs::temp_directory_path() / "test_bitcoin" / | : m_path_root(fs::temp_directory_path() / "test_bitcoin" / | ||||
strprintf("%lu_%i", static_cast<unsigned long>(GetTime()), | strprintf("%lu_%i", static_cast<unsigned long>(GetTime()), | ||||
▲ Show 20 Lines • Show All 68 Lines • ▼ Show 20 Lines | if (!LoadGenesisBlock(chainparams)) { | ||||
throw std::runtime_error(strprintf("ActivateBestChain failed. (%s)", | throw std::runtime_error(strprintf("ActivateBestChain failed. (%s)", | ||||
FormatStateMessage(state))); | FormatStateMessage(state))); | ||||
} | } | ||||
} | } | ||||
nScriptCheckThreads = 3; | nScriptCheckThreads = 3; | ||||
for (int i = 0; i < nScriptCheckThreads - 1; i++) { | for (int i = 0; i < nScriptCheckThreads - 1; i++) { | ||||
threadGroup.create_thread(&ThreadScriptCheck); | threadGroup.create_thread(&ThreadScriptCheck); | ||||
} | } | ||||
// Deterministic randomness for tests. | // Deterministic randomness for tests. | ||||
g_connman = std::unique_ptr<CConnman>(new CConnman(config, 0x1337, 0x1337)); | g_connman = std::make_unique<CConnman>(config, 0x1337, 0x1337); | ||||
connman = g_connman.get(); | |||||
peerLogic.reset( | |||||
new PeerLogicValidation(connman, scheduler, /*enable_bip61=*/true)); | |||||
} | } | ||||
TestingSetup::~TestingSetup() { | TestingSetup::~TestingSetup() { | ||||
threadGroup.interrupt_all(); | threadGroup.interrupt_all(); | ||||
threadGroup.join_all(); | threadGroup.join_all(); | ||||
GetMainSignals().FlushBackgroundCallbacks(); | GetMainSignals().FlushBackgroundCallbacks(); | ||||
GetMainSignals().UnregisterBackgroundSignalScheduler(); | GetMainSignals().UnregisterBackgroundSignalScheduler(); | ||||
g_connman.reset(); | g_connman.reset(); | ||||
peerLogic.reset(); | |||||
UnloadBlockIndex(); | UnloadBlockIndex(); | ||||
pcoinsTip.reset(); | pcoinsTip.reset(); | ||||
pcoinsdbview.reset(); | pcoinsdbview.reset(); | ||||
pblocktree.reset(); | pblocktree.reset(); | ||||
} | } | ||||
TestChain100Setup::TestChain100Setup() | TestChain100Setup::TestChain100Setup() | ||||
: TestingSetup(CBaseChainParams::REGTEST) { | : TestingSetup(CBaseChainParams::REGTEST) { | ||||
▲ Show 20 Lines • Show All 72 Lines • Show Last 20 Lines |