Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion src/bench/logging.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@ static void Logging(benchmark::Bench& bench, const std::vector<const char*>& ext

TestingSetup test_setup{
ChainType::REGTEST,
extra_args,
{.extra_args = extra_args},
};

bench.run([&] { log(); });
Expand Down
2 changes: 1 addition & 1 deletion src/bench/mempool_stress.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -106,7 +106,7 @@ static void ComplexMemPool(benchmark::Bench& bench)
static void MempoolCheck(benchmark::Bench& bench)
{
FastRandomContext det_rand{true};
auto testing_setup = MakeNoLogFileContext<TestChain100Setup>(ChainType::REGTEST, {"-checkmempool=1"});
auto testing_setup = MakeNoLogFileContext<TestChain100Setup>(ChainType::REGTEST, {.extra_args = {"-checkmempool=1"}});
CTxMemPool& pool = *testing_setup.get()->m_node.mempool;
LOCK2(cs_main, pool.cs);
testing_setup->PopulateMempool(det_rand, 400, true);
Expand Down
2 changes: 1 addition & 1 deletion src/test/checkqueue_tests.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,7 @@
struct NoLockLoggingTestingSetup : public TestingSetup {
NoLockLoggingTestingSetup()
#ifdef DEBUG_LOCKCONTENTION
: TestingSetup{ChainType::MAIN, /*extra_args=*/{"-debugexclude=lock"}} {}
: TestingSetup{ChainType::MAIN, {.extra_args = { "-debugexclude=lock" } }} {}
#else
: TestingSetup{ChainType::MAIN} {}
#endif
Expand Down
2 changes: 1 addition & 1 deletion src/test/fuzz/process_message.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -42,7 +42,7 @@ void initialize_process_message()

static const auto testing_setup = MakeNoLogFileContext<const TestingSetup>(
/*chain_type=*/ChainType::REGTEST,
/*extra_args=*/{"-txreconciliation"});
{.extra_args = {"-txreconciliation"}});
g_setup = testing_setup.get();
for (int i = 0; i < 2 * COINBASE_MATURITY; i++) {
MineBlock(g_setup->m_node, CScript() << OP_TRUE);
Expand Down
2 changes: 1 addition & 1 deletion src/test/fuzz/process_messages.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,7 @@ void initialize_process_messages()
{
static const auto testing_setup = MakeNoLogFileContext<const TestingSetup>(
/*chain_type=*/ChainType::REGTEST,
/*extra_args=*/{"-txreconciliation"});
{.extra_args = {"-txreconciliation"}});
g_setup = testing_setup.get();
for (int i = 0; i < 2 * COINBASE_MATURITY; i++) {
MineBlock(g_setup->m_node, CScript() << OP_TRUE);
Expand Down
2 changes: 1 addition & 1 deletion src/test/fuzz/rpc.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -41,7 +41,7 @@ using util::ToString;

namespace {
struct RPCFuzzTestingSetup : public TestingSetup {
RPCFuzzTestingSetup(const ChainType chain_type, const std::vector<const char*>& extra_args) : TestingSetup{chain_type, extra_args}
RPCFuzzTestingSetup(const ChainType chain_type, TestOpts opts) : TestingSetup{chain_type, opts}
{
}

Expand Down
2 changes: 1 addition & 1 deletion src/test/fuzz/utxo_total_supply.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@ FUZZ_TARGET(utxo_total_supply)
ChainTestingSetup test_setup{
ChainType::REGTEST,
{
"-testactivationheight=bip34@2",
.extra_args = {"-testactivationheight=bip34@2"},
},
};
// Create chainstate
Expand Down
4 changes: 2 additions & 2 deletions src/test/i2p_tests.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -23,8 +23,8 @@ class EnvTestingSetup : public BasicTestingSetup
{
public:
explicit EnvTestingSetup(const ChainType chainType = ChainType::MAIN,
const std::vector<const char*>& extra_args = {})
: BasicTestingSetup{chainType, extra_args},
TestOpts opts = {})
: BasicTestingSetup{chainType, opts},
m_prev_log_level{LogInstance().LogLevel()},
m_create_sock_orig{CreateSock}
{
Expand Down
2 changes: 1 addition & 1 deletion src/test/net_peer_connection_tests.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,7 @@

struct LogIPsTestingSetup : public TestingSetup {
LogIPsTestingSetup()
: TestingSetup{ChainType::MAIN, /*extra_args=*/{"-logips"}} {}
: TestingSetup{ChainType::MAIN, {.extra_args = {"-logips"}}} {}
};

BOOST_FIXTURE_TEST_SUITE(net_peer_connection_tests, LogIPsTestingSetup)
Expand Down
2 changes: 1 addition & 1 deletion src/test/txvalidationcache_tests.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@

struct Dersig100Setup : public TestChain100Setup {
Dersig100Setup()
: TestChain100Setup{ChainType::REGTEST, {"-testactivationheight=dersig@102"}} {}
: TestChain100Setup{ChainType::REGTEST, {.extra_args = {"-testactivationheight=dersig@102"}}} {}
};

bool CheckInputScripts(const CTransaction& tx, TxValidationState& state,
Expand Down
26 changes: 11 additions & 15 deletions src/test/util/setup_common.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -112,7 +112,7 @@ static void ExitFailure(std::string_view str_err)
exit(EXIT_FAILURE);
}

BasicTestingSetup::BasicTestingSetup(const ChainType chainType, const std::vector<const char*>& extra_args)
BasicTestingSetup::BasicTestingSetup(const ChainType chainType, TestOpts opts)
: m_args{}
{
m_node.shutdown = &m_interrupt;
Expand All @@ -129,7 +129,7 @@ BasicTestingSetup::BasicTestingSetup(const ChainType chainType, const std::vecto
"-debugexclude=libevent",
"-debugexclude=leveldb",
},
extra_args);
opts.extra_args);
if (G_TEST_COMMAND_LINE_ARGUMENTS) {
arguments = Cat(arguments, G_TEST_COMMAND_LINE_ARGUMENTS());
}
Expand Down Expand Up @@ -220,8 +220,8 @@ BasicTestingSetup::~BasicTestingSetup()
gArgs.ClearArgs();
}

ChainTestingSetup::ChainTestingSetup(const ChainType chainType, const std::vector<const char*>& extra_args)
: BasicTestingSetup(chainType, extra_args)
ChainTestingSetup::ChainTestingSetup(const ChainType chainType, TestOpts opts)
: BasicTestingSetup(chainType, opts)
{
const CChainParams& chainparams = Params();

Expand Down Expand Up @@ -304,13 +304,11 @@ void ChainTestingSetup::LoadVerifyActivateChainstate()

TestingSetup::TestingSetup(
const ChainType chainType,
const std::vector<const char*>& extra_args,
const bool coins_db_in_memory,
const bool block_tree_db_in_memory)
: ChainTestingSetup(chainType, extra_args)
TestOpts opts)
: ChainTestingSetup(chainType, opts)
{
m_coins_db_in_memory = coins_db_in_memory;
m_block_tree_db_in_memory = block_tree_db_in_memory;
m_coins_db_in_memory = opts.coins_db_in_memory;
m_block_tree_db_in_memory = opts.block_tree_db_in_memory;
// Ideally we'd move all the RPC tests to the functional testing framework
// instead of unit tests, but for now we need these here.
RegisterAllCoreRPCCommands(tableRPC);
Expand Down Expand Up @@ -339,11 +337,9 @@ TestingSetup::TestingSetup(
}

TestChain100Setup::TestChain100Setup(
const ChainType chain_type,
const std::vector<const char*>& extra_args,
const bool coins_db_in_memory,
const bool block_tree_db_in_memory)
: TestingSetup{ChainType::REGTEST, extra_args, coins_db_in_memory, block_tree_db_in_memory}
const ChainType chain_type,
TestOpts opts)
: TestingSetup{ChainType::REGTEST, opts}
{
SetMockTime(1598887952);
constexpr std::array<unsigned char, 32> vchKey = {
Expand Down
26 changes: 14 additions & 12 deletions src/test/util/setup_common.h
Original file line number Diff line number Diff line change
Expand Up @@ -48,14 +48,20 @@ std::ostream& operator<<(typename std::enable_if<std::is_enum<T>::value, std::os

static constexpr CAmount CENT{1000000};

struct TestOpts {
std::vector<const char*> extra_args{};
bool coins_db_in_memory{true};
bool block_tree_db_in_memory{true};
};

/** Basic testing setup.
* This just configures logging, data dir and chain parameters.
*/
struct BasicTestingSetup {
util::SignalInterrupt m_interrupt;
node::NodeContext m_node; // keep as first member to be destructed last

explicit BasicTestingSetup(const ChainType chainType = ChainType::MAIN, const std::vector<const char*>& extra_args = {});
explicit BasicTestingSetup(const ChainType chainType = ChainType::MAIN, TestOpts = {});
~BasicTestingSetup();

fs::path m_path_root;
Expand All @@ -73,7 +79,7 @@ struct ChainTestingSetup : public BasicTestingSetup {
bool m_coins_db_in_memory{true};
bool m_block_tree_db_in_memory{true};

explicit ChainTestingSetup(const ChainType chainType = ChainType::MAIN, const std::vector<const char*>& extra_args = {});
explicit ChainTestingSetup(const ChainType chainType = ChainType::MAIN, TestOpts = {});
~ChainTestingSetup();

// Supplies a chainstate, if one is needed
Expand All @@ -85,9 +91,7 @@ struct ChainTestingSetup : public BasicTestingSetup {
struct TestingSetup : public ChainTestingSetup {
explicit TestingSetup(
const ChainType chainType = ChainType::MAIN,
const std::vector<const char*>& extra_args = {},
const bool coins_db_in_memory = true,
const bool block_tree_db_in_memory = true);
TestOpts = {});
};

/** Identical to TestingSetup, but chain set to regtest */
Expand All @@ -106,9 +110,7 @@ class CScript;
struct TestChain100Setup : public TestingSetup {
TestChain100Setup(
const ChainType chain_type = ChainType::REGTEST,
const std::vector<const char*>& extra_args = {},
const bool coins_db_in_memory = true,
const bool block_tree_db_in_memory = true);
TestOpts = {});

/**
* Create a new block with just given transactions, coinbase paying to
Expand Down Expand Up @@ -220,16 +222,16 @@ struct TestChain100Setup : public TestingSetup {
* be used in "hot loops", for example fuzzing or benchmarking.
*/
template <class T = const BasicTestingSetup>
std::unique_ptr<T> MakeNoLogFileContext(const ChainType chain_type = ChainType::REGTEST, const std::vector<const char*>& extra_args = {})
std::unique_ptr<T> MakeNoLogFileContext(const ChainType chain_type = ChainType::REGTEST, TestOpts opts = {})
{
const std::vector<const char*> arguments = Cat(
opts.extra_args = Cat(
{
"-nodebuglogfile",
"-nodebug",
},
extra_args);
opts.extra_args);

return std::make_unique<T>(chain_type, arguments);
return std::make_unique<T>(chain_type, opts);
}

CBlock getBlock13b8a();
Expand Down
7 changes: 4 additions & 3 deletions src/test/validation_chainstatemanager_tests.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -167,9 +167,10 @@ struct SnapshotTestSetup : TestChain100Setup {
// destructive filesystem operations.
SnapshotTestSetup() : TestChain100Setup{
{},
{},
/*coins_db_in_memory=*/false,
/*block_tree_db_in_memory=*/false,
{
.coins_db_in_memory = false,
.block_tree_db_in_memory = false,
},
}
{
}
Expand Down