mirror of
https://github.com/bitcoin/bitcoin.git
synced 2025-04-23 23:12:20 +02:00
Add std::optional support to Boost's equality check
Also moved the operators to the bottom of the file since they're less important and to group them together. Co-authored-by: Hodlinator <172445034+hodlinator@users.noreply.github.com> Co-authored-by: stickies-v <stickies-v@protonmail.com>
This commit is contained in:
parent
712a2b5453
commit
743ac30e34
@ -78,24 +78,6 @@ constexpr inline auto TEST_DIR_PATH_ELEMENT{"test_common bitcoin"}; // Includes
|
||||
/** Random context to get unique temp data dirs. Separate from m_rng, which can be seeded from a const env var */
|
||||
static FastRandomContext g_rng_temp_path;
|
||||
|
||||
std::ostream& operator<<(std::ostream& os, const arith_uint256& num)
|
||||
{
|
||||
os << num.ToString();
|
||||
return os;
|
||||
}
|
||||
|
||||
std::ostream& operator<<(std::ostream& os, const uint160& num)
|
||||
{
|
||||
os << num.ToString();
|
||||
return os;
|
||||
}
|
||||
|
||||
std::ostream& operator<<(std::ostream& os, const uint256& num)
|
||||
{
|
||||
os << num.ToString();
|
||||
return os;
|
||||
}
|
||||
|
||||
struct NetworkSetup
|
||||
{
|
||||
NetworkSetup()
|
||||
@ -606,3 +588,18 @@ CBlock getBlock13b8a()
|
||||
stream >> TX_WITH_WITNESS(block);
|
||||
return block;
|
||||
}
|
||||
|
||||
std::ostream& operator<<(std::ostream& os, const arith_uint256& num)
|
||||
{
|
||||
return os << num.ToString();
|
||||
}
|
||||
|
||||
std::ostream& operator<<(std::ostream& os, const uint160& num)
|
||||
{
|
||||
return os << num.ToString();
|
||||
}
|
||||
|
||||
std::ostream& operator<<(std::ostream& os, const uint256& num)
|
||||
{
|
||||
return os << num.ToString();
|
||||
}
|
||||
|
@ -10,6 +10,8 @@
|
||||
#include <key.h>
|
||||
#include <node/caches.h>
|
||||
#include <node/context.h> // IWYU pragma: export
|
||||
#include <optional>
|
||||
#include <ostream>
|
||||
#include <primitives/transaction.h>
|
||||
#include <pubkey.h>
|
||||
#include <stdexcept>
|
||||
@ -29,6 +31,8 @@ class arith_uint256;
|
||||
class CFeeRate;
|
||||
class Chainstate;
|
||||
class FastRandomContext;
|
||||
class uint160;
|
||||
class uint256;
|
||||
|
||||
/** This is connected to the logger. Can be used to redirect logs to any other log */
|
||||
extern const std::function<void(const std::string&)> G_TEST_LOG_FUN;
|
||||
@ -39,15 +43,6 @@ extern const std::function<std::vector<const char*>()> G_TEST_COMMAND_LINE_ARGUM
|
||||
/** Retrieve the unit test name. */
|
||||
extern const std::function<std::string()> G_TEST_GET_FULL_NAME;
|
||||
|
||||
// Enable BOOST_CHECK_EQUAL for enum class types
|
||||
namespace std {
|
||||
template <typename T>
|
||||
std::ostream& operator<<(typename std::enable_if<std::is_enum<T>::value, std::ostream>::type& stream, const T& e)
|
||||
{
|
||||
return stream << static_cast<typename std::underlying_type<T>::type>(e);
|
||||
}
|
||||
} // namespace std
|
||||
|
||||
static constexpr CAmount CENT{1000000};
|
||||
|
||||
struct TestOpts {
|
||||
@ -250,10 +245,26 @@ std::unique_ptr<T> MakeNoLogFileContext(const ChainType chain_type = ChainType::
|
||||
|
||||
CBlock getBlock13b8a();
|
||||
|
||||
// Make types usable in BOOST_CHECK_*
|
||||
// Make types usable in BOOST_CHECK_* @{
|
||||
namespace std {
|
||||
template <typename T> requires std::is_enum_v<T>
|
||||
inline std::ostream& operator<<(std::ostream& os, const T& e)
|
||||
{
|
||||
return os << static_cast<std::underlying_type_t<T>>(e);
|
||||
}
|
||||
|
||||
template <typename T>
|
||||
inline std::ostream& operator<<(std::ostream& os, const std::optional<T>& v)
|
||||
{
|
||||
return v ? os << *v
|
||||
: os << "std::nullopt";
|
||||
}
|
||||
} // namespace std
|
||||
|
||||
std::ostream& operator<<(std::ostream& os, const arith_uint256& num);
|
||||
std::ostream& operator<<(std::ostream& os, const uint160& num);
|
||||
std::ostream& operator<<(std::ostream& os, const uint256& num);
|
||||
// @}
|
||||
|
||||
/**
|
||||
* BOOST_CHECK_EXCEPTION predicates to check the specific validation error.
|
||||
|
Loading…
x
Reference in New Issue
Block a user