From fe42411b4b07b99c591855f5f00ad45dfeec8e30 Mon Sep 17 00:00:00 2001 From: Vasil Dimov Date: Mon, 31 Aug 2020 13:16:13 +0200 Subject: test: move HasReason so it can be reused Move the class `HasReason` from `miner_tests.cpp` to `setup_common.h` so that it can be reused by other tests. --- src/test/util/setup_common.h | 16 ++++++++++++++++ 1 file changed, 16 insertions(+) (limited to 'src/test/util/setup_common.h') diff --git a/src/test/util/setup_common.h b/src/test/util/setup_common.h index 22f5d6d936..a09c8c122d 100644 --- a/src/test/util/setup_common.h +++ b/src/test/util/setup_common.h @@ -153,4 +153,20 @@ CBlock getBlock13b8a(); // define an implicit conversion here so that uint256 may be used directly in BOOST_CHECK_* std::ostream& operator<<(std::ostream& os, const uint256& num); +/** + * BOOST_CHECK_EXCEPTION predicates to check the specific validation error. + * Use as + * BOOST_CHECK_EXCEPTION(code that throws, exception type, HasReason("foo")); + */ +class HasReason { +public: + explicit HasReason(const std::string& reason) : m_reason(reason) {} + template + bool operator() (const E& e) const { + return std::string(e.what()).find(m_reason) != std::string::npos; + }; +private: + const std::string m_reason; +}; + #endif -- cgit v1.2.3