Skip to content

Commit 788aeeb

Browse files
committed
qa: use prev height as nLockTime for coinbase txs created in unit tests
We don't set the nSequence as it will be set directly in the block template generator in a following commit.
1 parent c76dbe9 commit 788aeeb

File tree

2 files changed

+4
-1
lines changed

2 files changed

+4
-1
lines changed

src/test/blockfilter_index_tests.cpp

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -81,6 +81,7 @@ CBlock BuildChainTestingSetup::CreateBlock(const CBlockIndex* prev,
8181
}
8282
{
8383
CMutableTransaction tx_coinbase{*block.vtx.at(0)};
84+
tx_coinbase.nLockTime = static_cast<uint32_t>(prev->nHeight);
8485
tx_coinbase.vin.at(0).scriptSig = CScript{} << prev->nHeight + 1;
8586
block.vtx.at(0) = MakeTransactionRef(std::move(tx_coinbase));
8687
block.hashMerkleRoot = BlockMerkleRoot(block);

src/test/validation_block_tests.cpp

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -82,7 +82,9 @@ std::shared_ptr<CBlock> MinerTestingSetup::Block(const uint256& prev_hash)
8282
txCoinbase.vout[0].nValue = 0;
8383
txCoinbase.vin[0].scriptWitness.SetNull();
8484
// Always pad with OP_0 at the end to avoid bad-cb-length error
85-
txCoinbase.vin[0].scriptSig = CScript{} << WITH_LOCK(::cs_main, return m_node.chainman->m_blockman.LookupBlockIndex(prev_hash)->nHeight + 1) << OP_0;
85+
const int prev_height{WITH_LOCK(::cs_main, return m_node.chainman->m_blockman.LookupBlockIndex(prev_hash)->nHeight)};
86+
txCoinbase.vin[0].scriptSig = CScript{} << prev_height + 1 << OP_0;
87+
txCoinbase.nLockTime = static_cast<uint32_t>(prev_height);
8688
pblock->vtx[0] = MakeTransactionRef(std::move(txCoinbase));
8789

8890
return pblock;

0 commit comments

Comments
 (0)