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:
7 files changed
+9
-3
No files matched your search
+3
-1
@@ -1052,7 +1052,9 @@ bool AppInitParameterInteraction(const ArgsManager& args)
|
|||||||
if (!g_wallet_init_interface.ParameterInteraction()) return false;
|
if (!g_wallet_init_interface.ParameterInteraction()) return false;
|
||||||
|
|
||||||
// Option to startup with mocktime set (used for regression testing):
|
// 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))
|
if (args.GetBoolArg("-peerbloomfilters", DEFAULT_PEERBLOOMFILTERS))
|
||||||
g_local_services = ServiceFlags(g_local_services | NODE_BLOOM);
|
g_local_services = ServiceFlags(g_local_services | NODE_BLOOM);
|
||||||
|
|||||||
@@ -42,6 +42,7 @@ void initialize_tx_pool()
|
|||||||
{
|
{
|
||||||
static const auto testing_setup = MakeNoLogFileContext<const TestingSetup>();
|
static const auto testing_setup = MakeNoLogFileContext<const TestingSetup>();
|
||||||
g_setup = testing_setup.get();
|
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;
|
BlockAssembler::Options options;
|
||||||
options.coinbase_output_script = P2WSH_EMPTY;
|
options.coinbase_output_script = P2WSH_EMPTY;
|
||||||
|
|||||||
@@ -44,6 +44,7 @@ void initialize_process_message()
|
|||||||
/*chain_type=*/ChainType::REGTEST,
|
/*chain_type=*/ChainType::REGTEST,
|
||||||
{.extra_args = {"-txreconciliation"}});
|
{.extra_args = {"-txreconciliation"}});
|
||||||
g_setup = testing_setup.get();
|
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++) {
|
for (int i = 0; i < 2 * COINBASE_MATURITY; i++) {
|
||||||
MineBlock(g_setup->m_node, {});
|
MineBlock(g_setup->m_node, {});
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -34,6 +34,7 @@ void initialize_process_messages()
|
|||||||
/*chain_type=*/ChainType::REGTEST,
|
/*chain_type=*/ChainType::REGTEST,
|
||||||
{.extra_args = {"-txreconciliation"}});
|
{.extra_args = {"-txreconciliation"}});
|
||||||
g_setup = testing_setup.get();
|
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++) {
|
for (int i = 0; i < 2 * COINBASE_MATURITY; i++) {
|
||||||
MineBlock(g_setup->m_node, {});
|
MineBlock(g_setup->m_node, {});
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -44,6 +44,7 @@ void initialize_tx_pool()
|
|||||||
{
|
{
|
||||||
static const auto testing_setup = MakeNoLogFileContext<const TestingSetup>();
|
static const auto testing_setup = MakeNoLogFileContext<const TestingSetup>();
|
||||||
g_setup = testing_setup.get();
|
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;
|
BlockAssembler::Options options;
|
||||||
options.coinbase_output_script = P2WSH_OP_TRUE;
|
options.coinbase_output_script = P2WSH_OP_TRUE;
|
||||||
|
|||||||
@@ -72,6 +72,7 @@ void initialize_chain()
|
|||||||
const auto params{CreateChainParams(ArgsManager{}, ChainType::REGTEST)};
|
const auto params{CreateChainParams(ArgsManager{}, ChainType::REGTEST)};
|
||||||
static const auto chain{CreateBlockChain(2 * COINBASE_MATURITY, *params)};
|
static const auto chain{CreateBlockChain(2 * COINBASE_MATURITY, *params)};
|
||||||
g_chain = &chain;
|
g_chain = &chain;
|
||||||
|
SetMockTime(chain.back()->Time());
|
||||||
|
|
||||||
// Make sure we can generate a valid snapshot.
|
// Make sure we can generate a valid snapshot.
|
||||||
sanity_check_snapshot();
|
sanity_check_snapshot();
|
||||||
|
|||||||
@@ -24,14 +24,13 @@ FUZZ_TARGET(utxo_total_supply)
|
|||||||
{
|
{
|
||||||
SeedRandomStateForTest(SeedRand::ZEROS);
|
SeedRandomStateForTest(SeedRand::ZEROS);
|
||||||
FuzzedDataProvider fuzzed_data_provider(buffer.data(), buffer.size());
|
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) */
|
/** The testing setup that creates a chainman only (no chainstate) */
|
||||||
ChainTestingSetup test_setup{
|
ChainTestingSetup test_setup{
|
||||||
ChainType::REGTEST,
|
ChainType::REGTEST,
|
||||||
{
|
{
|
||||||
.extra_args = {
|
.extra_args = {
|
||||||
"-testactivationheight=bip34@2",
|
"-testactivationheight=bip34@2",
|
||||||
strprintf("-mocktime=%d", mock_time).c_str()
|
|
||||||
},
|
},
|
||||||
},
|
},
|
||||||
};
|
};
|
||||||
|
|||||||
Reference in new issue
Block a user