merge bitcoin#15788: Unify testing setups for fuzz, bench, and unit tests

This commit is contained in:
Kittywhiskers Van Gogh 2021-10-25 21:28:37 +05:30
parent 544823b272
commit ad203019f9
108 changed files with 248 additions and 245 deletions

View File

@ -41,7 +41,11 @@ bench_bench_dash_SOURCES = \
bench/lockedpool.cpp \
bench/poly1305.cpp \
bench/prevector.cpp \
bench/string_cast.cpp
bench/string_cast.cpp \
test/setup_common.cpp \
test/setup_common.h \
test/util.cpp \
test/util.h
nodist_bench_bench_dash_SOURCES = $(GENERATED_BENCH_FILES)

View File

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

View File

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

View File

@ -5,8 +5,14 @@
#include <bench/bench.h>
#include <chainparams.h>
#include <test/setup_common.h>
#include <validation.h>
#include <algorithm>
#include <assert.h>
#include <iomanip>
#include <iostream>
#include <numeric>
#include <regex>
namespace {
@ -47,6 +53,11 @@ void benchmark::BenchRunner::RunAll(const Args& args)
std::vector<ankerl::nanobench::Result> benchmarkResults;
for (const auto& p : benchmarks()) {
TestingSetup test{CBaseChainParams::REGTEST};
{
assert(::ChainActive().Height() == 0);
}
if (!std::regex_match(p.first, baseMatch, reFilter)) {
continue;
}

View File

@ -9,7 +9,6 @@
#include <stacktraces.h>
#include <util/strencodings.h>
#include <util/system.h>
#include <validation.h>
#include <boost/lexical_cast.hpp>
@ -17,20 +16,11 @@
#include <bls/bls.h>
const std::function<std::string(const char*)> G_TRANSLATION_FUN = nullptr;
static const char* DEFAULT_BENCH_FILTER = ".*";
void InitBLSTests();
void CleanupBLSTests();
static fs::path SetDataDir()
{
fs::path ret = fs::temp_directory_path() / "bench_dash" / fs::unique_path();
fs::create_directories(ret);
gArgs.ForceSetArg("-datadir", ret.string());
return ret;
}
static void SetupBenchArgs()
{
gArgs.AddArg("-?", "Print this help message and exit", false, OptionsCategory::OPTIONS);
@ -72,21 +62,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();
RegisterPrettySignalHandlers();
RegisterPrettyTerminateHander();
ECC_Start();
ECCVerifyHandle verifyHandle;
BLSInit();
InitBLSTests();
SetupEnvironment();
benchmark::Args args;
args.regex_filter = gArgs.GetArg("-filter", DEFAULT_BENCH_FILTER);
args.is_list_only = gArgs.GetBoolArg("-list", false);
@ -96,12 +71,5 @@ int main(int argc, char** argv)
benchmark::BenchRunner::RunAll(args);
fs::remove_all(bench_datadir);
// need to be called before global destructors kick in (PoolAllocator is needed due to many BLSSecretKeys)
CleanupBLSTests();
ECC_Stop();
return EXIT_SUCCESS;
}

View File

@ -3,58 +3,18 @@
// 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/consensus.h>
#include <consensus/validation.h>
#include <crypto/sha256.h>
#include <miner.h>
#include <policy/policy.h>
#include <pow.h>
#include <scheduler.h>
#include <script/standard.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, /* fMineWitnessTx */ true)
->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::Bench& bench)
{
const CScript redeemScript = CScript() << OP_DROP << OP_TRUE;
@ -65,29 +25,6 @@ static void AssembleBlock(benchmark::Bench& bench)
const CScript scriptSig = CScript() << std::vector<uint8_t>(100, 0xff)
<< ToByteVector(redeemScript);
// Switch to regtest so we can mine faster
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);
}
// 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;
@ -112,11 +49,6 @@ static void AssembleBlock(benchmark::Bench& bench)
bench.minEpochIterations(700).run([&] {
PrepareBlock(SCRIPT_PUB);
});
thread_group.interrupt_all();
thread_group.join_all();
GetMainSignals().FlushBackgroundCallbacks();
GetMainSignals().UnregisterBackgroundSignalScheduler();
}
BENCHMARK(AssembleBlock);

