Skip to content

Commit 5d98fc7

Browse files
committed
Merge bitcoin/bitcoin#33030: test: check tx is final when there is no locktime
065e429 test: IsFinalTx returns true when there is no locktime (brunoerg) Pull request description: According to https://corecheck.dev/mutation/src/consensus/tx_verify.cpp, there is no proper test for the `tx.nLockTime == 0` check in the `IsFinalTx` function, which is understandable, since this check will only be useful for a specific case where the `nBlockHeight` (block height) is zero. Otherwise, the following check `if ((int64_t)tx.nLockTime < ((int64_t)tx.nLockTime < LOCKTIME_THRESHOLD ? (int64_t)nBlockHeight : nBlockTime))` would catch any of it. This PR adds a test case for it. ACKs for top commit: maflcko: lgtm ACK 065e429 enirox001: ACK 065e429: Valuable test case that explicitly demonstrates `IsFinalTx` behavior when nLockTime is 0 achow101: ACK 065e429 darosior: utACK 065e429 Tree-SHA512: e44a7c060bd4c3d746fab166442cadc3fd449ddd8b02cabf22024a5dde6f438f24c6e1bff2a6dc49b57c8e01234aa0fd393fbfe6194df9d9b6c3d4fa2655c99b
2 parents 7129c9e + 065e429 commit 5d98fc7

File tree

1 file changed

+4
-0
lines changed

1 file changed

+4
-0
lines changed

src/test/miner_tests.cpp

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -523,6 +523,10 @@ void MinerTestingSetup::TestBasicMining(const CScript& scriptPubKey, const std::
523523
BOOST_CHECK(TestSequenceLocks(CTransaction{tx}, tx_mempool)); // Sequence locks pass
524524
BOOST_CHECK(IsFinalTx(CTransaction(tx), m_node.chainman->ActiveChain().Tip()->nHeight + 2, m_node.chainman->ActiveChain().Tip()->GetMedianTimePast())); // Locktime passes on 2nd block
525525

526+
// ensure tx is final for a specific case where there is no locktime and block height is zero
527+
tx.nLockTime = 0;
528+
BOOST_CHECK(IsFinalTx(CTransaction(tx), /*nBlockHeight=*/0, m_node.chainman->ActiveChain().Tip()->GetMedianTimePast()));
529+
526530
// absolute time locked
527531
tx.vin[0].prevout.hash = txFirst[3]->GetHash();
528532
tx.nLockTime = m_node.chainman->ActiveChain().Tip()->GetMedianTimePast();

0 commit comments

Comments
 (0)