aboutsummaryrefslogtreecommitdiff
path: root/src/test
diff options
context:
space:
mode:
Diffstat (limited to 'src/test')
-rw-r--r--src/test/util/setup_common.cpp28
-rw-r--r--src/test/util/setup_common.h2
2 files changed, 20 insertions, 10 deletions
diff --git a/src/test/util/setup_common.cpp b/src/test/util/setup_common.cpp
index f5cc88f4ce..d0be9fe73a 100644
--- a/src/test/util/setup_common.cpp
+++ b/src/test/util/setup_common.cpp
@@ -17,6 +17,8 @@
#include <net_processing.h>
#include <node/miner.h>
#include <noui.h>
+#include <node/blockstorage.h>
+#include <node/chainstate.h>
#include <policy/fees.h>
#include <pow.h>
#include <rpc/blockchain.h>
@@ -24,6 +26,7 @@
#include <rpc/server.h>
#include <scheduler.h>
#include <script/sigcache.h>
+#include <shutdown.h>
#include <streams.h>
#include <txdb.h>
#include <util/strencodings.h>
@@ -143,8 +146,10 @@ ChainTestingSetup::ChainTestingSetup(const std::string& chainName, const std::ve
m_node.fee_estimator = std::make_unique<CBlockPolicyEstimator>();
m_node.mempool = std::make_unique<CTxMemPool>(m_node.fee_estimator.get(), 1);
+ m_cache_sizes = CalculateCacheSizes(m_args);
+
m_node.chainman = std::make_unique<ChainstateManager>();
- m_node.chainman->m_blockman.m_block_tree_db = std::make_unique<CBlockTreeDB>(1 << 20, true);
+ m_node.chainman->m_blockman.m_block_tree_db = std::make_unique<CBlockTreeDB>(m_cache_sizes.block_tree_db, true);
// Start script-checking threads. Set g_parallel_script_checks to true so they are used.
constexpr int script_check_threads = 2;
@@ -177,15 +182,18 @@ TestingSetup::TestingSetup(const std::string& chainName, const std::vector<const
// instead of unit tests, but for now we need these here.
RegisterAllCoreRPCCommands(tableRPC);
- m_node.chainman->InitializeChainstate(m_node.mempool.get());
- m_node.chainman->ActiveChainstate().InitCoinsDB(
- /*cache_size_bytes=*/1 << 23, /*in_memory=*/true, /*should_wipe=*/false);
- assert(!m_node.chainman->ActiveChainstate().CanFlushToDisk());
- m_node.chainman->ActiveChainstate().InitCoinsCache(1 << 23);
- assert(m_node.chainman->ActiveChainstate().CanFlushToDisk());
- if (!m_node.chainman->ActiveChainstate().LoadGenesisBlock()) {
- throw std::runtime_error("LoadGenesisBlock failed.");
- }
+ auto rv = LoadChainstate(fReindex.load(),
+ *Assert(m_node.chainman.get()),
+ Assert(m_node.mempool.get()),
+ fPruneMode,
+ chainparams.GetConsensus(),
+ m_args.GetBoolArg("-reindex-chainstate", false),
+ m_cache_sizes.block_tree_db,
+ m_cache_sizes.coins_db,
+ m_cache_sizes.coins,
+ true,
+ true);
+ assert(!rv.has_value());
BlockValidationState state;
if (!m_node.chainman->ActiveChainstate().ActivateBestChain(state)) {
diff --git a/src/test/util/setup_common.h b/src/test/util/setup_common.h
index 4f2ccb6ebb..df2c8952bc 100644
--- a/src/test/util/setup_common.h
+++ b/src/test/util/setup_common.h
@@ -9,6 +9,7 @@
#include <fs.h>
#include <key.h>
#include <util/system.h>
+#include <node/caches.h>
#include <node/context.h>
#include <pubkey.h>
#include <random.h>
@@ -89,6 +90,7 @@ struct BasicTestingSetup {
* initialization behaviour.
*/
struct ChainTestingSetup : public BasicTestingSetup {
+ CacheSizes m_cache_sizes{};
explicit ChainTestingSetup(const std::string& chainName = CBaseChainParams::MAIN, const std::vector<const char*>& extra_args = {});
~ChainTestingSetup();