Inside Bitcoin
Opening the selected file…
Inside Bitcoin
Opening the selected file…
The code behind the network, with room to understand it.
Release published 2026-10-28 · Snapshot fetched 2026-11-01. Latest stable release at fetch time; development branches and Git history are excluded. Only the selected code window and visible folders load here.
1// Copyright (c) The Bitcoin Core developers2// Distributed under the MIT software license, see the accompanying3// file COPYING or https://www.opensource.org/licenses/mit-license.php.5#ifndef BITCOIN_TEST_UTIL_COMMON_H6#define BITCOIN_TEST_UTIL_COMMON_H8#include <chrono>9#include <optional>10#include <ostream>11#include <string>13/**14* BOOST_CHECK_EXCEPTION predicates to check the specific validation error.15* Use as16* BOOST_CHECK_EXCEPTION(code that throws, exception type, HasReason("foo"));17*/18class HasReason19{20public:21explicit HasReason(std::string_view reason) : m_reason(reason) {}22bool operator()(std::string_view s) const { return s.find(m_reason) != std::string_view::npos; }23bool operator()(const std::exception& e) const { return (*this)(e.what()); }25private:26const std::string m_reason;27};29// Make types usable in BOOST_CHECK_* @{30namespace std {31template <typename Clock, typename Duration>32inline std::ostream& operator<<(std::ostream& os, const std::chrono::time_point<Clock, Duration>& tp)33{34return os << tp.time_since_epoch().count();35}37template <typename T> requires std::is_enum_v<T>38inline std::ostream& operator<<(std::ostream& os, const T& e)39{40return os << static_cast<std::underlying_type_t<T>>(e);41}43template <typename T>44inline std::ostream& operator<<(std::ostream& os, const std::optional<T>& v)45{46return v ? os << *v47: os << "std::nullopt";48}49} // namespace std51template <typename T>52concept HasToString = requires(const T& t) { t.ToString(); };54template <HasToString T>55inline std::ostream& operator<<(std::ostream& os, const T& obj)56{57return os << obj.ToString();58}60// @}62#endif // BITCOIN_TEST_UTIL_COMMON_H
Independent explanations by MyBitcoinExplorer. Not affiliated with or endorsed by Bitcoin Core. Guides are educational and do not replace the source or its tests.
Bitcoin Core source © its contributors, distributed under the MIT license. Original notices and bundled third-party licenses are retained in the source tree.