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`.
This commit is contained in:
James O'Beirne
2022-04-28 10:57:25 -04:00
parent 51fc9241c0
commit cced4e7336
2 changed files with 19 additions and 12 deletions

View File

@@ -220,19 +220,8 @@ ChainTestingSetup::~ChainTestingSetup()
m_node.chainman.reset();
}
TestingSetup::TestingSetup(
const std::string& chainName,
const std::vector<const char*>& 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<const char*>& 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<NetGroupManager>(/*asmap=*/std::vector<bool>());
m_node.addrman = std::make_unique<AddrMan>(*m_node.netgroupman,

View File

@@ -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<const char*>& extra_args = {},