From a5fc82e2b1403b7bf0f1ad494a62ccff793f99d0 Mon Sep 17 00:00:00 2001 From: ViniciusCestarii Date: Tue, 25 Aug 2026 09:18:59 -0300 Subject: [PATCH] test: cover enforce BIP68 to tx versions higher than 2 --- src/test/transaction_tests.cpp | 25 +++++++++++++++++++++++++ 1 file changed, 25 insertions(+) diff --git a/src/test/transaction_tests.cpp b/src/test/transaction_tests.cpp index 7caacab9488..beb0e740927 100644 --- a/src/test/transaction_tests.cpp +++ b/src/test/transaction_tests.cpp @@ -6,6 +6,7 @@ #include #include +#include #include #include #include @@ -1190,6 +1191,30 @@ BOOST_AUTO_TEST_CASE(isfinaltx_sequences_test) check_final(/*sequences=*/{CTxIn::MAX_SEQUENCE_NONFINAL, CTxIn::SEQUENCE_FINAL}, /*expected_final=*/false); } +BOOST_AUTO_TEST_CASE(calculatesequencelocks_tx_version_test) +{ + constexpr int coin_height{100}; + + // A single input with a height-based relative locktime of one block. Only the + // height branch is taken, so the block index is never dereferenced. + auto check_min_height{[](uint32_t version, int expected_min_height) { + CMutableTransaction mtx; + mtx.version = version; + mtx.vin.emplace_back(COutPoint{}, CScript{}, /*nSequenceIn=*/1); + + std::vector prev_heights{coin_height}; + const CBlockIndex block{}; + const auto lock_pair{CalculateSequenceLocks(CTransaction{mtx}, LOCKTIME_VERIFY_SEQUENCE, prev_heights, block)}; + BOOST_CHECK_EQUAL(lock_pair.first, expected_min_height); + }}; + + // BIP68 only applies to versions 2 and up + check_min_height(/*version=*/0, /*expected_min_height=*/-1); + check_min_height(/*version=*/1, /*expected_min_height=*/-1); + check_min_height(/*version=*/2, /*expected_min_height=*/coin_height); + check_min_height(/*version=*/std::numeric_limits::max(), /*expected_min_height=*/coin_height); +} + BOOST_AUTO_TEST_CASE(getvalueout_out_of_range_throws) { CMutableTransaction mtx;