0
0
Fork 0
mirror of https://github.com/bitcoin/bitcoin.git synced 2025-02-02 09:46:52 -05:00

Merge #17228: test: Add RegTestingSetup to setup_common

fa0a731d00 test: Add RegTestingSetup to setup_common (MarcoFalke)
fa54b3e248 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 fa0a731d00 -- diff looks correct

Tree-SHA512: 02b9765580b355ed8d1be555f8ae11fa6e3d575f5cb177bbdda0319378837e29de5555c126c477dc8a1e8a5be47335afdcff152cf2dea2fbdd1a988ddde3689b
This commit is contained in:
MarcoFalke 2019-11-04 08:16:25 -05:00
commit 5933c6d924
No known key found for this signature in database
GPG key ID: D2EA4850E7528B25
9 changed files with 56 additions and 33 deletions

View file

@ -56,8 +56,10 @@ RAW_TEST_FILES =
GENERATED_TEST_FILES = $(JSON_TEST_FILES:.json=.json.h) $(RAW_TEST_FILES:.raw=.raw.h)
BITCOIN_TEST_SUITE = \
test/lib/transaction_utils.h \
test/lib/blockfilter.cpp \
test/lib/blockfilter.h \
test/lib/transaction_utils.cpp \
test/lib/transaction_utils.h \
test/main.cpp \
test/setup_common.h \
test/setup_common.cpp

View file

@ -112,7 +112,7 @@ void benchmark::BenchRunner::RunAll(Printer& printer, uint64_t num_evals, double
printer.header();
for (const auto& p : benchmarks()) {
TestingSetup test{CBaseChainParams::REGTEST};
RegTestingSetup test{};
{
LOCK(cs_main);
assert(::ChainActive().Height() == 0);

View file

@ -3,8 +3,8 @@
// file COPYING or http://www.opensource.org/licenses/mit-license.php.
#include <blockencodings.h>
#include <consensus/merkle.h>
#include <chainparams.h>
#include <consensus/merkle.h>
#include <pow.h>
#include <streams.h>
@ -14,11 +14,7 @@
std::vector<std::pair<uint256, CTransactionRef>> extra_txn;
struct RegtestingSetup : public TestingSetup {
RegtestingSetup() : TestingSetup(CBaseChainParams::REGTEST) {}
};
BOOST_FIXTURE_TEST_SUITE(blockencodings_tests, RegtestingSetup)
BOOST_FIXTURE_TEST_SUITE(blockencodings_tests, RegTestingSetup)
static CBlock BuildBlockTestCase() {
CBlock block;

View file

@ -8,8 +8,9 @@
#include <index/blockfilterindex.h>
#include <miner.h>
#include <pow.h>
#include <test/setup_common.h>
#include <script/standard.h>
#include <test/lib/blockfilter.h>
#include <test/setup_common.h>
#include <util/time.h>
#include <validation.h>
@ -17,23 +18,6 @@
BOOST_AUTO_TEST_SUITE(blockfilter_index_tests)
static bool ComputeFilter(BlockFilterType filter_type, const CBlockIndex* block_index,
BlockFilter& filter)
{
CBlock block;
if (!ReadBlockFromDisk(block, block_index->GetBlockPos(), Params().GetConsensus())) {
return false;
}
CBlockUndo block_undo;
if (block_index->nHeight > 0 && !UndoReadFromDisk(block_undo, block_index)) {
return false;
}
filter = BlockFilter(filter_type, block, block_undo);
return true;
}
static bool CheckFilterLookups(BlockFilterIndex& filter_index, const CBlockIndex* block_index,
uint256& last_header)
{

View file

@ -0,0 +1,26 @@
// Copyright (c) 2019 The Bitcoin Core developers
// Distributed under the MIT software license, see the accompanying
// file COPYING or http://www.opensource.org/licenses/mit-license.php.
#include <test/lib/blockfilter.h>
#include <chainparams.h>
#include <validation.h>
bool ComputeFilter(BlockFilterType filter_type, const CBlockIndex* block_index, BlockFilter& filter)
{
CBlock block;
if (!ReadBlockFromDisk(block, block_index->GetBlockPos(), Params().GetConsensus())) {
return false;
}
CBlockUndo block_undo;
if (block_index->nHeight > 0 && !UndoReadFromDisk(block_undo, block_index)) {
return false;
}
filter = BlockFilter(filter_type, block, block_undo);
return true;
}

View file

@ -0,0 +1,13 @@
// Copyright (c) 2019 The Bitcoin Core developers
// Distributed under the MIT software license, see the accompanying
// file COPYING or http://www.opensource.org/licenses/mit-license.php.
#ifndef BITCOIN_TEST_LIB_BLOCKFILTER_H
#define BITCOIN_TEST_LIB_BLOCKFILTER_H
#include <blockfilter.h>
class CBlockIndex;
bool ComputeFilter(BlockFilterType filter_type, const CBlockIndex* block_index, BlockFilter& filter);
#endif // BITCOIN_TEST_LIB_BLOCKFILTER_H

View file

@ -124,7 +124,7 @@ TestingSetup::~TestingSetup()
pblocktree.reset();
}
TestChain100Setup::TestChain100Setup() : TestingSetup(CBaseChainParams::REGTEST)
TestChain100Setup::TestChain100Setup()
{
// CreateAndProcessBlock() does not support building SegWit blocks, so don't activate in these tests.
// TODO: fix the code to support SegWit blocks.

View file

@ -76,6 +76,12 @@ struct TestingSetup : public BasicTestingSetup {
~TestingSetup();
};
/** Identical to TestingSetup, but chain set to regtest */
struct RegTestingSetup : public TestingSetup {
RegTestingSetup()
: TestingSetup{CBaseChainParams::REGTEST} {}
};
class CBlock;
struct CMutableTransaction;
class CScript;
@ -84,7 +90,7 @@ class CScript;
// Testing fixture that pre-creates a
// 100-block REGTEST-mode block chain
//
struct TestChain100Setup : public TestingSetup {
struct TestChain100Setup : public RegTestingSetup {
TestChain100Setup();
// Create a new block with just given transactions, coinbase paying to

View file

@ -18,13 +18,9 @@
#include <thread>
struct RegtestingSetup : public TestingSetup {
RegtestingSetup() : TestingSetup(CBaseChainParams::REGTEST) {}
};
static const std::vector<unsigned char> V_OP_TRUE{OP_TRUE};
BOOST_FIXTURE_TEST_SUITE(validation_block_tests, RegtestingSetup)
BOOST_FIXTURE_TEST_SUITE(validation_block_tests, RegTestingSetup)
struct TestSubscriber : public CValidationInterface {
uint256 m_expected_tip;