View File

@ -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::Bench& bench)
{
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{};
@ -91,11 +63,6 @@ static void DuplicateInputs(benchmark::Bench& bench)
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);

View File

@ -1,6 +1,6 @@
#include <qt/test/addressbooktests.h>
#include <qt/test/util.h>
#include <test/test_dash.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_dash.h>
#include <test/setup_common.h>
#include <univalue.h>
#include <util/system.h>

View File

@ -16,7 +16,7 @@
#include <qt/transactionview.h>
#include <qt/walletmodel.h>
#include <key_io.h>
#include <test/test_dash.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_dash`
that runs all of the unit tests. The main source file is called
test_dash.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

@ -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 <addrman.h>
#include <test/test_dash.h>
#include <test/setup_common.h>
#include <string>
#include <boost/test/unit_test.hpp>
#include <util/asmap.h>

View File

@ -5,7 +5,7 @@
#include <util/system.h>
#include <support/allocators/secure.h>
#include <test/test_dash.h>
#include <test/setup_common.h>
#include <memory>

View File

@ -4,7 +4,7 @@
#include <amount.h>
#include <policy/feerate.h>
#include <test/test_dash.h>
#include <test/setup_common.h>
#include <boost/test/unit_test.hpp>

View File

@ -12,7 +12,7 @@
#include <arith_uint256.h>
#include <string>
#include <version.h>
#include <test/test_dash.h>
#include <test/setup_common.h>
BOOST_FIXTURE_TEST_SUITE(arith_uint256_tests, BasicTestingSetup)

View File

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

View File

@ -5,7 +5,7 @@
#include <test/data/base58_encode_decode.json.h>
#include <base58.h>
#include <test/test_dash.h>
#include <test/setup_common.h>
#include <util/strencodings.h>
#include <univalue.h>

View File

@ -3,7 +3,7 @@
// file COPYING or http://www.opensource.org/licenses/mit-license.php.
#include <util/strencodings.h>
#include <test/test_dash.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_dash.h>
#include <test/setup_common.h>
#include <boost/test/unit_test.hpp>

View File

@ -9,7 +9,7 @@
#include <uint256.h>
#include <util/system.h>
#include <util/strencodings.h>
#include <test/test_dash.h>
#include <test/setup_common.h>
#include <string>
#include <vector>

View File

@ -8,7 +8,7 @@
#include <key_io.h>
#include <util/system.h>
#include <util/strencodings.h>
#include <test/test_dash.h>
#include <test/setup_common.h>
#include <bip39.h>
#include <boost/test/unit_test.hpp>

View File

@ -3,7 +3,7 @@
#include <stdlib.h>
#include <rpc/blockchain.h>
#include <test/test_dash.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

@ -8,7 +8,7 @@
#include <pow.h>
#include <random.h>
#include <test/test_dash.h>
#include <test/setup_common.h>
#include <boost/test/unit_test.hpp>

View File

@ -8,7 +8,7 @@
#include <index/blockfilterindex.h>
#include <miner.h>
#include <pow.h>
#include <test/test_dash.h>
#include <test/setup_common.h>
#include <script/standard.h>
#include <validation.h>

View File

@ -3,7 +3,7 @@
// file COPYING or http://www.opensource.org/licenses/mit-license.php.
#include <test/data/blockfilters.json.h>
#include <test/test_dash.h>
#include <test/setup_common.h>
#include <blockfilter.h>
#include <core_io.h>

View File

@ -15,7 +15,7 @@
#include <uint256.h>
#include <util/system.h>
#include <util/strencodings.h>
#include <test/test_dash.h>
#include <test/setup_common.h>
#include <vector>

View File

