From bba1d4150ee8d4d4b4df2b91166dff564a756c09 Mon Sep 17 00:00:00 2001 From: ViniciusCestarii Date: Tue, 25 Aug 2026 08:55:13 -0300 Subject: [PATCH] test: cover IsFinalTx requires every input to be SEQUENCE_FINAL --- src/test/transaction_tests.cpp | 23 +++++++++++++++++++++++ 1 file changed, 23 insertions(+) diff --git a/src/test/transaction_tests.cpp b/src/test/transaction_tests.cpp index cd81c3445db..7caacab9488 100644 --- a/src/test/transaction_tests.cpp +++ b/src/test/transaction_tests.cpp @@ -1167,6 +1167,29 @@ BOOST_AUTO_TEST_CASE(checktxinputs_invalid_transactions_test) TxValidationResult::TX_PREMATURE_SPEND, /*expected_reason=*/"bad-txns-premature-spend-of-coinbase"); } +BOOST_AUTO_TEST_CASE(isfinaltx_sequences_test) +{ + constexpr int height{100}; + + // Every transaction here has the same unsatisfied nLockTime, so only the + // sequences decide the outcome. + auto check_final{[](const std::vector& sequences, bool expected_final) { + CMutableTransaction mtx; + mtx.nLockTime = height; + for (const uint32_t sequence : sequences) { + mtx.vin.emplace_back(COutPoint{}, CScript{}, sequence); + } + + BOOST_CHECK_EQUAL(IsFinalTx(CTransaction{mtx}, /*nBlockHeight=*/height, /*nBlockTime=*/0), expected_final); + }}; + + check_final(/*sequences=*/{CTxIn::SEQUENCE_FINAL, CTxIn::SEQUENCE_FINAL}, /*expected_final=*/true); + + // nLockTime is only ignored when every input is SEQUENCE_FINAL + check_final(/*sequences=*/{CTxIn::SEQUENCE_FINAL, CTxIn::MAX_SEQUENCE_NONFINAL}, /*expected_final=*/false); + check_final(/*sequences=*/{CTxIn::MAX_SEQUENCE_NONFINAL, CTxIn::SEQUENCE_FINAL}, /*expected_final=*/false); +} + BOOST_AUTO_TEST_CASE(getvalueout_out_of_range_throws) { CMutableTransaction mtx;