Skip to content
Closed
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
124 changes: 62 additions & 62 deletions src/test/test_dash.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -50,83 +50,83 @@ extern void noui_connect();

BasicTestingSetup::BasicTestingSetup(const std::string& chainName)
{
SHA256AutoDetect();
RandomInit();
ECC_Start();
BLSInit();
SetupEnvironment();
SetupNetworking();
InitSignatureCache();
InitScriptExecutionCache();
CPrivateSend::InitStandardDenominations();
fPrintToDebugLog = false; // don't want to write to debug.log file
fCheckBlockIndex = true;
SelectParams(chainName);
evoDb = new CEvoDB(1 << 20, true, true);
deterministicMNManager = new CDeterministicMNManager(*evoDb);
noui_connect();
SHA256AutoDetect();
RandomInit();
ECC_Start();
BLSInit();
SetupEnvironment();
SetupNetworking();
InitSignatureCache();
InitScriptExecutionCache();
CPrivateSend::InitStandardDenominations();
fPrintToDebugLog = false; // don't want to write to debug.log file
fCheckBlockIndex = true;
SelectParams(chainName);
evoDb = new CEvoDB(1 << 20, true, true);
deterministicMNManager = new CDeterministicMNManager(*evoDb);
noui_connect();
}

BasicTestingSetup::~BasicTestingSetup()
{
delete deterministicMNManager;
delete evoDb;
delete deterministicMNManager;
delete evoDb;

ECC_Stop();
ECC_Stop();
}

TestingSetup::TestingSetup(const std::string& chainName) : BasicTestingSetup(chainName)
{
const CChainParams& chainparams = Params();
// Ideally we'd move all the RPC tests to the functional testing framework
// instead of unit tests, but for now we need these here.
RegisterAllCoreRPCCommands(tableRPC);
ClearDatadirCache();
pathTemp = fs::temp_directory_path() / strprintf("test_dash_%lu_%i", (unsigned long)GetTime(), (int)(InsecureRandRange(100000)));
fs::create_directories(pathTemp);
gArgs.ForceSetArg("-datadir", pathTemp.string());

// Note that because we don't bother running a scheduler thread here,
// callbacks via CValidationInterface are unreliable, but that's OK,
// our unit tests aren't testing multiple parts of the code at once.
GetMainSignals().RegisterBackgroundSignalScheduler(scheduler);
mempool.setSanityCheck(1.0);
g_connman = std::unique_ptr<CConnman>(new CConnman(0x1337, 0x1337)); // Deterministic randomness for tests.
connman = g_connman.get();
pblocktree = new CBlockTreeDB(1 << 20, true);
pcoinsdbview = new CCoinsViewDB(1 << 23, true);
llmq::InitLLMQSystem(*evoDb, nullptr, true);
pcoinsTip = new CCoinsViewCache(pcoinsdbview);
if (!LoadGenesisBlock(chainparams)) {
throw std::runtime_error("LoadGenesisBlock failed.");
}
{
CValidationState state;
if (!ActivateBestChain(state, chainparams)) {
throw std::runtime_error("ActivateBestChain failed.");
}
// Ideally we'd move all the RPC tests to the functional testing framework
// instead of unit tests, but for now we need these here.
RegisterAllCoreRPCCommands(tableRPC);
ClearDatadirCache();
pathTemp = fs::temp_directory_path() / strprintf("test_dash_%lu_%i", (unsigned long) GetTime(), (int) (InsecureRandRange(100000)));
fs::create_directories(pathTemp);
gArgs.ForceSetArg("-datadir", pathTemp.string());

// Note that because we don't bother running a scheduler thread here,
// callbacks via CValidationInterface are unreliable, but that's OK,
// our unit tests aren't testing multiple parts of the code at once.
GetMainSignals().RegisterBackgroundSignalScheduler(scheduler);
mempool.setSanityCheck(1.0);
g_connman = std::unique_ptr<CConnman>(new CConnman(0x1337, 0x1337)); // Deterministic randomness for tests.
connman = g_connman.get();
pblocktree = new CBlockTreeDB(1 << 20, true);
pcoinsdbview = new CCoinsViewDB(1 << 23, true);
llmq::InitLLMQSystem(*evoDb, nullptr, true);
pcoinsTip = new CCoinsViewCache(pcoinsdbview);
if (!LoadGenesisBlock(chainparams)) {
throw std::runtime_error("LoadGenesisBlock failed.");
}
{
CValidationState state;
if (!ActivateBestChain(state, chainparams)) {
throw std::runtime_error("ActivateBestChain failed.");
}
nScriptCheckThreads = 3;
for (int i=0; i < nScriptCheckThreads-1; i++)
threadGroup.create_thread(&ThreadScriptCheck);
peerLogic.reset(new PeerLogicValidation(connman, scheduler));
}
nScriptCheckThreads = 3;
for (int i = 0; i < nScriptCheckThreads - 1; i++)
threadGroup.create_thread(&ThreadScriptCheck);
peerLogic.reset(new PeerLogicValidation(connman, scheduler));
}

TestingSetup::~TestingSetup()
{
llmq::InterruptLLMQSystem();
threadGroup.interrupt_all();
threadGroup.join_all();
GetMainSignals().FlushBackgroundCallbacks();
GetMainSignals().UnregisterBackgroundSignalScheduler();
g_connman.reset();
peerLogic.reset();
UnloadBlockIndex();
delete pcoinsTip;
llmq::DestroyLLMQSystem();
delete pcoinsdbview;
delete pblocktree;
fs::remove_all(pathTemp);
llmq::InterruptLLMQSystem();
threadGroup.interrupt_all();
threadGroup.join_all();
GetMainSignals().FlushBackgroundCallbacks();
GetMainSignals().UnregisterBackgroundSignalScheduler();
g_connman.reset();
peerLogic.reset();
UnloadBlockIndex();
delete pcoinsTip;
llmq::DestroyLLMQSystem();
delete pcoinsdbview;
delete pblocktree;
fs::remove_all(pathTemp);
}

TestChainSetup::TestChainSetup(int blockCount) : TestingSetup(CBaseChainParams::REGTEST)
Expand Down