Merge #15788: test: Unify testing setups for fuzz, bench, and unit tests

faf400077d scripted-diff: Bump copyright headers in test, bench (MarcoFalke)
fa821904bf scripted-diff: Rename test_bitcoin to test/setup_common (MarcoFalke)
fa8685d49e test: Use test_bitcoin setup in bench, Add test utils (MarcoFalke)
666696b673 test: Have segwit always active in (Basic)TestingSetup (MarcoFalke)

Pull request description:

  Now that the fuzz tests can use the BasicTestingSetup [1], do the same for bench.

  Also move some duplicate code to a common "test/util" module.

  [1]:  fuzz: Link BasicTestingSetup (shared with unit tests) #15504

ACKs for commit faf400:
  jonatack:
    ACK faf400077d

Tree-SHA512: 8ac5692e72cf50e460958f291643ae6b8bb04d5c1331ed50dce9eb4e9457e5a925144c532c42b360a26707e11eeece74aab27db8c76ab9a429b9dd7167e7cdc4
This commit is contained in:
MarcoFalke 2019-04-15 11:25:03 -04:00
commit 78295e97b8
No known key found for this signature in database
GPG key ID: D2EA4850E7528B25
94 changed files with 317 additions and 298 deletions

View file

@ -20,6 +20,10 @@
</ProjectConfiguration>
</ItemGroup>
<ItemGroup>
<ClCompile Include="..\..\src\test\util.h" />
<ClCompile Include="..\..\src\test\util.cpp" />
<ClCompile Include="..\..\src\test\setup_common.h" />
<ClCompile Include="..\..\src\test\setup_common.cpp" />
<ClCompile Include="..\..\src\bench\base58.cpp" />
<ClCompile Include="..\..\src\bench\bech32.cpp" />
<ClCompile Include="..\..\src\bench\bench.cpp" />

View file

@ -24,7 +24,7 @@
<ClCompile Include="..\..\src\test\*_properties.cpp" />
<ClCompile Include="..\..\src\test\gen\*_gen.cpp" />
<ClCompile Include="..\..\src\wallet\test\*_tests.cpp" />
<ClCompile Include="..\..\src\test\test_bitcoin.cpp" />
<ClCompile Include="..\..\src\test\setup_common.cpp" />
<ClCompile Include="..\..\src\test\main.cpp" />
<ClCompile Include="..\..\src\wallet\test\*_fixture.cpp" />
</ItemGroup>

View file

@ -32,7 +32,11 @@ bench_bench_bitcoin_SOURCES = \
bench/bech32.cpp \
bench/lockedpool.cpp \
bench/poly1305.cpp \
bench/prevector.cpp
bench/prevector.cpp \
test/setup_common.h \
test/setup_common.cpp \
test/util.h \
test/util.cpp
nodist_bench_bench_bitcoin_SOURCES = $(GENERATED_BENCH_FILES)

View file

@ -33,10 +33,10 @@ TEST_QT_H = \
qt/test/wallettests.h
TEST_BITCOIN_CPP = \
test/test_bitcoin.cpp
test/setup_common.cpp
TEST_BITCOIN_H = \
test/test_bitcoin.h
test/setup_common.h
qt_test_test_bitcoin_qt_CPPFLAGS = $(AM_CPPFLAGS) $(BITCOIN_INCLUDES) $(BITCOIN_QT_INCLUDES) \
$(QT_INCLUDES) $(QT_TEST_INCLUDES) $(PROTOBUF_CFLAGS)

View file

