Skip to content

Commit fa26bfd

Browse files
author
MarcoFalke
committed
test: Avoid resetting mocktime in testing setup
This allows to set the mocktime before the testing setup. Also, in some fuzz tests the mocktime was reset to 0 before this change, so set it.
1 parent fa6b45f commit fa26bfd

File tree

7 files changed

+9
-3
lines changed

7 files changed

+9
-3
lines changed

src/init.cpp

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1052,7 +1052,9 @@ bool AppInitParameterInteraction(const ArgsManager& args)
10521052
if (!g_wallet_init_interface.ParameterInteraction()) return false;
10531053

10541054
// Option to startup with mocktime set (used for regression testing):
1055-
SetMockTime(args.GetIntArg("-mocktime", 0)); // SetMockTime(0) is a no-op
1055+
if (const auto mocktime{args.GetIntArg("-mocktime")}) {
1056+
SetMockTime(std::chrono::seconds{*mocktime});
1057+
}
10561058

10571059
if (args.GetBoolArg("-peerbloomfilters", DEFAULT_PEERBLOOMFILTERS))
10581060
g_local_services = ServiceFlags(g_local_services | NODE_BLOOM);

src/test/fuzz/package_eval.cpp

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -42,6 +42,7 @@ void initialize_tx_pool()
4242
{
4343
static const auto testing_setup = MakeNoLogFileContext<const TestingSetup>();
4444
g_setup = testing_setup.get();
45+
SetMockTime(WITH_LOCK(g_setup->m_node.chainman->GetMutex(), return g_setup->m_node.chainman->ActiveTip()->Time()));
4546

4647
BlockAssembler::Options options;
4748
options.coinbase_output_script = P2WSH_EMPTY;

src/test/fuzz/process_message.cpp

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -44,6 +44,7 @@ void initialize_process_message()
4444
/*chain_type=*/ChainType::REGTEST,
4545
{.extra_args = {"-txreconciliation"}});
4646
g_setup = testing_setup.get();
47+
SetMockTime(WITH_LOCK(g_setup->m_node.chainman->GetMutex(), return g_setup->m_node.chainman->ActiveTip()->Time()));
4748
for (int i = 0; i < 2 * COINBASE_MATURITY; i++) {
4849
MineBlock(g_setup->m_node, {});
4950
}

src/test/fuzz/process_messages.cpp

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -34,6 +34,7 @@ void initialize_process_messages()
3434
/*chain_type=*/ChainType::REGTEST,
3535
{.extra_args = {"-txreconciliation"}});
3636
g_setup = testing_setup.get();
37+
SetMockTime(WITH_LOCK(g_setup->m_node.chainman->GetMutex(), return g_setup->m_node.chainman->ActiveTip()->Time()));
3738
for (int i = 0; i < 2 * COINBASE_MATURITY; i++) {
3839
MineBlock(g_setup->m_node, {});
3940
}

src/test/fuzz/tx_pool.cpp

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -44,6 +44,7 @@ void initialize_tx_pool()
4444
{
4545
static const auto testing_setup = MakeNoLogFileContext<const TestingSetup>();
4646
g_setup = testing_setup.get();
47+
SetMockTime(WITH_LOCK(g_setup->m_node.chainman->GetMutex(), return g_setup->m_node.chainman->ActiveTip()->Time()));
4748

4849
BlockAssembler::Options options;
4950
options.coinbase_output_script = P2WSH_OP_TRUE;

src/test/fuzz/utxo_snapshot.cpp

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -72,6 +72,7 @@ void initialize_chain()
7272
const auto params{CreateChainParams(ArgsManager{}, ChainType::REGTEST)};
7373
static const auto chain{CreateBlockChain(2 * COINBASE_MATURITY, *params)};
7474
g_chain = &chain;
75+
SetMockTime(chain.back()->Time());
7576

7677
// Make sure we can generate a valid snapshot.
7778
sanity_check_snapshot();

src/test/fuzz/utxo_total_supply.cpp

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -24,14 +24,13 @@ FUZZ_TARGET(utxo_total_supply)
2424
{
2525
SeedRandomStateForTest(SeedRand::ZEROS);
2626
FuzzedDataProvider fuzzed_data_provider(buffer.data(), buffer.size());
27-
const auto mock_time{ConsumeTime(fuzzed_data_provider, /*min=*/1296688602)}; // regtest genesis block timestamp
27+
SetMockTime(ConsumeTime(fuzzed_data_provider, /*min=*/1296688602)); // regtest genesis block timestamp
2828
/** The testing setup that creates a chainman only (no chainstate) */
2929
ChainTestingSetup test_setup{
3030
ChainType::REGTEST,
3131
{
3232
.extra_args = {
3333
"-testactivationheight=bip34@2",
34-
strprintf("-mocktime=%d", mock_time).c_str()
3534
},
3635
},
3736
};

0 commit comments

Comments
 (0)