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.
This commit is contained in:
MarcoFalke
2025-05-07 09:42:32 +02:00
parent fa6b45fa8e
commit fa26bfde98
7 changed files with 9 additions and 3 deletions

View File

@@ -1052,7 +1052,9 @@ bool AppInitParameterInteraction(const ArgsManager& args)
if (!g_wallet_init_interface.ParameterInteraction()) return false;
// Option to startup with mocktime set (used for regression testing):
SetMockTime(args.GetIntArg("-mocktime", 0)); // SetMockTime(0) is a no-op
if (const auto mocktime{args.GetIntArg("-mocktime")}) {
SetMockTime(std::chrono::seconds{*mocktime});
}
if (args.GetBoolArg("-peerbloomfilters", DEFAULT_PEERBLOOMFILTERS))
g_local_services = ServiceFlags(g_local_services | NODE_BLOOM);

View File

@@ -42,6 +42,7 @@ void initialize_tx_pool()
{
static const auto testing_setup = MakeNoLogFileContext<const TestingSetup>();
g_setup = testing_setup.get();
SetMockTime(WITH_LOCK(g_setup->m_node.chainman->GetMutex(), return g_setup->m_node.chainman->ActiveTip()->Time()));
BlockAssembler::Options options;
options.coinbase_output_script = P2WSH_EMPTY;

View File

@@ -44,6 +44,7 @@ void initialize_process_message()
/*chain_type=*/ChainType::REGTEST,
{.extra_args = {"-txreconciliation"}});
g_setup = testing_setup.get();
SetMockTime(WITH_LOCK(g_setup->m_node.chainman->GetMutex(), return g_setup->m_node.chainman->ActiveTip()->Time()));
for (int i = 0; i < 2 * COINBASE_MATURITY; i++) {
MineBlock(g_setup->m_node, {});
}

View File

@@ -34,6 +34,7 @@ void initialize_process_messages()
/*chain_type=*/ChainType::REGTEST,
{.extra_args = {"-txreconciliation"}});
g_setup = testing_setup.get();
SetMockTime(WITH_LOCK(g_setup->m_node.chainman->GetMutex(), return g_setup->m_node.chainman->ActiveTip()->Time()));
for (int i = 0; i < 2 * COINBASE_MATURITY; i++) {
MineBlock(g_setup->m_node, {});
}

View File

@@ -44,6 +44,7 @@ void initialize_tx_pool()
{
static const auto testing_setup = MakeNoLogFileContext<const TestingSetup>();
g_setup = testing_setup.get();
SetMockTime(WITH_LOCK(g_setup->m_node.chainman->GetMutex(), return g_setup->m_node.chainman->ActiveTip()->Time()));
BlockAssembler::Options options;
options.coinbase_output_script = P2WSH_OP_TRUE;

View File

@@ -72,6 +72,7 @@ void initialize_chain()
const auto params{CreateChainParams(ArgsManager{}, ChainType::REGTEST)};
static const auto chain{CreateBlockChain(2 * COINBASE_MATURITY, *params)};
g_chain = &chain;
SetMockTime(chain.back()->Time());
// Make sure we can generate a valid snapshot.
sanity_check_snapshot();

View File

@@ -24,14 +24,13 @@ FUZZ_TARGET(utxo_total_supply)
{
SeedRandomStateForTest(SeedRand::ZEROS);
FuzzedDataProvider fuzzed_data_provider(buffer.data(), buffer.size());
const auto mock_time{ConsumeTime(fuzzed_data_provider, /*min=*/1296688602)}; // regtest genesis block timestamp
SetMockTime(ConsumeTime(fuzzed_data_provider, /*min=*/1296688602)); // regtest genesis block timestamp
/** The testing setup that creates a chainman only (no chainstate) */
ChainTestingSetup test_setup{
ChainType::REGTEST,
{
.extra_args = {
"-testactivationheight=bip34@2",
strprintf("-mocktime=%d", mock_time).c_str()
},
},
};