@ -52,12 +52,12 @@ GENERATED_TEST_FILES = $(JSON_TEST_FILES:.json=.json.h) $(RAW_TEST_FILES:.raw=.r
BITCOIN_TEST_SUITE = \
test/main.cpp \
test/test_bitcoin.h \
test/test_bitcoin.cpp
test/setup_common.h \
test/setup_common.cpp
FUZZ_SUITE = \
test/test_bitcoin.h \
test/test_bitcoin.cpp \
test/setup_common.h \
test/setup_common.cpp \
test/fuzz/fuzz.cpp \
test/fuzz/fuzz.h

View file

@ -1,15 +1,19 @@
// Copyright (c) 2015-2018 The Bitcoin Core developers
// Copyright (c) 2015-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 <bench/bench.h>
#include <assert.h>
#include <iostream>
#include <iomanip>
#include <chainparams.h>
#include <test/setup_common.h>
#include <validation.h>
#include <algorithm>
#include <regex>
#include <assert.h>
#include <iomanip>
#include <iostream>
#include <numeric>
#include <regex>
void benchmark::ConsolePrinter::header()
{
@ -108,6 +112,13 @@ void benchmark::BenchRunner::RunAll(Printer& printer, uint64_t num_evals, double
printer.header();
for (const auto& p : benchmarks()) {
TestingSetup test{CBaseChainParams::REGTEST};
{
assert(::chainActive.Height() == 0);
const bool witness_enabled{IsWitnessEnabled(::chainActive.Tip(), Params().GetConsensus())};
assert(witness_enabled);
}
if (!std::regex_match(p.first, baseMatch, reFilter)) {
continue;
}

View file

@ -1,4 +1,4 @@
// Copyright (c) 2015-2018 The Bitcoin Core developers
// Copyright (c) 2015-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.
@ -6,14 +6,11 @@
#include <crypto/sha256.h>
#include <key.h>
#include <util/system.h>
#include <util/strencodings.h>
#include <validation.h>
#include <util/system.h>
#include <memory>
const std::function<std::string(const char*)> G_TRANSLATION_FUN = nullptr;
static const int64_t DEFAULT_BENCH_EVALUATIONS = 5;
static const char* DEFAULT_BENCH_FILTER = ".*";
static const char* DEFAULT_BENCH_SCALING = "1.0";
@ -36,14 +33,6 @@ static void SetupBenchArgs()
gArgs.AddArg("-plot-height=<x>", strprintf("Plot height in pixel (default: %u)", DEFAULT_PLOT_HEIGHT), false, OptionsCategory::OPTIONS);
}
static fs::path SetDataDir()
{
fs::path ret = fs::temp_directory_path() / "bench_bitcoin" / fs::unique_path();
fs::create_directories(ret);
gArgs.ForceSetArg("-datadir", ret.string());
return ret;
}
int main(int argc, char** argv)
{
SetupBenchArgs();
@ -59,13 +48,6 @@ int main(int argc, char** argv)
return EXIT_SUCCESS;
}
// Set the datadir after parsing the bench options
const fs::path bench_datadir{SetDataDir()};
SHA256AutoDetect();
ECC_Start();
SetupEnvironment();
int64_t evaluations = gArgs.GetArg("-evals", DEFAULT_BENCH_EVALUATIONS);
std::string regex_filter = gArgs.GetArg("-filter", DEFAULT_BENCH_FILTER);
std::string scaling_str = gArgs.GetArg("-scaling", DEFAULT_BENCH_SCALING);
@ -88,9 +70,5 @@ int main(int argc, char** argv)
benchmark::BenchRunner::RunAll(*printer, evaluations, scaling_factor, regex_filter, is_list_only);
fs::remove_all(bench_datadir);
ECC_Stop();
return EXIT_SUCCESS;
}

View file

@ -1,58 +1,18 @@
// Copyright (c) 2011-2018 The Bitcoin Core developers
// Copyright (c) 2011-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 <bench/bench.h>
#include <chainparams.h>
#include <coins.h>
#include <consensus/merkle.h>
#include <consensus/validation.h>
#include <crypto/sha256.h>
#include <miner.h>
#include <policy/policy.h>
#include <pow.h>
#include <scheduler.h>
#include <txdb.h>
#include <test/util.h>
#include <txmempool.h>
#include <util/time.h>
#include <validation.h>
#include <validationinterface.h>
#include <boost/thread.hpp>
#include <list>
#include <vector>
static std::shared_ptr<CBlock> PrepareBlock(const CScript& coinbase_scriptPubKey)
{
auto block = std::make_shared<CBlock>(
BlockAssembler{Params()}
.CreateNewBlock(coinbase_scriptPubKey)
->block);
block->nTime = ::chainActive.Tip()->GetMedianTimePast() + 1;
block->hashMerkleRoot = BlockMerkleRoot(*block);
return block;
}
static CTxIn MineBlock(const CScript& coinbase_scriptPubKey)
{
auto block = PrepareBlock(coinbase_scriptPubKey);
while (!CheckProofOfWork(block->GetHash(), block->nBits, Params().GetConsensus())) {
++block->nNonce;
assert(block->nNonce);
}
bool processed{ProcessNewBlock(Params(), block, true, nullptr)};
assert(processed);
return CTxIn{block->vtx[0]->GetHash(), 0};
}
static void AssembleBlock(benchmark::State& state)
{
const std::vector<unsigned char> op_true{OP_TRUE};
@ -64,32 +24,6 @@ static void AssembleBlock(benchmark::State& state)
const CScript SCRIPT_PUB{CScript(OP_0) << std::vector<unsigned char>{witness_program.begin(), witness_program.end()}};
// Switch to regtest so we can mine faster
// Also segwit is active, so we can include witness transactions
SelectParams(CBaseChainParams::REGTEST);
InitScriptExecutionCache();
boost::thread_group thread_group;
CScheduler scheduler;
{
LOCK(cs_main);
::pblocktree.reset(new CBlockTreeDB(1 << 20, true));
::pcoinsdbview.reset(new CCoinsViewDB(1 << 23, true));
::pcoinsTip.reset(new CCoinsViewCache(pcoinsdbview.get()));
}
{
const CChainParams& chainparams = Params();
thread_group.create_thread(std::bind(&CScheduler::serviceQueue, &scheduler));
GetMainSignals().RegisterBackgroundSignalScheduler(scheduler);
LoadGenesisBlock(chainparams);
CValidationState state;
ActivateBestChain(state, chainparams);
assert(::chainActive.Tip() != nullptr);
const bool witness_enabled{IsWitnessEnabled(::chainActive.Tip(), chainparams.GetConsensus())};
assert(witness_enabled);
}
// Collect some loose transactions that spend the coinbases of our mined blocks
constexpr size_t NUM_BLOCKS{200};
std::array<CTransactionRef, NUM_BLOCKS - COINBASE_MATURITY + 1> txs;
@ -114,11 +48,6 @@ static void AssembleBlock(benchmark::State& state)
while (state.KeepRunning()) {
PrepareBlock(SCRIPT_PUB);
}
thread_group.interrupt_all();
thread_group.join_all();
GetMainSignals().FlushBackgroundCallbacks();
GetMainSignals().UnregisterBackgroundSignalScheduler();
}
BENCHMARK(AssembleBlock, 700);

View file

@ -1,4 +1,4 @@
// Copyright (c) 2011-2018 The Bitcoin Core developers
// Copyright (c) 2011-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.
@ -10,15 +10,11 @@
#include <miner.h>
#include <policy/policy.h>
#include <pow.h>
#include <scheduler.h>
#include <txdb.h>
#include <test/util.h>
#include <txmempool.h>
#include <util/time.h>
#include <validation.h>
#include <validationinterface.h>
#include <boost/thread.hpp>
#include <list>
#include <vector>
@ -27,31 +23,7 @@ static void DuplicateInputs(benchmark::State& state)
{
const CScript SCRIPT_PUB{CScript(OP_TRUE)};
// Switch to regtest so we can mine faster
// Also segwit is active, so we can include witness transactions
SelectParams(CBaseChainParams::REGTEST);
InitScriptExecutionCache();
boost::thread_group thread_group;
CScheduler scheduler;
const CChainParams& chainparams = Params();
{
LOCK(cs_main);
::pblocktree.reset(new CBlockTreeDB(1 << 20, true));
::pcoinsdbview.reset(new CCoinsViewDB(1 << 23, true));
::pcoinsTip.reset(new CCoinsViewCache(pcoinsdbview.get()));
}
{
thread_group.create_thread(std::bind(&CScheduler::serviceQueue, &scheduler));
GetMainSignals().RegisterBackgroundSignalScheduler(scheduler);
LoadGenesisBlock(chainparams);
CValidationState cvstate;
ActivateBestChain(cvstate, chainparams);
assert(::chainActive.Tip() != nullptr);
const bool witness_enabled{IsWitnessEnabled(::chainActive.Tip(), chainparams.GetConsensus())};
assert(witness_enabled);
}
CBlock block{};
CMutableTransaction coinbaseTx{};
@ -92,11 +64,6 @@ static void DuplicateInputs(benchmark::State& state)
assert(!CheckBlock(block, cvstate, chainparams.GetConsensus(), false, false));
assert(cvstate.GetRejectReason() == "bad-txns-inputs-duplicate");
}
thread_group.interrupt_all();
thread_group.join_all();
GetMainSignals().FlushBackgroundCallbacks();
GetMainSignals().UnregisterBackgroundSignalScheduler();
}
BENCHMARK(DuplicateInputs, 10);

View file

@ -1,6 +1,6 @@
#include <qt/test/addressbooktests.h>
#include <qt/test/util.h>
#include <test/test_bitcoin.h>
#include <test/setup_common.h>
#include <interfaces/chain.h>
#include <interfaces/node.h>

View file

@ -12,7 +12,7 @@
#include <rpc/register.h>
#include <rpc/server.h>
#include <qt/rpcconsole.h>
#include <test/test_bitcoin.h>
#include <test/setup_common.h>
#include <univalue.h>
#include <util/system.h>

View file

@ -15,7 +15,7 @@
#include <qt/transactionview.h>
#include <qt/walletmodel.h>
#include <key_io.h>
#include <test/test_bitcoin.h>
#include <test/setup_common.h>
#include <validation.h>
#include <wallet/wallet.h>
#include <qt/overviewpage.h>

View file

@ -42,7 +42,7 @@ unit tests as possible).
The build system is setup to compile an executable called `test_bitcoin`
that runs all of the unit tests. The main source file is called
test_bitcoin.cpp. To add a new unit test file to our test suite you need
setup_common.cpp. To add a new unit test file to our test suite you need
to add the file to `src/Makefile.test.include`. The pattern is to create
one test file for each class or source file for which you want to create
unit tests. The file naming convention is `<source_filename>_tests.cpp`