@ -5,7 +5,7 @@
#include <bls/bls.h>
#include <bls/bls_batchverifier.h>
#include <random.h>
#include <test/test_dash.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 <compat/byteswap.h>
#include <test/test_dash.h>
#include <test/setup_common.h>
#include <boost/test/unit_test.hpp>

View File

@ -2,7 +2,7 @@
#include <cachemap.h>
#include <test/test_dash.h>
#include <test/setup_common.h>
#include <boost/test/unit_test.hpp>

View File

@ -2,7 +2,7 @@
#include <cachemultimap.h>
#include <test/test_dash.h>
#include <test/setup_common.h>
#include <algorithm>
#include <iostream>

View File

@ -6,7 +6,7 @@
#include <script/interpreter.h>
#include <test/lcg.h>
#include <test/test_dash.h>
#include <test/setup_common.h>
#include <boost/test/unit_test.hpp>

View File

@ -6,7 +6,7 @@
#include <util/system.h>
#include <util/time.h>
#include <test/test_dash.h>
#include <test/setup_common.h>
#include <checkqueue.h>
#include <boost/test/unit_test.hpp>
#include <boost/thread.hpp>

View File

@ -6,7 +6,7 @@
#include <coins.h>
#include <consensus/validation.h>
#include <script/standard.h>
#include <test/test_dash.h>
#include <test/setup_common.h>
#include <uint256.h>
#include <undo.h>
#include <util/strencodings.h>

View File

@ -4,7 +4,7 @@
#include <compressor.h>
#include <util/system.h>
#include <test/test_dash.h>
#include <test/setup_common.h>
#include <stdint.h>

View File

@ -16,7 +16,7 @@
#include <crypto/sha512.h>
#include <random.h>
#include <util/strencodings.h>
#include <test/test_dash.h>
#include <test/setup_common.h>
#include <vector>

View File

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

View File

@ -5,7 +5,7 @@
#include <dbwrapper.h>
#include <uint256.h>
#include <random.h>
#include <test/test_dash.h>
#include <test/setup_common.h>
#include <memory>

View File

@ -15,7 +15,7 @@
#include <util/system.h>
#include <validation.h>
#include <test/test_dash.h>
#include <test/setup_common.h>
#include <stdint.h>

View File

@ -6,7 +6,7 @@
#include <string>
#include <script/sign.h>
#include <script/standard.h>
#include <test/test_dash.h>
#include <test/setup_common.h>
#include <boost/test/unit_test.hpp>
#include <script/descriptor.h>
#include <util/strencodings.h>

View File

@ -5,7 +5,7 @@
#include <policy/policy.h>
#include <script/interpreter.h>
#include <test/test_dash.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_dash.h>
#include <test/setup_common.h>
#include <consensus/validation.h>
#include <script/interpreter.h>

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_dash.h>
#include <test/setup_common.h>
#include <bls/bls.h>
#include <evo/simplifiedmns.h>

View File

@ -3,7 +3,7 @@
// file COPYING or http://www.opensource.org/licenses/mit-license.php.
#include <flatfile.h>
#include <test/test_dash.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 <fs.h>
#include <test/test_dash.h>
#include <test/setup_common.h>
#include <util/getuniquepath.h>
#include <boost/test/unit_test.hpp>

View File

@ -4,7 +4,7 @@
#include <util/strencodings.h>
#include <util/system.h>
#include <test/test_dash.h>
#include <test/setup_common.h>
#include <string>
#include <vector>

View File

@ -6,7 +6,7 @@
#include <test/data/proposals_valid.json.h>
#include <test/data/proposals_invalid.json.h>
#include <test/test_dash.h>
#include <test/setup_common.h>
#include <iostream>
#include <fstream>

View File

@ -5,7 +5,7 @@
#include <crypto/siphash.h>
#include <hash.h>
#include <util/strencodings.h>
#include <test/test_dash.h>
#include <test/setup_common.h>
#include <vector>

View File

