test: use BOOST_REQUIRE for fatal preconditions in coinjoin_tests#7164
Conversation
Replace assert() and BOOST_CHECK() with BOOST_REQUIRE() where subsequent code depends on the check result. When Commit() or CreateTransaction() fails intermittently (e.g. under sanitizer builds), BOOST_CHECK logs the failure but continues execution, causing a cascading hard assert() crash in AddTxToChain() when the transaction is not found in mapWallet. BOOST_REQUIRE aborts the test case on failure, giving a clean failure message instead of a process abort. Fixes dashpay#6696
✅ No Merge Conflicts DetectedThis PR currently has no conflicts with other open PRs. |
WalkthroughThis pull request modifies the coinjoin test file to replace weaker runtime assertions (assert/BOOST_CHECK) with stricter test assertions (BOOST_REQUIRE). The changes affect wallet test setup, destination reservation, transaction creation, and commit operations. By enforcing preconditions more strictly, failed assertions now halt test execution immediately rather than allowing the test to continue with potentially invalid state. Estimated code review effort🎯 1 (Trivial) | ⏱️ ~5 minutes 🚥 Pre-merge checks | ✅ 4 | ❌ 1❌ Failed checks (1 warning)
✅ Passed checks (4 passed)
✏️ Tip: You can configure your own custom pre-merge checks in the settings. ✨ Finishing Touches
🧪 Generate unit tests (beta)
Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out. Comment |
Issue
Refs #6696
Description
The
CTransactionBuilderTesttest intermittently crashes with a hardassert()failure inAddTxToChain():This happens because
BOOST_CHECK(txBuilder.Commit(strResult))is non-fatal — whenCommit()fails intermittently (e.g., under UBSAN/sanitizer builds), execution continues andAddTxToChain()is called with an invalid/empty txid, hitting the hardassert().Solution
Replace
assert()andBOOST_CHECK()withBOOST_REQUIRE()at all points where subsequent code depends on the check result:assert(it != wallet->mapWallet.end())→BOOST_REQUIRE(...)inAddTxToChain()BOOST_CHECK(txBuilder.Commit(strResult))→BOOST_REQUIRE(...)(both call sites)BOOST_CHECK(dest_opt)andBOOST_CHECK(res)→BOOST_REQUIRE(...)inGetTallyItem()where the result is immediately dereferencedassert(tallyItem.outpoints.size() == vecAmounts.size())→BOOST_REQUIRE_EQUAL(...)inGetTallyItem()BOOST_REQUIREaborts the test case on failure, producing a clean failure message instead of a process abort viaassert(). This prevents the cascading crash that makes debugging the root cause harder.Validation
What was tested:
wallet/test/coinjoin_tests.cppResults:
linux64-build / Build source— passlinux64-test / Test source— passlinux64_ubsan-build / Build source— passlinux64_ubsan-test / Test source— passmac-build / Build source— passwin64-build / Build source— passEnvironment: GitHub Actions CI (linux64 + ubsan + mac + win64 matrix)