View file

@ -1,8 +1,8 @@
// Copyright (c) 2012-2018 The Bitcoin Core developers
// Copyright (c) 2012-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 <addrman.h>
#include <test/test_bitcoin.h>
#include <test/setup_common.h>
#include <string>
#include <boost/test/unit_test.hpp>

View file

@ -1,11 +1,11 @@
// Copyright (c) 2012-2018 The Bitcoin Core developers
// Copyright (c) 2012-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 <util/system.h>
#include <support/allocators/secure.h>
#include <test/test_bitcoin.h>
#include <test/setup_common.h>
#include <memory>

View file

@ -1,10 +1,10 @@
// Copyright (c) 2016-2018 The Bitcoin Core developers
// Copyright (c) 2016-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 <amount.h>
#include <policy/feerate.h>
#include <test/test_bitcoin.h>
#include <test/setup_common.h>
#include <boost/test/unit_test.hpp>

View file

@ -1,4 +1,4 @@
// Copyright (c) 2011-2018 The Bitcoin Core developers
// Copyright (c) 2011-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.
@ -12,7 +12,7 @@
#include <arith_uint256.h>
#include <string>
#include <version.h>
#include <test/test_bitcoin.h>
#include <test/setup_common.h>
BOOST_FIXTURE_TEST_SUITE(arith_uint256_tests, BasicTestingSetup)

View file

@ -1,9 +1,9 @@
// Copyright (c) 2012-2018 The Bitcoin Core developers
// Copyright (c) 2012-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 <util/strencodings.h>
#include <test/test_bitcoin.h>
#include <test/setup_common.h>
#include <boost/test/unit_test.hpp>

View file

@ -1,11 +1,11 @@
// Copyright (c) 2011-2018 The Bitcoin Core developers
// Copyright (c) 2011-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/data/base58_encode_decode.json.h>
#include <base58.h>
#include <test/test_bitcoin.h>
#include <test/setup_common.h>
#include <util/strencodings.h>
#include <univalue.h>

View file

@ -1,9 +1,9 @@
// Copyright (c) 2011-2018 The Bitcoin Core developers
// Copyright (c) 2011-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 <util/strencodings.h>
#include <test/test_bitcoin.h>
#include <test/setup_common.h>
#include <boost/test/unit_test.hpp>

View file

@ -3,7 +3,7 @@
// file COPYING or http://www.opensource.org/licenses/mit-license.php.
#include <bech32.h>
#include <test/test_bitcoin.h>
#include <test/setup_common.h>
#include <boost/test/unit_test.hpp>

View file

@ -1,4 +1,4 @@
// Copyright (c) 2013-2018 The Bitcoin Core developers
// Copyright (c) 2013-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.
@ -9,7 +9,7 @@
#include <uint256.h>
#include <util/system.h>
#include <util/strencodings.h>
#include <test/test_bitcoin.h>
#include <test/setup_common.h>
#include <string>
#include <vector>

View file