@ -9,7 +9,7 @@
#include <key_io.h>
#include <script/script.h>
#include <util/strencodings.h>
#include <test/test_dash.h>
#include <test/setup_common.h>
#include <boost/test/unit_test.hpp>

View File

@ -9,7 +9,7 @@
#include <uint256.h>
#include <util/system.h>
#include <util/strencodings.h>
#include <test/test_dash.h>
#include <test/setup_common.h>
#include <string>
#include <vector>

View File

@ -4,7 +4,7 @@
#include <limitedmap.h>
#include <test/test_dash.h>
#include <test/setup_common.h>
#include <boost/test/unit_test.hpp>

View File

@ -4,7 +4,7 @@
#include <logging.h>
#include <logging/timer.h>
#include <test/test_dash.h>
#include <test/setup_common.h>
#include <chrono>

View File

@ -5,7 +5,7 @@
#include <txmempool.h>
#include <util/system.h>
#include <test/test_dash.h>
#include <test/setup_common.h>
#include <boost/test/unit_test.hpp>
#include <list>

View File

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

View File

@ -4,7 +4,7 @@
#include <merkleblock.h>
#include <uint256.h>
#include <test/test_dash.h>
#include <test/setup_common.h>
#include <boost/test/unit_test.hpp>

View File

@ -20,7 +20,7 @@
#include <util/system.h>
#include <util/strencodings.h>
#include <test/test_dash.h>
#include <test/setup_common.h>
#include <memory>

View File

@ -11,7 +11,7 @@
#include <script/sign.h>
#include <script/ismine.h>
#include <uint256.h>
#include <test/test_dash.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 <addrman.h>
#include <test/test_dash.h>
#include <test/setup_common.h>
#include <string>
#include <boost/test/unit_test.hpp>
#include <hash.h>

View File

@ -8,7 +8,7 @@
#include <protocol.h>
#include <serialize.h>
#include <streams.h>
#include <test/test_dash.h>
#include <test/setup_common.h>
#include <util/strencodings.h>
#include <version.h>

View File

@ -9,7 +9,7 @@
#include <uint256.h>
#include <arith_uint256.h>
#include <version.h>
#include <test/test_dash.h>
#include <test/setup_common.h>
#include <vector>

View File

@ -7,7 +7,7 @@
#include <uint256.h>
#include <util/system.h>
#include <test/test_dash.h>
#include <test/setup_common.h>
#include <boost/test/unit_test.hpp>

View File

@ -7,7 +7,7 @@
#include <pow.h>
#include <random.h>
#include <util/system.h>
#include <test/test_dash.h>
#include <test/setup_common.h>
#include <boost/test/unit_test.hpp>

View File

@ -9,7 +9,7 @@
#include <serialize.h>
#include <streams.h>
#include <test/test_dash.h>
#include <test/setup_common.h>
#include <boost/test/unit_test.hpp>

View File

@ -9,7 +9,7 @@
#include <support/events.h>
#include <test/test_dash.h>
#include <test/setup_common.h>
#include <vector>

View File

@ -4,7 +4,7 @@
#include <random.h>
#include <test/test_dash.h>
#include <test/setup_common.h>
#include <boost/test/unit_test.hpp>

View File

@ -2,7 +2,7 @@
#include <governance/governance.h>
#include <test/test_dash.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 <sync.h>
#include <test/test_dash.h>
#include <test/setup_common.h>
#include <boost/test/unit_test.hpp>

View File

@ -12,7 +12,7 @@
#include <key_io.h>
#include <netbase.h>
#include <test/test_dash.h>
#include <test/setup_common.h>
#include <boost/algorithm/string.hpp>
#include <boost/test/unit_test.hpp>

View File

@ -4,7 +4,7 @@
#include <compat/sanity.h>
#include <key.h>
#include <test/test_dash.h>
#include <test/setup_common.h>
#include <boost/test/unit_test.hpp>

View File

