Skip to content

Commit 776d370

Browse files
committed
test: default mock time to genesis block
1 parent 5889546 commit 776d370

File tree

2 files changed

+8
-0
lines changed

2 files changed

+8
-0
lines changed

src/test/sv2_test_setup.cpp

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -18,6 +18,9 @@ Sv2BasicTestingSetup::Sv2BasicTestingSetup()
1818
// Select a default chain for tests to satisfy BaseParams() users.
1919
SelectBaseParams(ChainType::REGTEST);
2020

21+
// Default mock time anchored to Bitcoin genesis so certificate helpers see a realistic clock.
22+
SetMockTime(TEST_GENESIS_TIME);
23+
2124
// Create an isolated temporary datadir for this test process.
2225
const auto micros = count_microseconds(Now<SteadyMicroseconds>().time_since_epoch());
2326
const std::string subdir = util::Join(std::array<std::string, 2>{"sv2_tests", util::ToString(micros)}, "");
@@ -37,6 +40,8 @@ Sv2BasicTestingSetup::Sv2BasicTestingSetup()
3740

3841
Sv2BasicTestingSetup::~Sv2BasicTestingSetup()
3942
{
43+
SetMockTime(std::chrono::seconds{0});
44+
4045
try {
4146
fs::remove_all(m_tmp_root);
4247
} catch (const std::exception&) {

src/test/sv2_test_setup.h

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -47,6 +47,9 @@ inline Sv2SignatureNoiseMessage MakeSkewTolerantCertificate(const CKey& static_k
4747
XOnlyPubKey(static_key.GetPubKey()), authority_key);
4848
}
4949

50+
//! Default mock time for SV2 unit tests: Bitcoin genesis block timestamp (2009-01-03).
51+
inline constexpr std::chrono::seconds TEST_GENESIS_TIME{1231006505};
52+
5053

5154
class ECC_Context;
5255

0 commit comments

Comments
 (0)