@ -3,7 +3,7 @@
#include <stdlib.h>
#include <rpc/blockchain.h>
#include <test/test_bitcoin.h>
#include <test/setup_common.h>
/* Equality between doubles is imprecise. Comparison should be done
* with a small threshold of tolerance, rather than exact equality.

View file

@ -1,4 +1,4 @@
// Copyright (c) 2011-2018 The Bitcoin Core developers
// Copyright (c) 2011-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.
@ -8,7 +8,7 @@
#include <pow.h>
#include <random.h>
#include <test/test_bitcoin.h>
#include <test/setup_common.h>
#include <boost/test/unit_test.hpp>

View file

@ -1,9 +1,9 @@
// Copyright (c) 2018 The Bitcoin Core developers
// Copyright (c) 2018-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/data/blockfilters.json.h>
#include <test/test_bitcoin.h>
#include <test/setup_common.h>
#include <blockfilter.h>
#include <core_io.h>

View file

@ -1,4 +1,4 @@
// Copyright (c) 2012-2018 The Bitcoin Core developers
// Copyright (c) 2012-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.
@ -15,7 +15,7 @@
#include <uint256.h>
#include <util/system.h>
#include <util/strencodings.h>
#include <test/test_bitcoin.h>
#include <test/setup_common.h>
#include <vector>

View file

@ -1,9 +1,9 @@
// Copyright (c) 2016-2018 The Bitcoin Core developers
// Copyright (c) 2016-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 <compat/byteswap.h>
#include <test/test_bitcoin.h>
#include <test/setup_common.h>
#include <boost/test/unit_test.hpp>

View file

@ -1,4 +1,4 @@
// Copyright (c) 2012-2018 The Bitcoin Core developers
// Copyright (c) 2012-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.
@ -6,7 +6,7 @@
#include <util/time.h>
#include <validation.h>
#include <test/test_bitcoin.h>
#include <test/setup_common.h>
#include <checkqueue.h>
#include <boost/test/unit_test.hpp>
#include <boost/thread.hpp>

View file

@ -1,4 +1,4 @@
// Copyright (c) 2014-2018 The Bitcoin Core developers
// Copyright (c) 2014-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.
@ -6,7 +6,7 @@
#include <coins.h>
#include <consensus/validation.h>
#include <script/standard.h>
#include <test/test_bitcoin.h>
#include <test/setup_common.h>
#include <uint256.h>
#include <undo.h>
#include <util/strencodings.h>

View file

@ -1,10 +1,10 @@
// Copyright (c) 2012-2018 The Bitcoin Core developers
// Copyright (c) 2012-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 <compressor.h>
#include <util/system.h>
#include <test/test_bitcoin.h>
#include <test/setup_common.h>
#include <stdint.h>

View file

@ -1,4 +1,4 @@
// Copyright (c) 2014-2018 The Bitcoin Core developers
// Copyright (c) 2014-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.
@ -13,7 +13,7 @@
#include <crypto/hmac_sha512.h>
#include <random.h>
#include <util/strencodings.h>
#include <test/test_bitcoin.h>
#include <test/setup_common.h>
#include <vector>

View file

@ -1,10 +1,10 @@
// Copyright (c) 2012-2018 The Bitcoin Core developers
// Copyright (c) 2012-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 <boost/test/unit_test.hpp>
#include <cuckoocache.h>
#include <script/sigcache.h>
#include <test/test_bitcoin.h>
#include <test/setup_common.h>
#include <random.h>
#include <thread>

View file

@ -1,11 +1,11 @@
// Copyright (c) 2012-2018 The Bitcoin Core developers
// Copyright (c) 2012-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 <dbwrapper.h>
#include <uint256.h>
#include <random.h>
#include <test/test_bitcoin.h>
#include <test/setup_common.h>
#include <memory>

View file

@ -1,4 +1,4 @@
// Copyright (c) 2011-2018 The Bitcoin Core developers
// Copyright (c) 2011-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.
@ -15,7 +15,7 @@
#include <util/system.h>
#include <validation.h>
#include <test/test_bitcoin.h>
#include <test/setup_common.h>
#include <stdint.h>

View file

@ -1,4 +1,4 @@
// Copyright (c) 2018 The Bitcoin Core developers
// Copyright (c) 2018-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.
@ -6,7 +6,7 @@
#include <string>
#include <script/sign.h>
#include <script/standard.h>
#include <test/test_bitcoin.h>
#include <test/setup_common.h>
#include <boost/test/unit_test.hpp>
#include <script/descriptor.h>
#include <util/strencodings.h>

View file

@ -3,7 +3,7 @@
// file COPYING or http://www.opensource.org/licenses/mit-license.php.
#include <flatfile.h>
#include <test/test_bitcoin.h>
#include <test/setup_common.h>
#include <boost/test/unit_test.hpp>

View file

@ -1,9 +1,9 @@
// Copyright (c) 2011-2018 The Bitcoin Core developers
// Copyright (c) 2011-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 <fs.h>
#include <test/test_bitcoin.h>
#include <test/setup_common.h>
#include <boost/test/unit_test.hpp>

View file

@ -1,4 +1,4 @@
// Copyright (c) 2009-2018 The Bitcoin Core developers
// Copyright (c) 2009-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.

View file

@ -1,10 +1,10 @@
// Copyright (c) 2012-2018 The Bitcoin Core developers
// Copyright (c) 2012-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 <util/strencodings.h>
#include <util/system.h>
#include <test/test_bitcoin.h>
#include <test/setup_common.h>
#include <string>
#include <vector>

View file

@ -1,11 +1,11 @@
// Copyright (c) 2013-2018 The Bitcoin Core developers
// Copyright (c) 2013-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 <crypto/siphash.h>
#include <hash.h>
#include <util/strencodings.h>
#include <test/test_bitcoin.h>
#include <test/setup_common.h>
#include <vector>

View file

@ -1,4 +1,4 @@
// Copyright (c) 2011-2018 The Bitcoin Core developers
// Copyright (c) 2011-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.
@ -9,7 +9,7 @@
#include <key_io.h>
#include <script/script.h>
#include <util/strencodings.h>
#include <test/test_bitcoin.h>
#include <test/setup_common.h>
#include <boost/test/unit_test.hpp>

View file

@ -1,4 +1,4 @@
// Copyright (c) 2018 The Bitcoin Core developers
// Copyright (c) 2018-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 <key.h>
@ -8,7 +8,7 @@
#include <uint256.h>
#include <util/system.h>
#include <util/strencodings.h>
#include <test/test_bitcoin.h>
#include <test/setup_common.h>
#include <string>
#include <vector>

View file

@ -1,4 +1,4 @@
// Copyright (c) 2012-2018 The Bitcoin Core developers
// Copyright (c) 2012-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.
@ -9,7 +9,7 @@
#include <uint256.h>
#include <util/system.h>
#include <util/strencodings.h>
#include <test/test_bitcoin.h>
#include <test/setup_common.h>
#include <string>
#include <vector>

View file

@ -1,10 +1,10 @@
// Copyright (c) 2012-2018 The Bitcoin Core developers
// Copyright (c) 2012-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 <limitedmap.h>
#include <test/test_bitcoin.h>
#include <test/setup_common.h>
#include <boost/test/unit_test.hpp>

View file

@ -1,4 +1,4 @@
// Copyright (c) 2011-2018 The Bitcoin Core developers
// Copyright (c) 2011-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.
@ -6,7 +6,7 @@
#include <txmempool.h>
#include <util/system.h>
#include <test/test_bitcoin.h>
#include <test/setup_common.h>
#include <boost/test/unit_test.hpp>
#include <list>

View file

@ -1,9 +1,9 @@
// Copyright (c) 2015-2018 The Bitcoin Core developers
// Copyright (c) 2015-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 <consensus/merkle.h>
#include <test/test_bitcoin.h>
#include <test/setup_common.h>
#include <boost/test/unit_test.hpp>

View file

@ -1,10 +1,10 @@
// Copyright (c) 2012-2018 The Bitcoin Core developers
// Copyright (c) 2012-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 <merkleblock.h>
#include <uint256.h>
#include <test/test_bitcoin.h>
#include <test/setup_common.h>
#include <boost/test/unit_test.hpp>

View file

@ -1,4 +1,4 @@
// Copyright (c) 2011-2018 The Bitcoin Core developers
// Copyright (c) 2011-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.
@ -18,7 +18,7 @@
#include <util/system.h>
#include <util/strencodings.h>
#include <test/test_bitcoin.h>
#include <test/setup_common.h>
#include <memory>

View file

@ -1,4 +1,4 @@
// Copyright (c) 2011-2018 The Bitcoin Core developers
// Copyright (c) 2011-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.
@ -11,7 +11,7 @@
#include <script/sign.h>
#include <script/ismine.h>
#include <uint256.h>
#include <test/test_bitcoin.h>
#include <test/setup_common.h>
#include <boost/test/unit_test.hpp>

View file

@ -1,8 +1,8 @@
// Copyright (c) 2012-2018 The Bitcoin Core developers
// Copyright (c) 2012-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 <addrman.h>
#include <test/test_bitcoin.h>
#include <test/setup_common.h>
#include <string>
#include <boost/test/unit_test.hpp>
#include <hash.h>

View file

@ -1,9 +1,9 @@
// Copyright (c) 2012-2018 The Bitcoin Core developers
// Copyright (c) 2012-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 <netbase.h>
#include <test/test_bitcoin.h>
#include <test/setup_common.h>
#include <util/strencodings.h>
#include <string>

View file

@ -1,4 +1,4 @@
// Copyright (c) 2012-2018 The Bitcoin Core developers
// Copyright (c) 2012-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.
@ -9,7 +9,7 @@
#include <uint256.h>
#include <arith_uint256.h>
#include <version.h>
#include <test/test_bitcoin.h>
#include <test/setup_common.h>
#include <vector>

View file

@ -1,4 +1,4 @@
// Copyright (c) 2011-2018 The Bitcoin Core developers
// Copyright (c) 2011-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.
@ -8,7 +8,7 @@
#include <uint256.h>
#include <util/system.h>
#include <test/test_bitcoin.h>
#include <test/setup_common.h>
#include <boost/test/unit_test.hpp>

View file

@ -1,4 +1,4 @@
// Copyright (c) 2015-2018 The Bitcoin Core developers
// Copyright (c) 2015-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.
@ -7,7 +7,7 @@
#include <pow.h>
#include <random.h>
#include <util/system.h>
#include <test/test_bitcoin.h>
#include <test/setup_common.h>
#include <boost/test/unit_test.hpp>

View file

@ -1,4 +1,4 @@
// Copyright (c) 2015-2018 The Bitcoin Core developers
// Copyright (c) 2015-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.
@ -9,7 +9,7 @@
#include <serialize.h>
#include <streams.h>
#include <test/test_bitcoin.h>
#include <test/setup_common.h>
#include <boost/test/unit_test.hpp>

View file

@ -1,4 +1,4 @@
// Copyright (c) 2016-2018 The Bitcoin Core developers
// Copyright (c) 2016-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.
@ -12,7 +12,7 @@
#include <support/events.h>
#include <test/test_bitcoin.h>
#include <test/setup_common.h>
#include <vector>

View file

@ -1,10 +1,10 @@
// Copyright (c) 2017-2018 The Bitcoin Core developers
// Copyright (c) 2017-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 <random.h>
#include <test/test_bitcoin.h>
#include <test/setup_common.h>
#include <boost/test/unit_test.hpp>

View file

@ -1,9 +1,9 @@
// Copyright (c) 2015-2018 The Bitcoin Core developers
// Copyright (c) 2015-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 <reverselock.h>
#include <test/test_bitcoin.h>
#include <test/setup_common.h>
#include <boost/test/unit_test.hpp>

View file

@ -1,4 +1,4 @@
// Copyright (c) 2012-2018 The Bitcoin Core developers
// Copyright (c) 2012-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.
@ -12,7 +12,7 @@
#include <key_io.h>
#include <netbase.h>
#include <test/test_bitcoin.h>
#include <test/setup_common.h>
#include <boost/algorithm/string.hpp>
#include <boost/test/unit_test.hpp>

View file

@ -1,10 +1,10 @@
// Copyright (c) 2012-2018 The Bitcoin Core developers
// Copyright (c) 2012-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 <compat/sanity.h>
#include <key.h>
#include <test/test_bitcoin.h>
#include <test/setup_common.h>
#include <boost/test/unit_test.hpp>

View file

@ -1,11 +1,11 @@
// Copyright (c) 2012-2018 The Bitcoin Core developers
// Copyright (c) 2012-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 <random.h>
#include <scheduler.h>
#include <test/test_bitcoin.h>
#include <test/setup_common.h>
#include <boost/thread.hpp>
#include <boost/test/unit_test.hpp>

View file

@ -1,4 +1,4 @@
// Copyright (c) 2012-2018 The Bitcoin Core developers
// Copyright (c) 2012-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.
@ -13,7 +13,7 @@
#include <policy/settings.h>
#include <script/sign.h>
#include <script/ismine.h>
#include <test/test_bitcoin.h>
#include <test/setup_common.h>
#include <vector>

View file

@ -1,4 +1,4 @@
// Copyright (c) 2017-2018 The Bitcoin Core developers
// Copyright (c) 2017-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.
@ -8,7 +8,7 @@
#include <script/script.h>
#include <script/script_error.h>
#include <script/standard.h>
#include <test/test_bitcoin.h>
#include <test/setup_common.h>
#include <boost/test/unit_test.hpp>

View file

@ -1,4 +1,4 @@
// Copyright (c) 2011-2018 The Bitcoin Core developers
// Copyright (c) 2011-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.
@ -12,7 +12,7 @@
#include <script/sign.h>
#include <util/system.h>
#include <util/strencodings.h>
#include <test/test_bitcoin.h>
#include <test/setup_common.h>
#include <rpc/util.h>
#if defined(HAVE_CONSENSUS_LIB)

View file

@ -1,10 +1,10 @@
// Copyright (c) 2012-2018 The Bitcoin Core developers
// Copyright (c) 2012-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/scriptnum10.h>
#include <script/script.h>
#include <test/test_bitcoin.h>
#include <test/setup_common.h>
#include <boost/test/unit_test.hpp>
#include <limits.h>

View file

@ -1,11 +1,11 @@
// Copyright (c) 2012-2018 The Bitcoin Core developers
// Copyright (c) 2012-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 <serialize.h>
#include <streams.h>
#include <hash.h>
#include <test/test_bitcoin.h>
#include <test/setup_common.h>
#include <stdint.h>

View file

@ -1,8 +1,8 @@
// Copyright (c) 2011-2018 The Bitcoin Core developers
// Copyright (c) 2011-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/test_bitcoin.h>
#include <test/setup_common.h>
#include <banman.h>
#include <chainparams.h>
@ -33,7 +33,7 @@ std::ostream& operator<<(std::ostream& os, const uint256& num)
}
BasicTestingSetup::BasicTestingSetup(const std::string& chainName)
: m_path_root(fs::temp_directory_path() / "test_bitcoin" / strprintf("%lu_%i", (unsigned long)GetTime(), (int)(InsecureRandRange(1 << 30))))
: m_path_root(fs::temp_directory_path() / "test_common_" PACKAGE_NAME / strprintf("%lu_%i", (unsigned long)GetTime(), (int)(InsecureRandRange(1 << 30))))
{
SHA256AutoDetect();
ECC_Start();
@ -42,9 +42,6 @@ BasicTestingSetup::BasicTestingSetup(const std::string& chainName)
InitSignatureCache();
InitScriptExecutionCache();
fCheckBlockIndex = true;
// CreateAndProcessBlock() does not support building SegWit blocks, so don't activate in these tests.
// TODO: fix the code to support SegWit blocks.
gArgs.ForceSetArg("-vbparams", strprintf("segwit:0:%d", (int64_t)Consensus::BIP9Deployment::NO_TIMEOUT));
SelectParams(chainName);
noui_connect();
}
@ -115,6 +112,11 @@ TestingSetup::~TestingSetup()
TestChain100Setup::TestChain100Setup() : TestingSetup(CBaseChainParams::REGTEST)
{
// CreateAndProcessBlock() does not support building SegWit blocks, so don't activate in these tests.
// TODO: fix the code to support SegWit blocks.
gArgs.ForceSetArg("-vbparams", strprintf("segwit:0:%d", (int64_t)Consensus::BIP9Deployment::NO_TIMEOUT));
SelectParams(CBaseChainParams::REGTEST);
// Generate a 100-block chain:
coinbaseKey.MakeNewKey(true);
CScript scriptPubKey = CScript() << ToByteVector(coinbaseKey.GetPubKey()) << OP_CHECKSIG;

View file

@ -1,9 +1,9 @@
// Copyright (c) 2015-2018 The Bitcoin Core developers
// Copyright (c) 2015-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_TEST_BITCOIN_H
#define BITCOIN_TEST_TEST_BITCOIN_H
#ifndef BITCOIN_TEST_SETUP_COMMON_H
#define BITCOIN_TEST_SETUP_COMMON_H
#include <chainparamsbase.h>
#include <fs.h>

View file

@ -1,4 +1,4 @@
// Copyright (c) 2013-2018 The Bitcoin Core developers
// Copyright (c) 2013-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.
@ -10,7 +10,7 @@
#include <script/script.h>
#include <serialize.h>
#include <streams.h>
#include <test/test_bitcoin.h>
#include <test/setup_common.h>
#include <util/system.h>
#include <util/strencodings.h>
#include <version.h>

View file

@ -1,4 +1,4 @@
// Copyright (c) 2012-2018 The Bitcoin Core developers
// Copyright (c) 2012-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.
@ -9,7 +9,7 @@
#include <script/script.h>
#include <script/standard.h>
#include <uint256.h>
#include <test/test_bitcoin.h>
#include <test/setup_common.h>
#include <vector>

View file

@ -1,10 +1,10 @@
// Copyright (c) 2014-2018 The Bitcoin Core developers
// Copyright (c) 2014-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 <chain.h>
#include <util/system.h>
#include <test/test_bitcoin.h>
#include <test/setup_common.h>
#include <vector>

View file

@ -1,10 +1,10 @@
// Copyright (c) 2012-2018 The Bitcoin Core developers
// Copyright (c) 2012-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 <streams.h>
#include <support/allocators/zeroafterfree.h>
#include <test/test_bitcoin.h>
#include <test/setup_common.h>
#include <boost/test/unit_test.hpp>

View file

@ -1,9 +1,9 @@
// Copyright (c) 2012-2017 The Bitcoin Core developers
// Copyright (c) 2012-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 <sync.h>
#include <test/test_bitcoin.h>
#include <test/setup_common.h>
#include <boost/test/unit_test.hpp>

View file

@ -1,9 +1,9 @@
// Copyright (c) 2011-2018 The Bitcoin Core developers
// Copyright (c) 2011-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 <timedata.h>
#include <test/test_bitcoin.h>
#include <test/setup_common.h>
#include <boost/test/unit_test.hpp>

View file

@ -2,7 +2,7 @@
// Distributed under the MIT software license, see the accompanying
// file COPYING or http://www.opensource.org/licenses/mit-license.php.
//
#include <test/test_bitcoin.h>
#include <test/setup_common.h>
#include <torcontrol.h>
#include <boost/test/unit_test.hpp>

View file

@ -1,10 +1,10 @@
// Copyright (c) 2011-2018 The Bitcoin Core developers
// Copyright (c) 2011-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/data/tx_invalid.json.h>
#include <test/data/tx_valid.json.h>
#include <test/test_bitcoin.h>
#include <test/setup_common.h>
#include <clientversion.h>
#include <checkqueue.h>

View file

@ -1,11 +1,11 @@
// Copyright (c) 2017-2018 The Bitcoin Core developers
// Copyright (c) 2017-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 <chainparams.h>
#include <index/txindex.h>
#include <script/standard.h>
#include <test/test_bitcoin.h>
#include <test/setup_common.h>
#include <util/system.h>
#include <util/time.h>
#include <validation.h>

View file

@ -1,4 +1,4 @@
// Copyright (c) 2017-2018 The Bitcoin Core developers
// Copyright (c) 2017-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.
@ -8,7 +8,7 @@
#include <consensus/validation.h>
#include <primitives/transaction.h>
#include <script/script.h>
#include <test/test_bitcoin.h>
#include <test/setup_common.h>
#include <boost/test/unit_test.hpp>

View file

@ -1,4 +1,4 @@
// Copyright (c) 2011-2018 The Bitcoin Core developers
// Copyright (c) 2011-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.
@ -11,7 +11,7 @@
#include <random.h>
#include <script/standard.h>
#include <script/sign.h>
#include <test/test_bitcoin.h>
#include <test/setup_common.h>
#include <util/time.h>
#include <core_io.h>
#include <keystore.h>

View file

@ -1,10 +1,10 @@
// Copyright (c) 2011-2018 The Bitcoin Core developers
// Copyright (c) 2011-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 <arith_uint256.h>
#include <uint256.h>
#include <version.h>
#include <test/test_bitcoin.h>
#include <test/setup_common.h>
#include <boost/test/unit_test.hpp>
#include <stdint.h>

90
src/test/util.cpp Normal file
View file

@ -0,0 +1,90 @@
// 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/util.h>
#include <chainparams.h>
#include <consensus/merkle.h>
#include <consensus/validation.h>
#include <key_io.h>
#include <miner.h>
#include <outputtype.h>
#include <pow.h>
#include <scheduler.h>
#include <script/standard.h>
#include <txdb.h>
#include <validation.h>
#include <validationinterface.h>
#ifdef ENABLE_WALLET
#include <wallet/wallet.h>
#endif
#include <boost/thread.hpp>
#ifdef ENABLE_WALLET
std::string getnewaddress(CWallet& w)
{
constexpr auto output_type = OutputType::BECH32;
CPubKey new_key;
if (!w.GetKeyFromPool(new_key)) assert(false);
w.LearnRelatedScripts(new_key, output_type);
const auto dest = GetDestinationForKey(new_key, output_type);
w.SetAddressBook(dest, /* label */ "", "receive");
return EncodeDestination(dest);
}
void importaddress(CWallet& wallet, const std::string& address)
{
LOCK(wallet.cs_wallet);
const auto dest = DecodeDestination(address);
assert(IsValidDestination(dest));
const auto script = GetScriptForDestination(dest);
wallet.MarkDirty();
assert(!wallet.HaveWatchOnly(script));
if (!wallet.AddWatchOnly(script, 0 /* nCreateTime */)) assert(false);
wallet.SetAddressBook(dest, /* label */ "", "receive");
}
#endif // ENABLE_WALLET
CTxIn generatetoaddress(const std::string& address)
{
const auto dest = DecodeDestination(address);
assert(IsValidDestination(dest));
const auto coinbase_script = GetScriptForDestination(dest);
return MineBlock(coinbase_script);
}
CTxIn MineBlock(const CScript& coinbase_scriptPubKey)
{
auto block = PrepareBlock(coinbase_scriptPubKey);
while (!CheckProofOfWork(block->GetHash(), block->nBits, Params().GetConsensus())) {
++block->nNonce;
assert(block->nNonce);
}
bool processed{ProcessNewBlock(Params(), block, true, nullptr)};
assert(processed);
return CTxIn{block->vtx[0]->GetHash(), 0};
}
std::shared_ptr<CBlock> PrepareBlock(const CScript& coinbase_scriptPubKey)
{
auto block = std::make_shared<CBlock>(
BlockAssembler{Params()}
.CreateNewBlock(coinbase_scriptPubKey)
->block);
block->nTime = ::chainActive.Tip()->GetMedianTimePast() + 1;
block->hashMerkleRoot = BlockMerkleRoot(*block);
return block;
}

