Skip to content

Commit

Permalink
refactor: get rid of DashPostChainstateSetup()
Browse files Browse the repository at this point in the history
`validation_chainstatemanager_tests` can work without `CJContext`, we
can safely reincorporate it into `TestingSetup`.
  • Loading branch information
kwvg committed Feb 24, 2025
1 parent 6502e54 commit c9c5275
Show file tree
Hide file tree
Showing 3 changed files with 10 additions and 28 deletions.
30 changes: 10 additions & 20 deletions src/test/util/setup_common.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -118,24 +118,6 @@ void DashChainstateSetupClose(NodeContext& node)
Assert(node.mempool.get()));
}

void DashPostChainstateSetup(NodeContext& node)
{
node.cj_ctx = std::make_unique<CJContext>(*node.chainman, *node.connman, *node.dmnman, *node.mn_metaman, *node.mempool,
/*mn_activeman=*/nullptr, *node.mn_sync, *node.llmq_ctx->isman, node.peerman,
/*relay_txes=*/true);
#ifdef ENABLE_WALLET
node.coinjoin_loader = interfaces::MakeCoinJoinLoader(node);
#endif // ENABLE_WALLET
}

void DashPostChainstateSetupClose(NodeContext& node)
{
#ifdef ENABLE_WALLET
node.coinjoin_loader.reset();
#endif // ENABLE_WALLET
node.cj_ctx.reset();
}

BasicTestingSetup::BasicTestingSetup(const std::string& chainName, const std::vector<const char*>& extra_args)
: m_path_root{fs::temp_directory_path() / "test_common_" PACKAGE_NAME / g_insecure_rand_ctx_temp_path.rand256().ToString()},
m_args{}
Expand Down Expand Up @@ -330,7 +312,12 @@ TestingSetup::TestingSetup(const std::string& chainName, const std::vector<const
m_node.connman->Init(options);
}

DashPostChainstateSetup(m_node);
m_node.cj_ctx = std::make_unique<CJContext>(*m_node.chainman, *m_node.connman, *m_node.dmnman, *m_node.mn_metaman, *m_node.mempool,
/*mn_activeman=*/nullptr, *m_node.mn_sync, *m_node.llmq_ctx->isman, m_node.peerman,
/*relay_txes=*/true);
#ifdef ENABLE_WALLET
m_node.coinjoin_loader = interfaces::MakeCoinJoinLoader(m_node);
#endif // ENABLE_WALLET

BlockValidationState state;
if (!m_node.chainman->ActiveChainstate().ActivateBestChain(state)) {
Expand All @@ -340,7 +327,10 @@ TestingSetup::TestingSetup(const std::string& chainName, const std::vector<const

TestingSetup::~TestingSetup()
{
DashPostChainstateSetupClose(m_node);
#ifdef ENABLE_WALLET
m_node.coinjoin_loader.reset();
#endif // ENABLE_WALLET
m_node.cj_ctx.reset();

// Interrupt() and PrepareShutdown() routines
if (m_node.llmq_ctx) {
Expand Down
4 changes: 0 additions & 4 deletions src/test/util/setup_common.h
Original file line number Diff line number Diff line change
Expand Up @@ -91,10 +91,6 @@ void DashChainstateSetup(ChainstateManager& chainman,
const Consensus::Params& consensus_params);
void DashChainstateSetupClose(NodeContext& node);

/** Initialize Dash-specific components after chainstate initialization */
void DashPostChainstateSetup(NodeContext& node);
void DashPostChainstateSetupClose(NodeContext& node);

/** Basic testing setup.
* This just configures logging, data dir and chain parameters.
*/
Expand Down
4 changes: 0 additions & 4 deletions src/test/validation_chainstatemanager_tests.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -50,7 +50,6 @@ BOOST_AUTO_TEST_CASE(chainstatemanager)
WITH_LOCK(::cs_main, c1.InitCoinsCache(1 << 23));

DashChainstateSetup(manager, m_node, /*fReset=*/false, /*fReindexChainState=*/false, consensus_params);
DashPostChainstateSetup(m_node);

BOOST_CHECK(!manager.IsSnapshotActive());
BOOST_CHECK(WITH_LOCK(::cs_main, return !manager.IsSnapshotValidated()));
Expand All @@ -68,7 +67,6 @@ BOOST_AUTO_TEST_CASE(chainstatemanager)

BOOST_CHECK(!manager.SnapshotBlockhash().has_value());

DashPostChainstateSetupClose(m_node);
if (m_node.llmq_ctx) {
m_node.llmq_ctx->Interrupt();
m_node.llmq_ctx->Stop();
Expand All @@ -85,7 +83,6 @@ BOOST_AUTO_TEST_CASE(chainstatemanager)
chainstates.push_back(&c2);

DashChainstateSetup(manager, m_node, /*fReset=*/false, /*fReindexChainState=*/false, consensus_params);
DashPostChainstateSetup(m_node);

BOOST_CHECK_EQUAL(manager.SnapshotBlockhash().value(), snapshot_blockhash);

Expand Down Expand Up @@ -120,7 +117,6 @@ BOOST_AUTO_TEST_CASE(chainstatemanager)
// Let scheduler events finish running to avoid accessing memory that is going to be unloaded
SyncWithValidationInterfaceQueue();

DashPostChainstateSetupClose(m_node);
if (m_node.llmq_ctx) {
m_node.llmq_ctx->Interrupt();
m_node.llmq_ctx->Stop();
Expand Down

0 comments on commit c9c5275

Please sign in to comment.