mirror of
https://github.com/bitcoin/bitcoin.git
synced 2026-09-12 05:32:22 +02:00
test: Use NodeClockContext in more call sites
This refactor is a follow-up to commit
faad08e59c and does not
change any behavior.
These call sites are clean mechanical swaps. The remaining ones
require non-trivial test refactoring and are left for future
follow-ups.
This commit is contained in:
@@ -16,6 +16,7 @@
|
||||
#include <span.h>
|
||||
#include <sync.h>
|
||||
#include <test/util/setup_common.h>
|
||||
#include <test/util/time.h>
|
||||
#include <uint256.h>
|
||||
#include <util/strencodings.h>
|
||||
#include <util/time.h>
|
||||
@@ -37,9 +38,10 @@ static void BlockFilterIndexSync(benchmark::Bench& bench)
|
||||
CPubKey pubkey{"02ed26169896db86ced4cbb7b3ecef9859b5952825adbeab998fb5b307e54949c9"_hex_u8};
|
||||
CScript script = GetScriptForDestination(WitnessV0KeyHash(pubkey));
|
||||
std::vector<CMutableTransaction> noTxns;
|
||||
NodeClockContext clock_ctx{};
|
||||
for (int i = 0; i < CHAIN_SIZE - 100; i++) {
|
||||
test_setup->CreateAndProcessBlock(noTxns, script);
|
||||
SetMockTime(GetTime() + 1);
|
||||
clock_ctx += 1s;
|
||||
}
|
||||
assert(WITH_LOCK(::cs_main, return test_setup->m_node.chainman->ActiveHeight() == CHAIN_SIZE));
|
||||
|
||||
|
||||
@@ -8,6 +8,7 @@
|
||||
#include <random.h>
|
||||
#include <support/allocators/secure.h>
|
||||
#include <test/util/setup_common.h>
|
||||
#include <test/util/time.h>
|
||||
#include <util/time.h>
|
||||
#include <wallet/context.h>
|
||||
#include <wallet/test/util.h>
|
||||
@@ -44,7 +45,7 @@ static void WalletEncrypt(benchmark::Bench& bench, unsigned int key_count)
|
||||
|
||||
// Setting a mock time is necessary to force default derive iteration count during
|
||||
// wallet encryption.
|
||||
SetMockTime(1);
|
||||
NodeClockContext clock_ctx{1s};
|
||||
|
||||
std::unique_ptr<WalletDatabase> database;
|
||||
std::shared_ptr<CWallet> wallet;
|
||||
|
||||
@@ -97,8 +97,7 @@ BOOST_AUTO_TEST_CASE(addrman_simple)
|
||||
|
||||
BOOST_AUTO_TEST_CASE(addrman_terrible_many_failures)
|
||||
{
|
||||
auto now = Now<NodeSeconds>();
|
||||
SetMockTime(now - (ADDRMAN_MIN_FAIL + 24h));
|
||||
NodeClockContext clock_ctx{};
|
||||
|
||||
auto addrman{std::make_unique<AddrMan>(EMPTY_NETGROUPMAN, DETERMINISTIC, GetCheckRatio(m_node))};
|
||||
|
||||
@@ -109,7 +108,7 @@ BOOST_AUTO_TEST_CASE(addrman_terrible_many_failures)
|
||||
BOOST_CHECK(addrman->Add({addr}, source));
|
||||
BOOST_CHECK(addrman->Good(addr));
|
||||
|
||||
SetMockTime(now);
|
||||
clock_ctx += ADDRMAN_MIN_FAIL + 24h;
|
||||
|
||||
CAddress addr_helper{CAddress(ResolveService("251.252.2.3", 8333), NODE_NONE)};
|
||||
addr_helper.nTime = Now<NodeSeconds>();
|
||||
@@ -132,7 +131,7 @@ BOOST_AUTO_TEST_CASE(addrman_terrible_many_failures)
|
||||
|
||||
BOOST_AUTO_TEST_CASE(addrman_penalty_self_announcement)
|
||||
{
|
||||
SetMockTime(Now<NodeSeconds>());
|
||||
NodeClockContext clock_ctx{};
|
||||
auto addrman = std::make_unique<AddrMan>(EMPTY_NETGROUPMAN, DETERMINISTIC, GetCheckRatio(m_node));
|
||||
|
||||
const auto base_time{Now<NodeSeconds>() - 10000s};
|
||||
|
||||
@@ -70,6 +70,7 @@ BOOST_FIXTURE_TEST_CASE(write_during_multiblock_activation, TestChain100Setup)
|
||||
|
||||
auto& chainstate{Assert(m_node.chainman)->ActiveChainstate()};
|
||||
BlockValidationState state_dummy{};
|
||||
NodeClockContext clock_ctx{};
|
||||
|
||||
// Pop two blocks from the tip
|
||||
const CBlockIndex* tip{chainstate.m_chain.Tip()};
|
||||
@@ -88,7 +89,7 @@ BOOST_FIXTURE_TEST_CASE(write_during_multiblock_activation, TestChain100Setup)
|
||||
m_node.validation_signals->SyncWithValidationInterfaceQueue();
|
||||
// The periodic flush interval is between 50 and 70 minutes (inclusive)
|
||||
// The next call to a PERIODIC write will flush
|
||||
SetMockTime(GetMockTime() + DATABASE_WRITE_INTERVAL_MAX);
|
||||
clock_ctx += DATABASE_WRITE_INTERVAL_MAX;
|
||||
|
||||
const auto sub{std::make_shared<TestSubscriber>()};
|
||||
m_node.validation_signals->RegisterSharedValidationInterface(sub);
|
||||
|
||||
@@ -5,6 +5,7 @@
|
||||
#include <primitives/transaction.h>
|
||||
#include <private_broadcast.h>
|
||||
#include <test/util/setup_common.h>
|
||||
#include <test/util/time.h>
|
||||
#include <util/time.h>
|
||||
|
||||
#include <algorithm>
|
||||
@@ -26,7 +27,7 @@ static CTransactionRef MakeDummyTx(uint32_t id, size_t num_witness)
|
||||
|
||||
BOOST_AUTO_TEST_CASE(basic)
|
||||
{
|
||||
SetMockTime(Now<NodeSeconds>());
|
||||
NodeClockContext clock_ctx{};
|
||||
|
||||
PrivateBroadcast pb;
|
||||
const NodeId recipient1{1};
|
||||
@@ -94,7 +95,7 @@ BOOST_AUTO_TEST_CASE(basic)
|
||||
BOOST_CHECK_EQUAL(pb.GetStale().size(), 0);
|
||||
|
||||
// 2. Fast-forward the mock clock past the INITIAL_STALE_DURATION.
|
||||
SetMockTime(Now<NodeSeconds>() + PrivateBroadcast::INITIAL_STALE_DURATION + 1min);
|
||||
clock_ctx += PrivateBroadcast::INITIAL_STALE_DURATION + 1min;
|
||||
|
||||
// 3. Now that the initial duration has passed, both unconfirmed transactions should be stale.
|
||||
BOOST_CHECK_EQUAL(pb.GetStale().size(), 2);
|
||||
@@ -125,7 +126,7 @@ BOOST_AUTO_TEST_CASE(basic)
|
||||
BOOST_CHECK_EQUAL(stale_state.size(), 1);
|
||||
BOOST_CHECK_EQUAL(stale_state[0], tx_for_recipient2);
|
||||
|
||||
SetMockTime(Now<NodeSeconds>() + 10h);
|
||||
clock_ctx += 10h;
|
||||
|
||||
BOOST_CHECK_EQUAL(pb.GetStale().size(), 2);
|
||||
|
||||
@@ -141,7 +142,7 @@ BOOST_AUTO_TEST_CASE(basic)
|
||||
|
||||
BOOST_AUTO_TEST_CASE(stale_unpicked_tx)
|
||||
{
|
||||
SetMockTime(Now<NodeSeconds>());
|
||||
NodeClockContext clock_ctx{};
|
||||
|
||||
PrivateBroadcast pb;
|
||||
const auto tx{MakeDummyTx(/*id=*/42, /*num_witness=*/0)};
|
||||
@@ -149,9 +150,9 @@ BOOST_AUTO_TEST_CASE(stale_unpicked_tx)
|
||||
|
||||
// Unpicked transactions use the longer INITIAL_STALE_DURATION.
|
||||
BOOST_CHECK_EQUAL(pb.GetStale().size(), 0);
|
||||
SetMockTime(Now<NodeSeconds>() + PrivateBroadcast::INITIAL_STALE_DURATION - 1min);
|
||||
clock_ctx += PrivateBroadcast::INITIAL_STALE_DURATION - 1min;
|
||||
BOOST_CHECK_EQUAL(pb.GetStale().size(), 0);
|
||||
SetMockTime(Now<NodeSeconds>() + 2min);
|
||||
clock_ctx += 2min;
|
||||
const auto stale_state{pb.GetStale()};
|
||||
BOOST_REQUIRE_EQUAL(stale_state.size(), 1);
|
||||
BOOST_CHECK_EQUAL(stale_state[0], tx);
|
||||
|
||||
@@ -11,6 +11,7 @@
|
||||
#include <rpc/util.h>
|
||||
#include <test/util/common.h>
|
||||
#include <test/util/setup_common.h>
|
||||
#include <test/util/time.h>
|
||||
#include <univalue.h>
|
||||
#include <util/time.h>
|
||||
|
||||
@@ -341,10 +342,9 @@ BOOST_AUTO_TEST_CASE(rpc_ban)
|
||||
|
||||
BOOST_CHECK_NO_THROW(CallRPC(std::string("clearbanned")));
|
||||
|
||||
auto now = 10'000s;
|
||||
SetMockTime(now);
|
||||
NodeClockContext clock_ctx{10'000s};
|
||||
BOOST_CHECK_NO_THROW(r = CallRPC(std::string("setban 127.0.0.0/24 add 200")));
|
||||
SetMockTime(now += 2s);
|
||||
clock_ctx += 2s;
|
||||
const int64_t time_remaining_expected{198};
|
||||
BOOST_CHECK_NO_THROW(r = CallRPC(std::string("listbanned")));
|
||||
ar = r.get_array();
|
||||
@@ -355,7 +355,7 @@ BOOST_AUTO_TEST_CASE(rpc_ban)
|
||||
const int64_t ban_duration{o1.find_value("ban_duration").getInt<int64_t>()};
|
||||
const int64_t time_remaining{o1.find_value("time_remaining").getInt<int64_t>()};
|
||||
BOOST_CHECK_EQUAL(adr.get_str(), "127.0.0.0/24");
|
||||
BOOST_CHECK_EQUAL(banned_until, time_remaining_expected + now.count());
|
||||
BOOST_CHECK_EQUAL(banned_until, time_remaining_expected + TicksSinceEpoch<std::chrono::seconds>(NodeClock::now()));
|
||||
BOOST_CHECK_EQUAL(ban_duration, banned_until - ban_created);
|
||||
BOOST_CHECK_EQUAL(time_remaining, time_remaining_expected);
|
||||
|
||||
|
||||
Reference in New Issue
Block a user