Skip to content

Commit 5933c6d

Browse files
author
MarcoFalke
committed
Merge #17228: test: Add RegTestingSetup to setup_common
fa0a731 test: Add RegTestingSetup to setup_common (MarcoFalke) fa54b3e test: move-only ComputeFilter to src/test/lib/blockfilter (MarcoFalke) Pull request description: The default chain for `TestingSetup` is the main chain. However, any test that wants to mine blocks on demand needs to switch to regtest. This is done manually and in-line right now. Fix that by creating an explicit `RegTestingSetup` and use it where appropriate. Also, add a move-only commit to move `ComputeFilter` into the newly created unit test library. Both commits are part of #15845, but split up because they are useful on their own. ACKs for top commit: practicalswift: ACK fa0a731 -- diff looks correct Tree-SHA512: 02b9765580b355ed8d1be555f8ae11fa6e3d575f5cb177bbdda0319378837e29de5555c126c477dc8a1e8a5be47335afdcff152cf2dea2fbdd1a988ddde3689b
2 parents 73b26e3 + fa0a731 commit 5933c6d

9 files changed

+56
-33
lines changed

src/Makefile.test.include

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -56,8 +56,10 @@ RAW_TEST_FILES =
5656
GENERATED_TEST_FILES = $(JSON_TEST_FILES:.json=.json.h) $(RAW_TEST_FILES:.raw=.raw.h)
5757

5858
BITCOIN_TEST_SUITE = \
59-
test/lib/transaction_utils.h \
59+
test/lib/blockfilter.cpp \
60+
test/lib/blockfilter.h \
6061
test/lib/transaction_utils.cpp \
62+
test/lib/transaction_utils.h \
6163
test/main.cpp \
6264
test/setup_common.h \
6365
test/setup_common.cpp

