From 3cb9d9c861710c0cff018bee90b1969193d3ed68 Mon Sep 17 00:00:00 2001 From: Vasil Dimov Date: Thu, 22 Jul 2021 18:23:21 +0200 Subject: net: make CaptureMessage() mockable Rename `CaptureMessage()` to `CaptureMessageToFile()` and introduce a `std::function` variable called `CaptureMessage` whose value can be changed by unit tests, should they need to inspect message contents. --- src/net.h | 13 ++++++++++++- 1 file changed, 12 insertions(+), 1 deletion(-) (limited to 'src/net.h') diff --git a/src/net.h b/src/net.h index bbc253e7ff..23254e6445 100644 --- a/src/net.h +++ b/src/net.h @@ -31,6 +31,7 @@ #include #include #include +#include #include #include #include @@ -1272,7 +1273,17 @@ private: }; /** Dump binary message to file, with timestamp */ -void CaptureMessage(const CAddress& addr, const std::string& msg_type, const Span& data, bool is_incoming); +void CaptureMessageToFile(const CAddress& addr, + const std::string& msg_type, + const Span& data, + bool is_incoming); + +/** Defaults to `CaptureMessageToFile()`, but can be overridden by unit tests. */ +extern std::function& data, + bool is_incoming)> + CaptureMessage; struct NodeEvictionCandidate { -- cgit v1.2.3