mirror of
https://github.com/bitcoin/bitcoin.git
synced 2026-09-14 23:37:51 +02:00
Merge bitcoin/bitcoin#36018: test: [refactor] Properly use BOOST_CHECK_EXCEPTION
fa0fe212f5test: [refactor] Properly use BOOST_CHECK_EXCEPTION (MarcoFalke) Pull request description: The exception checking in unit tests is partly verbose, fragile, inconsistent and thus confusing. Fix all those issues by using `BOOST_CHECK_EXCEPTION` consistently: * The test code is less bloated and follows a standard pattern; Extra state and dead code like `exceptionThrown = false;` or `BOOST_CHECK(0)` can be removed. * The checks are more strict, because they use `HasReason{...}` or a similar predicate. ACKs for top commit: l0rinc: ACKfa0fe212f5janb84: ACKfa0fe212f5jonatack: Light ACKfa0fe212f5Tree-SHA512: f3a9abfe02988299f6d2604643feb630e078c2177287899d4fcc191802536d41d09e6365d81d0184bf3533583987969cb1b85ab3e112e7364fdb5b85a3405cb7
This commit is contained in:
@@ -541,24 +541,14 @@ BOOST_AUTO_TEST_CASE(ccoins_serialization)
|
||||
BOOST_CHECK_EQUAL(cc3.out.scriptPubKey.size(), 0U);
|
||||
|
||||
// scriptPubKey that ends beyond the end of the stream
|
||||
try {
|
||||
Coin cc4;
|
||||
SpanReader{"000007"_hex} >> cc4;
|
||||
BOOST_CHECK_MESSAGE(false, "We should have thrown");
|
||||
} catch (const std::ios_base::failure&) {
|
||||
}
|
||||
BOOST_CHECK_EXCEPTION(SpanReader{"000007"_hex} >> Coin{}, std::ios_base::failure, HasReason{"end of data"});
|
||||
|
||||
// Very large scriptPubKey (3*10^9 bytes) past the end of the stream
|
||||
DataStream tmp{};
|
||||
uint64_t x = 3000000000ULL;
|
||||
tmp << VARINT(x);
|
||||
BOOST_CHECK_EQUAL(HexStr(tmp), "8a95c0bb00");
|
||||
try {
|
||||
Coin cc5;
|
||||
SpanReader{"00008a95c0bb00"_hex} >> cc5;
|
||||
BOOST_CHECK_MESSAGE(false, "We should have thrown");
|
||||
} catch (const std::ios_base::failure&) {
|
||||
}
|
||||
BOOST_CHECK_EXCEPTION(SpanReader{"00008a95c0bb00"_hex} >> Coin{}, std::ios_base::failure, HasReason{"end of data"});
|
||||
}
|
||||
|
||||
const static COutPoint OUTPOINT;
|
||||
|
||||
Reference in New Issue
Block a user