From cced4e7336d93a2dc88e4a61c49941887766bd72 Mon Sep 17 00:00:00 2001 From: James O'Beirne Date: Thu, 28 Apr 2022 10:57:25 -0400 Subject: [PATCH] test: move-only-ish: factor out LoadVerifyActivateChainstate() in TestingSetup(). This is used in the following commit to test reinitializing chainstates after snapshot validation and cleanup. Best reviewed with `git diff --color-moved=dimmed-zebra`. --- src/test/util/setup_common.cpp | 29 +++++++++++++++++------------ src/test/util/setup_common.h | 2 ++ 2 files changed, 19 insertions(+), 12 deletions(-) diff --git a/src/test/util/setup_common.cpp b/src/test/util/setup_common.cpp index 852c04e2d9..9ac6c468e2 100644 --- a/src/test/util/setup_common.cpp +++ b/src/test/util/setup_common.cpp @@ -220,19 +220,8 @@ ChainTestingSetup::~ChainTestingSetup() m_node.chainman.reset(); } -TestingSetup::TestingSetup( - const std::string& chainName, - const std::vector& extra_args, - const bool coins_db_in_memory, - const bool block_tree_db_in_memory) - : ChainTestingSetup(chainName, extra_args), - m_coins_db_in_memory(coins_db_in_memory), - m_block_tree_db_in_memory(block_tree_db_in_memory) +void TestingSetup::LoadVerifyActivateChainstate() { - // 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); - node::ChainstateLoadOptions options; options.mempool = Assert(m_node.mempool.get()); options.block_tree_db_in_memory = m_block_tree_db_in_memory; @@ -252,6 +241,22 @@ TestingSetup::TestingSetup( if (!m_node.chainman->ActiveChainstate().ActivateBestChain(state)) { throw std::runtime_error(strprintf("ActivateBestChain failed. (%s)", state.ToString())); } +} + +TestingSetup::TestingSetup( + const std::string& chainName, + const std::vector& extra_args, + const bool coins_db_in_memory, + const bool block_tree_db_in_memory) + : ChainTestingSetup(chainName, extra_args), + m_coins_db_in_memory(coins_db_in_memory), + m_block_tree_db_in_memory(block_tree_db_in_memory) +{ + // 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); + + LoadVerifyActivateChainstate(); m_node.netgroupman = std::make_unique(/*asmap=*/std::vector()); m_node.addrman = std::make_unique(*m_node.netgroupman, diff --git a/src/test/util/setup_common.h b/src/test/util/setup_common.h index 9fe2692c26..3a7d1b54b3 100644 --- a/src/test/util/setup_common.h +++ b/src/test/util/setup_common.h @@ -110,6 +110,8 @@ struct TestingSetup : public ChainTestingSetup { bool m_coins_db_in_memory{true}; bool m_block_tree_db_in_memory{true}; + void LoadVerifyActivateChainstate(); + explicit TestingSetup( const std::string& chainName = CBaseChainParams::MAIN, const std::vector& extra_args = {},