Skip to content

Commit 4d99b61

Browse files
committed
test/miner_tests: Pass in chain tip to CreateBlockIndex
1 parent f0dd5e6 commit 4d99b61

File tree

1 file changed

+14
-5
lines changed

1 file changed

+14
-5
lines changed

src/test/miner_tests.cpp

Lines changed: 14 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -82,11 +82,11 @@ constexpr static struct {
8282
{2, 0xbbbeb305}, {2, 0xfe1c810a},
8383
};
8484

85-
static CBlockIndex CreateBlockIndex(int nHeight) EXCLUSIVE_LOCKS_REQUIRED(cs_main)
85+
static CBlockIndex CreateBlockIndex(int nHeight, CBlockIndex* active_chain_tip) EXCLUSIVE_LOCKS_REQUIRED(cs_main)
8686
{
8787
CBlockIndex index;
8888
index.nHeight = nHeight;
89-
index.pprev = ::ChainActive().Tip();
89+
index.pprev = active_chain_tip;
9090
return index;
9191
}
9292

@@ -440,7 +440,11 @@ BOOST_AUTO_TEST_CASE(CreateNewBlock_validity)
440440
m_node.mempool->addUnchecked(entry.Fee(HIGHFEE).Time(GetTime()).SpendsCoinbase(true).FromTx(tx));
441441
BOOST_CHECK(CheckFinalTx(::ChainActive().Tip(), CTransaction(tx), flags)); // Locktime passes
442442
BOOST_CHECK(!TestSequenceLocks(CTransaction(tx), flags)); // Sequence locks fail
443-
BOOST_CHECK(SequenceLocks(CTransaction(tx), flags, prevheights, CreateBlockIndex(::ChainActive().Tip()->nHeight + 2))); // Sequence locks pass on 2nd block
443+
444+
{
445+
CBlockIndex* active_chain_tip = m_node.chainman->ActiveChain().Tip();
446+
BOOST_CHECK(SequenceLocks(CTransaction(tx), flags, prevheights, CreateBlockIndex(active_chain_tip->nHeight + 2, active_chain_tip))); // Sequence locks pass on 2nd block
447+
}
444448

445449
// relative time locked
446450
tx.vin[0].prevout.hash = txFirst[1]->GetHash();
@@ -452,8 +456,13 @@ BOOST_AUTO_TEST_CASE(CreateNewBlock_validity)
452456
BOOST_CHECK(!TestSequenceLocks(CTransaction(tx), flags)); // Sequence locks fail
453457

454458
for (int i = 0; i < CBlockIndex::nMedianTimeSpan; i++)
455-
::ChainActive().Tip()->GetAncestor(::ChainActive().Tip()->nHeight - i)->nTime += 512; //Trick the MedianTimePast
456-
BOOST_CHECK(SequenceLocks(CTransaction(tx), flags, prevheights, CreateBlockIndex(::ChainActive().Tip()->nHeight + 1))); // Sequence locks pass 512 seconds later
459+
m_node.chainman->ActiveChain().Tip()->GetAncestor(m_node.chainman->ActiveChain().Tip()->nHeight - i)->nTime += 512; //Trick the MedianTimePast
460+
461+
{
462+
CBlockIndex* active_chain_tip = m_node.chainman->ActiveChain().Tip();
463+
BOOST_CHECK(SequenceLocks(CTransaction(tx), flags, prevheights, CreateBlockIndex(active_chain_tip->nHeight + 1, active_chain_tip))); // Sequence locks pass 512 seconds later
464+
}
465+
457466
for (int i = 0; i < CBlockIndex::nMedianTimeSpan; i++)
458467
::ChainActive().Tip()->GetAncestor(::ChainActive().Tip()->nHeight - i)->nTime -= 512; //undo tricked MTP
459468

0 commit comments

Comments
 (0)