test: allow on-disk coins and block tree dbs in tests

Used when testing cleanup of on-disk chainstate data for snapshot
testcases. Also necessary for simulating node restart in .cpp tests.
This commit is contained in:
James O'Beirne
2022-04-13 15:16:26 -04:00
parent 3c361391b8
commit 51fc9241c0
3 changed files with 35 additions and 11 deletions

View File

@@ -220,8 +220,14 @@ ChainTestingSetup::~ChainTestingSetup()
m_node.chainman.reset();
}
TestingSetup::TestingSetup(const std::string& chainName, const std::vector<const char*>& extra_args)
: ChainTestingSetup(chainName, extra_args)
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.
@@ -229,8 +235,8 @@ TestingSetup::TestingSetup(const std::string& chainName, const std::vector<const
node::ChainstateLoadOptions options;
options.mempool = Assert(m_node.mempool.get());
options.block_tree_db_in_memory = true;
options.coins_db_in_memory = true;
options.block_tree_db_in_memory = m_block_tree_db_in_memory;
options.coins_db_in_memory = m_coins_db_in_memory;
options.reindex = node::fReindex;
options.reindex_chainstate = m_args.GetBoolArg("-reindex-chainstate", false);
options.prune = node::fPruneMode;
@@ -263,8 +269,12 @@ TestingSetup::TestingSetup(const std::string& chainName, const std::vector<const
}
}
TestChain100Setup::TestChain100Setup(const std::string& chain_name, const std::vector<const char*>& extra_args)
: TestingSetup{chain_name, extra_args}
TestChain100Setup::TestChain100Setup(
const std::string& chain_name,
const std::vector<const char*>& extra_args,
const bool coins_db_in_memory,
const bool block_tree_db_in_memory)
: TestingSetup{CBaseChainParams::REGTEST, extra_args, coins_db_in_memory, block_tree_db_in_memory}
{
SetMockTime(1598887952);
constexpr std::array<unsigned char, 32> vchKey = {