test: Introduce MockableSteadyClock::mock_time_point and ElapseSteady helper

This refactor clarifies that the MockableSteadyClock::mock_time_point
has millisecond precision by defining a type an using it.

Moreover, a ElapseSteady helper is added which can be re-used easily.
This commit is contained in:
MarcoFalke
2025-03-28 10:06:25 +01:00
parent faf2d512c5
commit fa9c38794e
5 changed files with 34 additions and 4 deletions

View File

@@ -15,6 +15,7 @@ add_library(test_util STATIC EXCLUDE_FROM_ALL
script.cpp
setup_common.cpp
str.cpp
time.cpp
transaction_utils.cpp
txmempool.cpp
validation.cpp

5
src/test/util/time.cpp Normal file
View File

@@ -0,0 +1,5 @@
// Copyright (c) The Bitcoin Core developers
// Distributed under the MIT software license, see the accompanying
// file COPYING or http://www.opensource.org/licenses/mit-license.php.
#include <test/util/time.h>

23
src/test/util/time.h Normal file
View File

@@ -0,0 +1,23 @@
// Copyright (c) The Bitcoin Core developers
// Distributed under the MIT software license, see the accompanying
// file COPYING or http://www.opensource.org/licenses/mit-license.php.
#ifndef BITCOIN_TEST_UTIL_TIME_H
#define BITCOIN_TEST_UTIL_TIME_H
#include <util/time.h>
struct ElapseSteady {
MockableSteadyClock::mock_time_point::duration t{MockableSteadyClock::INITIAL_MOCK_TIME};
ElapseSteady()
{
(*this)(0s); // init
}
void operator()(std::chrono::milliseconds d)
{
t += d;
MockableSteadyClock::SetMockTime(t);
}
};
#endif // BITCOIN_TEST_UTIL_TIME_H