Skip to content

Commit fe42411

Browse files
committed
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.
1 parent d2bb681 commit fe42411

File tree

2 files changed

+16
-11
lines changed

2 files changed

+16
-11
lines changed

src/test/miner_tests.cpp

Lines changed: 0 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -36,17 +36,6 @@ struct MinerTestingSetup : public TestingSetup {
3636

3737
BOOST_FIXTURE_TEST_SUITE(miner_tests, MinerTestingSetup)
3838

39-
// BOOST_CHECK_EXCEPTION predicates to check the specific validation error
40-
class HasReason {
41-
public:
42-
explicit HasReason(const std::string& reason) : m_reason(reason) {}
43-
bool operator() (const std::runtime_error& e) const {
44-
return std::string(e.what()).find(m_reason) != std::string::npos;
45-
};
46-
private:
47-
const std::string m_reason;
48-
};
49-
5039
static CFeeRate blockMinFeeRate = CFeeRate(DEFAULT_BLOCK_MIN_TX_FEE);
5140

5241
BlockAssembler MinerTestingSetup::AssemblerForTest(const CChainParams& params)

src/test/util/setup_common.h

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -153,4 +153,20 @@ CBlock getBlock13b8a();
153153
// define an implicit conversion here so that uint256 may be used directly in BOOST_CHECK_*
154154
std::ostream& operator<<(std::ostream& os, const uint256& num);
155155

156+
/**
157+
* BOOST_CHECK_EXCEPTION predicates to check the specific validation error.
158+
* Use as
159+
* BOOST_CHECK_EXCEPTION(code that throws, exception type, HasReason("foo"));
160+
*/
161+
class HasReason {
162+
public:
163+
explicit HasReason(const std::string& reason) : m_reason(reason) {}
164+
template <typename E>
165+
bool operator() (const E& e) const {
166+
return std::string(e.what()).find(m_reason) != std::string::npos;
167+
};
168+
private:
169+
const std::string m_reason;
170+
};
171+
156172
#endif

0 commit comments

Comments
 (0)