consensus/test: add out-of-range output unit tests for `CTransaction::GetValueOut`
What changed, and why it matters
This commit only adds a new automated test to Bitcoin Core. It checks that a helper function called GetValueOut() correctly throws an error when a transaction output exceeds the maximum allowed money value. There is no change to production code, no bug fix, and no security patch.
No action required; this is a routine test-coverage improvement. Reviewers may optionally confirm the test passes and that the existing GetValueOut() behavior is already enforced elsewhere in consensus code.
Security signals we found
No production code modified
Test-only addition
Exercises existing error-handling path
Evidence from the diff
The diff adds a single BOOST_AUTO_TEST_CASE in src/test/transaction_tests.cpp. It constructs a mutable transaction with one output whose amount is MAX_MONEY + 1, then verifies that CTransaction::GetValueOut() throws a std::runtime_error with the message ‘GetValueOut: value out of range’. The production behavior already existed; this merely exercises the out-of-range branch for coverage.
Changed components
src/test/transaction_tests.cppInspect captured patch +9 / −0
diff --git a/src/test/transaction_tests.cpp b/src/test/transaction_tests.cpp
index 0f175c7d..a7a46e4f 100644
--- a/src/test/transaction_tests.cpp
+++ b/src/test/transaction_tests.cpp
@@ -1155,6 +1155,15 @@ BOOST_AUTO_TEST_CASE(checktxinputs_invalid_transactions_test)
TxValidationResult::TX_PREMATURE_SPEND, /*expected_reason=*/"bad-txns-premature-spend-of-coinbase");
}
+BOOST_AUTO_TEST_CASE(getvalueout_out_of_range_throws)
+{
+ CMutableTransaction mtx;
+ mtx.vout.emplace_back(MAX_MONEY + 1, CScript() << OP_TRUE);
+
+ const CTransaction tx{mtx};
+ BOOST_CHECK_EXCEPTION(tx.GetValueOut(), std::runtime_error, HasReason("GetValueOut: value out of range"));
+}
+
/** Sanity check the return value of SpendsNonAnchorWitnessProg for various output types. */
BOOST_AUTO_TEST_CASE(spends_witness_prog)
{
Why this scored 13/100
Community notes
Notes can correct, qualify, or add evidence to the AI analysis. Every note shown here has been validated by a human moderator.
The AI analysis stands alone for now. Submit a note if you can add evidence or important context.