@ -6,7 +6,7 @@
#include <scheduler.h>
#include <util/time.h>
#include <test/test_dash.h>
#include <test/setup_common.h>
#include <boost/thread.hpp>
#include <boost/test/unit_test.hpp>

View File

@ -3,7 +3,7 @@
// file COPYING or http://www.opensource.org/licenses/mit-license.php.
#include <script/script.h>
#include <test/test_dash.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 <script/script.h>
#include <test/test_dash.h>
#include <test/setup_common.h>
#include <boost/test/unit_test.hpp>

View File

@ -12,7 +12,7 @@
#include <script/script_error.h>
#include <script/sign.h>
#include <script/ismine.h>
#include <test/test_dash.h>
#include <test/setup_common.h>
#include <vector>

View File

@ -8,7 +8,7 @@
#include <script/script.h>
#include <script/script_error.h>
#include <script/standard.h>
#include <test/test_dash.h>
#include <test/setup_common.h>
#include <boost/test/unit_test.hpp>

View File

@ -12,7 +12,7 @@
#include <script/sign.h>
#include <util/system.h>
#include <util/strencodings.h>
#include <test/test_dash.h>
#include <test/setup_common.h>
#if defined(HAVE_CONSENSUS_LIB)
#include <script/dashconsensus.h>

View File

@ -4,7 +4,7 @@
#include <test/scriptnum10.h>
#include <script/script.h>
#include <test/test_dash.h>
#include <test/setup_common.h>
#include <boost/test/unit_test.hpp>
#include <limits.h>

View File

