Skip to content

Commit 2e79fb6

Browse files
dongcarlMacroFake
authored and
MacroFake
committed
validation tests: Use existing {Chainstate,Block}Man
Use {Chain,}TestingSetup's existing {Chainstate,Block}Manager and avoid unnecessarily creating a local one. This also helps reduce the code diff for a later commit where we change {Chainstate,Block}Manager's constructor signature.
1 parent a6fc293 commit 2e79fb6

File tree

2 files changed

+4
-18
lines changed

2 files changed

+4
-18
lines changed

src/test/validation_chainstate_tests.cpp

+2-9
Original file line numberDiff line numberDiff line change
@@ -9,27 +9,20 @@
99
#include <sync.h>
1010
#include <test/util/chainstate.h>
1111
#include <test/util/setup_common.h>
12-
#include <timedata.h>
1312
#include <uint256.h>
1413
#include <validation.h>
1514

1615
#include <vector>
1716

1817
#include <boost/test/unit_test.hpp>
1918

20-
BOOST_FIXTURE_TEST_SUITE(validation_chainstate_tests, TestingSetup)
19+
BOOST_FIXTURE_TEST_SUITE(validation_chainstate_tests, ChainTestingSetup)
2120

2221
//! Test resizing coins-related CChainState caches during runtime.
2322
//!
2423
BOOST_AUTO_TEST_CASE(validation_chainstate_resize_caches)
2524
{
26-
const ChainstateManager::Options chainman_opts{
27-
.chainparams = Params(),
28-
.adjusted_time_callback = GetAdjustedTime,
29-
};
30-
ChainstateManager manager{chainman_opts};
31-
32-
WITH_LOCK(::cs_main, manager.m_blockman.m_block_tree_db = std::make_unique<CBlockTreeDB>(1 << 20, true));
25+
ChainstateManager& manager = *Assert(m_node.chainman);
3326
CTxMemPool& mempool = *Assert(m_node.mempool);
3427

3528
//! Create and add a Coin with DynamicMemoryUsage of 80 bytes to the given view.

src/test/validation_flush_tests.cpp

+2-9
Original file line numberDiff line numberDiff line change
@@ -4,14 +4,11 @@
44
//
55
#include <sync.h>
66
#include <test/util/setup_common.h>
7-
#include <txmempool.h>
87
#include <validation.h>
98

109
#include <boost/test/unit_test.hpp>
1110

12-
using node::BlockManager;
13-
14-
BOOST_FIXTURE_TEST_SUITE(validation_flush_tests, ChainTestingSetup)
11+
BOOST_FIXTURE_TEST_SUITE(validation_flush_tests, TestingSetup)
1512

1613
//! Test utilities for detecting when we need to flush the coins cache based
1714
//! on estimated memory usage.
@@ -20,11 +17,7 @@ BOOST_FIXTURE_TEST_SUITE(validation_flush_tests, ChainTestingSetup)
2017
//!
2118
BOOST_AUTO_TEST_CASE(getcoinscachesizestate)
2219
{
23-
CTxMemPool& mempool = *Assert(m_node.mempool);
24-
BlockManager blockman{};
25-
CChainState chainstate{&mempool, blockman, *Assert(m_node.chainman)};
26-
chainstate.InitCoinsDB(/*cache_size_bytes=*/1 << 10, /*in_memory=*/true, /*should_wipe=*/false);
27-
WITH_LOCK(::cs_main, chainstate.InitCoinsCache(1 << 10));
20+
CChainState& chainstate{m_node.chainman->ActiveChainstate()};
2821

2922
constexpr bool is_64_bit = sizeof(void*) == 8;
3023

0 commit comments

Comments
 (0)