Skip to content

Commit cced4e7

Browse files
committed
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`.
1 parent 51fc924 commit cced4e7

File tree

2 files changed

+19
-12
lines changed

2 files changed

+19
-12
lines changed

src/test/util/setup_common.cpp

Lines changed: 17 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -220,19 +220,8 @@ ChainTestingSetup::~ChainTestingSetup()
220220
m_node.chainman.reset();
221221
}
222222

223-
TestingSetup::TestingSetup(
224-
const std::string& chainName,
225-
const std::vector<const char*>& extra_args,
226-
const bool coins_db_in_memory,
227-
const bool block_tree_db_in_memory)
228-
: ChainTestingSetup(chainName, extra_args),
229-
m_coins_db_in_memory(coins_db_in_memory),
230-
m_block_tree_db_in_memory(block_tree_db_in_memory)
223+
void TestingSetup::LoadVerifyActivateChainstate()
231224
{
232-
// Ideally we'd move all the RPC tests to the functional testing framework
233-
// instead of unit tests, but for now we need these here.
234-
RegisterAllCoreRPCCommands(tableRPC);
235-
236225
node::ChainstateLoadOptions options;
237226
options.mempool = Assert(m_node.mempool.get());
238227
options.block_tree_db_in_memory = m_block_tree_db_in_memory;
@@ -252,6 +241,22 @@ TestingSetup::TestingSetup(
252241
if (!m_node.chainman->ActiveChainstate().ActivateBestChain(state)) {
253242
throw std::runtime_error(strprintf("ActivateBestChain failed. (%s)", state.ToString()));
254243
}
244+
}
245+
246+
TestingSetup::TestingSetup(
247+
const std::string& chainName,
248+
const std::vector<const char*>& extra_args,
249+
const bool coins_db_in_memory,
250+
const bool block_tree_db_in_memory)
251+
: ChainTestingSetup(chainName, extra_args),
252+
m_coins_db_in_memory(coins_db_in_memory),
253+
m_block_tree_db_in_memory(block_tree_db_in_memory)
254+
{
255+
// Ideally we'd move all the RPC tests to the functional testing framework
256+
// instead of unit tests, but for now we need these here.
257+
RegisterAllCoreRPCCommands(tableRPC);
258+
259+
LoadVerifyActivateChainstate();
255260

256261
m_node.netgroupman = std::make_unique<NetGroupManager>(/*asmap=*/std::vector<bool>());
257262
m_node.addrman = std::make_unique<AddrMan>(*m_node.netgroupman,

src/test/util/setup_common.h

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -110,6 +110,8 @@ struct TestingSetup : public ChainTestingSetup {
110110
bool m_coins_db_in_memory{true};
111111
bool m_block_tree_db_in_memory{true};
112112

113+
void LoadVerifyActivateChainstate();
114+
113115
explicit TestingSetup(
114116
const std::string& chainName = CBaseChainParams::MAIN,
115117
const std::vector<const char*>& extra_args = {},

0 commit comments

Comments
 (0)