mirror of
https://github.com/bitcoin/bitcoin.git
synced 2026-04-27 07:18:33 +02:00
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:
@@ -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
5
src/test/util/time.cpp
Normal 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
23
src/test/util/time.h
Normal 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
|
||||
Reference in New Issue
Block a user