@@ -302,10 +302,27 @@ TestingSetup::TestingSetup(const std::string& chainName, const std::vector<const
302302 if (!m_node.chainman ->ActiveChainstate ().ActivateBestChain (state)) {
303303 throw std::runtime_error (strprintf (" ActivateBestChain failed. (%s)" , state.ToString ()));
304304 }
305+
306+ g_txindex = std::make_unique<TxIndex>(1 << 20 , true );
307+ if (!g_txindex->Start (m_node.chainman ->ActiveChainstate ())) {
308+ throw std::runtime_error (" TxIndex::Start() failed." );
309+ }
310+
311+ // Allow tx index to catch up with the block index.
312+ IndexWaitSynced (*g_txindex);
305313}
306314
307315TestingSetup::~TestingSetup ()
308316{
317+ // Allow tx index to catch up with the block index cause otherwise
318+ // we might be destroying it while scheduler still has some work for it
319+ // e.g. via BlockConnected signal
320+ {
321+ IndexWaitSynced (*g_txindex);
322+ g_txindex->Stop ();
323+ SyncWithValidationInterfaceQueue ();
324+ g_txindex.reset ();
325+ }
309326 DashTestSetupClose (m_node);
310327 m_node.connman ->Stop ();
311328 m_node.peerman .reset ();
@@ -349,14 +366,6 @@ TestChainSetup::TestChainSetup(int num_blocks, const std::vector<const char*>& e
349366 hash != checkpoints.mapCheckpoints .end () &&
350367 m_node.chainman ->ActiveChain ().Tip ()->GetBlockHash () == hash->second );
351368 }
352-
353- g_txindex = std::make_unique<TxIndex>(1 << 20 , true );
354- if (!g_txindex->Start (m_node.chainman ->ActiveChainstate ())) {
355- throw std::runtime_error (" TxIndex::Start() failed." );
356- }
357-
358- // Allow tx index to catch up with the block index.
359- IndexWaitSynced (*g_txindex);
360369}
361370
362371void TestChainSetup::mineBlocks (int num_blocks)
@@ -498,17 +507,6 @@ CMutableTransaction TestChainSetup::CreateValidMempoolTransaction(CTransactionRe
498507 return mempool_txn;
499508}
500509
501- TestChainSetup::~TestChainSetup ()
502- {
503- // Allow tx index to catch up with the block index cause otherwise
504- // we might be destroying it while scheduler still has some work for it
505- // e.g. via BlockConnected signal
506- IndexWaitSynced (*g_txindex);
507- g_txindex->Stop ();
508- SyncWithValidationInterfaceQueue ();
509- g_txindex.reset ();
510- }
511-
512510CTxMemPoolEntry TestMemPoolEntryHelper::FromTx (const CMutableTransaction& tx) const
513511{
514512 return FromTx (MakeTransactionRef (tx));
0 commit comments