test: Use SteadyClockContext in pcp_tests
What changed, and why it matters
This is a small internal cleanup of a test file. It swaps a hand-rolled mock clock helper for a standard test utility called SteadyClockContext. There is no change to the actual Bitcoin network code, no bug fix, and no security-relevant behavior change.
No action needed. This is a non-security test refactor.
Security signals we found
No strong security signals were identified.
Evidence from the diff
The commit refactors src/test/pcp_tests.cpp to use SteadyClockContext instead of manually managing MockableSteadyClock::INITIAL_MOCK_TIME and a private ElapseTime() method. The test class’s m_time member is replaced by SteadyClockContext m_clock, and calls to ElapseTime() become direct operator+=() calls on m_clock. This only affects unit-test infrastructure for PCP (Port Control Protocol) mapping logic.
Changed components
src/test/pcp_tests.cppInspect captured patch +3 / −10
diff --git a/src/test/pcp_tests.cpp b/src/test/pcp_tests.cpp
index 51b004a5..8ecbab58 100644
--- a/src/test/pcp_tests.cpp
+++ b/src/test/pcp_tests.cpp
@@ -92,7 +92,6 @@ public:
m_local_ip(local_ip),
m_gateway_ip(gateway_ip)
{
- ElapseTime(std::chrono::seconds(0)); // start mocking steady time
PrepareOp();
}
@@ -193,10 +192,10 @@ public:
{
// Only handles receive events.
if (AtEndOfScript() || requested != Sock::RECV) {
- ElapseTime(timeout);
+ m_clock += timeout;
} else {
std::chrono::milliseconds delay = std::min(m_time_left, timeout);
- ElapseTime(delay);
+ m_clock += delay;
m_time_left -= delay;
if (CurOp().op == TestOp::RECV && m_time_left == 0s && occurred != nullptr) {
*occurred = Sock::RECV;
@@ -223,18 +222,12 @@ private:
const std::vector<TestOp> m_script;
mutable size_t m_script_ptr = 0;
mutable std::chrono::milliseconds m_time_left;
- mutable std::chrono::milliseconds m_time{MockableSteadyClock::INITIAL_MOCK_TIME};
+ mutable SteadyClockContext m_clock{};
mutable bool m_connected{false};
mutable CService m_bound;
mutable CNetAddr m_local_ip;
mutable CNetAddr m_gateway_ip;
- void ElapseTime(std::chrono::milliseconds duration) const
- {
- m_time += duration;
- MockableSteadyClock::SetMockTime(m_time);
- }
-
bool AtEndOfScript() const { return m_script_ptr == m_script.size(); }
const TestOp &CurOp() const {
BOOST_REQUIRE(m_script_ptr < m_script.size());
Why this scored 15/100
Community notes
Notes can correct, qualify, or add evidence to the AI analysis. Every note shown here has been validated by a human moderator.
The AI analysis stands alone for now. Submit a note if you can add evidence or important context.