34
src/test/util.h Normal file
View file

@ -0,0 +1,34 @@
// 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_UTIL_H
#define BITCOIN_TEST_UTIL_H
#include <memory>
#include <string>
class CBlock;
class CScript;
class CTxIn;
class CWallet;
// Lower-level utils //
/** Returns the generated coin */
CTxIn MineBlock(const CScript& coinbase_scriptPubKey);
/** Prepare a block to be mined */
std::shared_ptr<CBlock> PrepareBlock(const CScript& coinbase_scriptPubKey);
// RPC-like //
/** Import the address to the wallet */
void importaddress(CWallet& wallet, const std::string& address);
/** Returns a new address from the wallet */
std::string getnewaddress(CWallet& w);
/** Returns the generated coin */
CTxIn generatetoaddress(const std::string& address);
#endif // BITCOIN_TEST_UTIL_H

View file

@ -1,4 +1,4 @@
// Copyright (c) 2011-2018 The Bitcoin Core developers
// Copyright (c) 2011-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.
@ -9,7 +9,7 @@
#include <sync.h>
#include <util/strencodings.h>
#include <util/moneystr.h>
#include <test/test_bitcoin.h>
#include <test/setup_common.h>
#include <stdint.h>
#include <vector>

View file

@ -1,4 +1,4 @@
// Copyright (c) 2018 The Bitcoin Core developers
// Copyright (c) 2018-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.
@ -10,7 +10,7 @@
#include <miner.h>
#include <pow.h>
#include <random.h>
#include <test/test_bitcoin.h>
#include <test/setup_common.h>
#include <validation.h>
#include <validationinterface.h>