src/bench/bench.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -112,7 +112,7 @@ void benchmark::BenchRunner::RunAll(Printer& printer, uint64_t num_evals, double
112112
printer.header();
113113

114114
for (const auto& p : benchmarks()) {
115-
TestingSetup test{CBaseChainParams::REGTEST};
115+
RegTestingSetup test{};
116116
{
117117
LOCK(cs_main);
118118
assert(::ChainActive().Height() == 0);

src/test/blockencodings_tests.cpp

Lines changed: 2 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -3,8 +3,8 @@
33
// file COPYING or http://www.opensource.org/licenses/mit-license.php.
44

55
#include <blockencodings.h>
6-
#include <consensus/merkle.h>
76
#include <chainparams.h>
7+
#include <consensus/merkle.h>
88
#include <pow.h>
99
#include <streams.h>
1010

@@ -14,11 +14,7 @@
1414

1515
std::vector<std::pair<uint256, CTransactionRef>> extra_txn;
1616

17-
struct RegtestingSetup : public TestingSetup {
18-
RegtestingSetup() : TestingSetup(CBaseChainParams::REGTEST) {}
19-
};
20-
21-
BOOST_FIXTURE_TEST_SUITE(blockencodings_tests, RegtestingSetup)
17+
BOOST_FIXTURE_TEST_SUITE(blockencodings_tests, RegTestingSetup)
2218

2319
static CBlock BuildBlockTestCase() {
2420
CBlock block;

src/test/blockfilter_index_tests.cpp

Lines changed: 2 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -8,32 +8,16 @@
88
#include <index/blockfilterindex.h>
99
#include <miner.h>
1010
#include <pow.h>
11-
#include <test/setup_common.h>
1211
#include <script/standard.h>
12+
#include <test/lib/blockfilter.h>
13+
#include <test/setup_common.h>
1314
#include <util/time.h>
1415
#include <validation.h>
1516

1617
#include <boost/test/unit_test.hpp>
1718

1819
BOOST_AUTO_TEST_SUITE(blockfilter_index_tests)
1920

20-
static bool ComputeFilter(BlockFilterType filter_type, const CBlockIndex* block_index,
21-
BlockFilter& filter)
22-
{
23-
CBlock block;
24-
if (!ReadBlockFromDisk(block, block_index->GetBlockPos(), Params().GetConsensus())) {
25-
return false;
26-
}
27-
28-
CBlockUndo block_undo;
29-
if (block_index->nHeight > 0 && !UndoReadFromDisk(block_undo, block_index)) {
30-
return false;
31-
}
32-
33-
filter = BlockFilter(filter_type, block, block_undo);
34-
return true;
35-
}
36-
3721
static bool CheckFilterLookups(BlockFilterIndex& filter_index, const CBlockIndex* block_index,
3822
uint256& last_header)
3923
{

src/test/lib/blockfilter.cpp

Lines changed: 26 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,26 @@
1+
// Copyright (c) 2019 The Bitcoin Core developers
2+
// Distributed under the MIT software license, see the accompanying
3+
// file COPYING or http://www.opensource.org/licenses/mit-license.php.
4+
5+
#include <test/lib/blockfilter.h>
6+
7+
#include <chainparams.h>
8+
#include <validation.h>
9+
10+
11+
bool ComputeFilter(BlockFilterType filter_type, const CBlockIndex* block_index, BlockFilter& filter)
12+
{
13+
CBlock block;
14+
if (!ReadBlockFromDisk(block, block_index->GetBlockPos(), Params().GetConsensus())) {
15+
return false;
16+
}
17+
18+
CBlockUndo block_undo;
19+
if (block_index->nHeight > 0 && !UndoReadFromDisk(block_undo, block_index)) {
20+
return false;
21+
}
22+
23+
filter = BlockFilter(filter_type, block, block_undo);
24+
return true;
25+
}
26+

src/test/lib/blockfilter.h

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,13 @@
1+
// Copyright (c) 2019 The Bitcoin Core developers
2+
// Distributed under the MIT software license, see the accompanying
3+
// file COPYING or http://www.opensource.org/licenses/mit-license.php.
4+
5+
#ifndef BITCOIN_TEST_LIB_BLOCKFILTER_H
6+
#define BITCOIN_TEST_LIB_BLOCKFILTER_H
7+
8+
#include <blockfilter.h>
9+
class CBlockIndex;
10+
11+
bool ComputeFilter(BlockFilterType filter_type, const CBlockIndex* block_index, BlockFilter& filter);
12+
13+
#endif // BITCOIN_TEST_LIB_BLOCKFILTER_H

src/test/setup_common.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -124,7 +124,7 @@ TestingSetup::~TestingSetup()
124124
pblocktree.reset();
125125
}
126126

127-
TestChain100Setup::TestChain100Setup() : TestingSetup(CBaseChainParams::REGTEST)
127+
TestChain100Setup::TestChain100Setup()
128128
{
129129
// CreateAndProcessBlock() does not support building SegWit blocks, so don't activate in these tests.
130130
// TODO: fix the code to support SegWit blocks.

src/test/setup_common.h

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -76,6 +76,12 @@ struct TestingSetup : public BasicTestingSetup {
7676
~TestingSetup();
7777
};
7878

79+
/** Identical to TestingSetup, but chain set to regtest */
80+
struct RegTestingSetup : public TestingSetup {
81+
RegTestingSetup()
82+
: TestingSetup{CBaseChainParams::REGTEST} {}
83+
};
84+
7985
class CBlock;
8086
struct CMutableTransaction;
8187
class CScript;
@@ -84,7 +90,7 @@ class CScript;
8490
// Testing fixture that pre-creates a
8591
// 100-block REGTEST-mode block chain
8692
//
87-
struct TestChain100Setup : public TestingSetup {
93+
struct TestChain100Setup : public RegTestingSetup {
8894
TestChain100Setup();
8995

9096
// Create a new block with just given transactions, coinbase paying to

src/test/validation_block_tests.cpp

Lines changed: 1 addition & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -18,13 +18,9 @@
1818

1919
#include <thread>
2020

21-
struct RegtestingSetup : public TestingSetup {
22-
RegtestingSetup() : TestingSetup(CBaseChainParams::REGTEST) {}
23-
};
24-
2521
static const std::vector<unsigned char> V_OP_TRUE{OP_TRUE};
2622

27-
BOOST_FIXTURE_TEST_SUITE(validation_block_tests, RegtestingSetup)
23+
BOOST_FIXTURE_TEST_SUITE(validation_block_tests, RegTestingSetup)
2824

2925
struct TestSubscriber : public CValidationInterface {
3026
uint256 m_expected_tip;

0 commit comments

Comments
 (0)