@ -5,7 +5,7 @@
#include <serialize.h>
#include <streams.h>
#include <hash.h>
#include <test/test_dash.h>
#include <test/setup_common.h>
#include <stdint.h>

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_dash.h>
#include <test/setup_common.h>
#include <banman.h>
#include <chainparams.h>
@ -41,7 +41,7 @@ std::ostream& operator<<(std::ostream& os, const uint256& num)
}
BasicTestingSetup::BasicTestingSetup(const std::string& chainName)
: m_path_root(fs::temp_directory_path() / "test_dash" / 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();
@ -52,8 +52,6 @@ BasicTestingSetup::BasicTestingSetup(const std::string& chainName)
InitScriptExecutionCache();
CCoinJoin::InitStandardDenominations();
fCheckBlockIndex = true;
// Make sure CreateAndProcessBlock() support building <deployment_name> blocks before activating it in these tests.
//gArgs.ForceSetArg("-vbparams", strprintf("deployment_name:0:%d", (int64_t)Consensus::BIP9Deployment::NO_TIMEOUT));
SelectParams(chainName);
evoDb.reset(new CEvoDB(1 << 20, true, true));
deterministicMNManager.reset(new CDeterministicMNManager(*evoDb));
@ -145,6 +143,10 @@ TestingSetup::~TestingSetup()
TestChainSetup::TestChainSetup(int blockCount) : TestingSetup(CBaseChainParams::REGTEST)
{
// Make sure CreateAndProcessBlock() support building <deployment_name> blocks before activating it in these tests.
//gArgs.ForceSetArg("-vbparams", strprintf("deployment_name: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

@ -3,8 +3,8 @@
// Distributed under the MIT software license, see the accompanying
// file COPYING or http://www.opensource.org/licenses/mit-license.php.
#ifndef BITCOIN_TEST_TEST_DASH_H
#define BITCOIN_TEST_TEST_DASH_H
#ifndef BITCOIN_TEST_SETUP_COMMON_H
#define BITCOIN_TEST_SETUP_COMMON_H
#include <chainparamsbase.h>
#include <fs.h>

View File

@ -10,7 +10,7 @@
#include <script/script.h>
#include <serialize.h>
#include <streams.h>
#include <test/test_dash.h>
#include <test/setup_common.h>
#include <util/system.h>
#include <util/strencodings.h>
#include <version.h>

View File

@ -8,7 +8,7 @@
#include <script/script.h>
#include <script/standard.h>
#include <uint256.h>
#include <test/test_dash.h>
#include <test/setup_common.h>
#include <vector>

View File

@ -4,7 +4,7 @@
#include <chain.h>
#include <util/system.h>
#include <test/test_dash.h>
#include <test/setup_common.h>
#include <vector>

View File

@ -5,7 +5,7 @@
#include <random.h>
#include <streams.h>
#include <support/allocators/zeroafterfree.h>
#include <test/test_dash.h>
#include <test/setup_common.h>
#include <boost/test/unit_test.hpp>

View File

@ -5,7 +5,7 @@
#include <chainparams.h>
#include <validation.h>
#include <test/test_dash.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 <sync.h>
#include <test/test_dash.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 <timedata.h>
#include <test/test_dash.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_dash.h>
#include <test/setup_common.h>
#include <torcontrol.h>
#include <boost/test/unit_test.hpp>

View File

@ -4,7 +4,7 @@
#include <test/data/tx_invalid.json.h>
#include <test/data/tx_valid.json.h>
#include <test/test_dash.h>
#include <test/setup_common.h>
#include <clientversion.h>
#include <checkqueue.h>

View File

@ -5,7 +5,7 @@
#include <chainparams.h>
#include <index/txindex.h>
#include <script/standard.h>
#include <test/test_dash.h>
#include <test/setup_common.h>
#include <util/system.h>
#include <util/time.h>
#include <validation.h>

View File

@ -8,7 +8,7 @@
#include <consensus/validation.h>
#include <primitives/transaction.h>
#include <script/script.h>
#include <test/test_dash.h>
#include <test/setup_common.h>
#include <boost/test/unit_test.hpp>

View File

@ -11,7 +11,7 @@
#include <random.h>
#include <script/standard.h>
#include <script/sign.h>
#include <test/test_dash.h>
#include <test/setup_common.h>
#include <util/time.h>
#include <core_io.h>
#include <keystore.h>

View File

@ -4,7 +4,7 @@
#include <arith_uint256.h>
#include <uint256.h>
#include <version.h>
#include <test/test_dash.h>
#include <test/setup_common.h>
#include <boost/test/unit_test.hpp>
#include <stdint.h>

85
src/test/util.cpp Normal file
View File

@ -0,0 +1,85 @@
// 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 <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)
{
CPubKey new_key;
if (!w.GetKeyFromPool(new_key, false)) assert(false);
CKeyID keyID = new_key.GetID();
w.SetAddressBook(keyID, /* label */ "", "receive");
return EncodeDestination(keyID);
}
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

@ -11,7 +11,7 @@
#include <util/strencodings.h>
#include <util/string.h>
#include <util/moneystr.h>
#include <test/test_dash.h>
#include <test/setup_common.h>
#include <util/vector.h>
#include <stdint.h>

View File

@ -3,7 +3,7 @@
// file COPYING or http://www.opensource.org/licenses/mit-license.php.
#include <util/threadnames.h>
#include <test/test_dash.h>
#include <test/setup_common.h>
#include <thread>
#include <vector>

View File

@ -10,7 +10,7 @@
#include <miner.h>
#include <pow.h>
#include <random.h>
#include <test/test_dash.h>
#include <test/setup_common.h>
#include <validation.h>
#include <validationinterface.h>

View File

@ -3,7 +3,7 @@
// file COPYING or http://www.opensource.org/licenses/mit-license.php.
//
#include <sync.h>
#include <test/test_dash.h>
#include <test/setup_common.h>
#include <txmempool.h>
#include <validation.h>

View File

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

View File

@ -4,7 +4,7 @@
#include <chain.h>
#include <versionbits.h>
#include <test/test_dash.h>
#include <test/setup_common.h>
#include <chainparams.h>
#include <validation.h>
#include <consensus/params.h>

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_dash.h>
#include <test/setup_common.h>
#include <amount.h>
#include <coinjoin/util.h>

Some files were not shown because too many files have changed in this diff Show More