View file

@ -6,7 +6,7 @@
#include <net.h>
#include <validation.h>
#include <test/test_bitcoin.h>
#include <test/setup_common.h>
#include <boost/signals2/signal.hpp>
#include <boost/test/unit_test.hpp>

View file

@ -1,10 +1,10 @@
// Copyright (c) 2014-2018 The Bitcoin Core developers
// Copyright (c) 2014-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 <chain.h>
#include <versionbits.h>
#include <test/test_bitcoin.h>
#include <test/setup_common.h>
#include <chainparams.h>
#include <validation.h>
#include <consensus/params.h>

View file

@ -8,7 +8,7 @@
#include <amount.h>
#include <primitives/transaction.h>
#include <random.h>
#include <test/test_bitcoin.h>
#include <test/setup_common.h>
#include <wallet/test/wallet_test_fixture.h>
#include <boost/test/unit_test.hpp>

View file

@ -7,7 +7,7 @@
#include <boost/test/unit_test.hpp>
#include <fs.h>
#include <test/test_bitcoin.h>
#include <test/setup_common.h>
#include <wallet/db.h>

View file

@ -6,7 +6,7 @@
#define BITCOIN_WALLET_TEST_INIT_TEST_FIXTURE_H
#include <interfaces/chain.h>
#include <test/test_bitcoin.h>
#include <test/setup_common.h>
struct InitWalletDirTestingSetup: public BasicTestingSetup {

View file

@ -4,7 +4,7 @@
#include <boost/test/unit_test.hpp>
#include <test/test_bitcoin.h>
#include <test/setup_common.h>
#include <wallet/test/init_test_fixture.h>
#include <init.h>

View file

@ -12,7 +12,7 @@
#include <univalue.h>
#include <boost/test/unit_test.hpp>
#include <test/test_bitcoin.h>
#include <test/setup_common.h>
#include <wallet/test/wallet_test_fixture.h>
BOOST_FIXTURE_TEST_SUITE(psbt_wallet_tests, WalletTestingSetup)

View file

@ -2,7 +2,7 @@
// Distributed under the MIT software license, see the accompanying
// file COPYING or http://www.opensource.org/licenses/mit-license.php.
#include <test/test_bitcoin.h>
#include <test/setup_common.h>
#include <util/strencodings.h>
#include <wallet/crypter.h>

View file

@ -5,7 +5,7 @@
#ifndef BITCOIN_WALLET_TEST_WALLET_TEST_FIXTURE_H
#define BITCOIN_WALLET_TEST_WALLET_TEST_FIXTURE_H
#include <test/test_bitcoin.h>
#include <test/setup_common.h>
#include <interfaces/chain.h>
#include <interfaces/wallet.h>

View file

@ -13,7 +13,7 @@
#include <consensus/validation.h>
#include <interfaces/chain.h>
#include <rpc/server.h>
#include <test/test_bitcoin.h>
#include <test/setup_common.h>
#include <validation.h>
#include <wallet/coincontrol.h>
#include <wallet/test/wallet_test_fixture.h>