Problem
Coverage reports indicate that a few consensus related validations aren’t exercised in unit-, and some not even in the functional-tests: Inspired by the coverage reports:
- “bad-txns-premature-spend-of-coinbase”: Only covered in functional tests
- “bad-txns-inputvalues-outofrange”: Unreachable in functional tests [1], uncovered in unit tests
- “bad-txns-in-belowout”: Only covered in functional tests
- “GetValueOut: value out of range” and total coverage report
Replacing them with explicit throws still passes all unit (and sometimes even functional) tests, confirming those branches are not being exercised, see: https://github.com/l0rinc/bitcoin/pull/112
Fixes
Add minimal unit test coverage for Consensus::CheckTxInputs invalid outcomes for bad-txns-premature-spend-of-coinbase, bad-txns-inputvalues-outofrange, bad-txns-in-belowout.
Add a unit test covering CTransaction::GetValueOut() throwing for out of range values.
After the prerequisits are tested, document why bad-txns-fee-outofrange is unreachable - while keeping the check in place because it is consensus-critical code.