Changeset View
Changeset View
Standalone View
Standalone View
src/test/miner_tests.cpp
Show First 20 Lines • Show All 83 Lines • ▼ Show 20 Lines | constexpr static struct { | ||||
{1, 0x70de86a8}, {1, 0x74d64cd5}, {1, 0x49e738a1}, {2, 0x6910b602}, | {1, 0x70de86a8}, {1, 0x74d64cd5}, {1, 0x49e738a1}, {2, 0x6910b602}, | ||||
{0, 0x643c565f}, {1, 0x54264b3f}, {2, 0x97ea6396}, {2, 0x55174459}, | {0, 0x643c565f}, {1, 0x54264b3f}, {2, 0x97ea6396}, {2, 0x55174459}, | ||||
{2, 0x03e8779a}, {1, 0x98f34d8f}, {1, 0xc07b2b07}, {1, 0xdfe29668}, | {2, 0x03e8779a}, {1, 0x98f34d8f}, {1, 0xc07b2b07}, {1, 0xdfe29668}, | ||||
{1, 0x3141c7c1}, {1, 0xb3b595f4}, {1, 0x735abf08}, {5, 0x623bfbce}, | {1, 0x3141c7c1}, {1, 0xb3b595f4}, {1, 0x735abf08}, {5, 0x623bfbce}, | ||||
{2, 0xd351e722}, {1, 0xf4ca48c9}, {1, 0x5b19c670}, {1, 0xa164bf0e}, | {2, 0xd351e722}, {1, 0xf4ca48c9}, {1, 0x5b19c670}, {1, 0xa164bf0e}, | ||||
{2, 0xbbbeb305}, {2, 0xfe1c810a}, | {2, 0xbbbeb305}, {2, 0xfe1c810a}, | ||||
}; | }; | ||||
static CBlockIndex CreateBlockIndex(int nHeight) | static CBlockIndex CreateBlockIndex(int nHeight, CBlockIndex *active_chain_tip) | ||||
EXCLUSIVE_LOCKS_REQUIRED(cs_main) { | EXCLUSIVE_LOCKS_REQUIRED(cs_main) { | ||||
CBlockIndex index; | CBlockIndex index; | ||||
index.nHeight = nHeight; | index.nHeight = nHeight; | ||||
index.pprev = ::ChainActive().Tip(); | index.pprev = active_chain_tip; | ||||
return index; | return index; | ||||
} | } | ||||
// Test suite for ancestor feerate transaction selection. | // Test suite for ancestor feerate transaction selection. | ||||
// Implemented as an additional function, rather than a separate test case, | // Implemented as an additional function, rather than a separate test case, | ||||
// to allow reusing the blockchain created in CreateNewBlock_validity. | // to allow reusing the blockchain created in CreateNewBlock_validity. | ||||
void MinerTestingSetup::TestPackageSelection( | void MinerTestingSetup::TestPackageSelection( | ||||
const CChainParams &chainparams, const CScript &scriptPubKey, | const CChainParams &chainparams, const CScript &scriptPubKey, | ||||
▲ Show 20 Lines • Show All 406 Lines • ▼ Show 20 Lines | const Consensus::Params ¶ms = chainparams.GetConsensus(); | ||||
// Locktime passes. | // Locktime passes. | ||||
TxValidationState state; | TxValidationState state; | ||||
BOOST_CHECK(ContextualCheckTransactionForCurrentBlock( | BOOST_CHECK(ContextualCheckTransactionForCurrentBlock( | ||||
::ChainActive().Tip(), params, CTransaction(tx), state, flags)); | ::ChainActive().Tip(), params, CTransaction(tx), state, flags)); | ||||
} | } | ||||
// Sequence locks fail. | // Sequence locks fail. | ||||
BOOST_CHECK(!TestSequenceLocks(CTransaction(tx), flags)); | BOOST_CHECK(!TestSequenceLocks(CTransaction(tx), flags)); | ||||
// Sequence locks pass on 2nd block. | // Sequence locks pass on 2nd block. | ||||
BOOST_CHECK( | BOOST_CHECK( | ||||
SequenceLocks(CTransaction(tx), flags, prevheights, | SequenceLocks(CTransaction(tx), flags, prevheights, | ||||
CreateBlockIndex(::ChainActive().Tip()->nHeight + 2))); | CreateBlockIndex(m_node.chainman->ActiveHeight() + 2, | ||||
m_node.chainman->ActiveTip()))); | |||||
// Relative time locked. | // Relative time locked. | ||||
tx.vin[0].prevout = COutPoint(txFirst[1]->GetId(), 0); | tx.vin[0].prevout = COutPoint(txFirst[1]->GetId(), 0); | ||||
// txFirst[1] is the 3rd block. | // txFirst[1] is the 3rd block. | ||||
tx.vin[0].nSequence = CTxIn::SEQUENCE_LOCKTIME_TYPE_FLAG | | tx.vin[0].nSequence = CTxIn::SEQUENCE_LOCKTIME_TYPE_FLAG | | ||||
(((::ChainActive().Tip()->GetMedianTimePast() + 1 - | (((::ChainActive().Tip()->GetMedianTimePast() + 1 - | ||||
::ChainActive()[1]->GetMedianTimePast()) >> | ::ChainActive()[1]->GetMedianTimePast()) >> | ||||
CTxIn::SEQUENCE_LOCKTIME_GRANULARITY) + | CTxIn::SEQUENCE_LOCKTIME_GRANULARITY) + | ||||
Show All 9 Lines | m_node.mempool->addUnchecked(entry.Time(GetTime()).FromTx(tx)); | ||||
::ChainActive().Tip(), params, CTransaction(tx), state, flags)); | ::ChainActive().Tip(), params, CTransaction(tx), state, flags)); | ||||
} | } | ||||
// Sequence locks fail. | // Sequence locks fail. | ||||
BOOST_CHECK(!TestSequenceLocks(CTransaction(tx), flags)); | BOOST_CHECK(!TestSequenceLocks(CTransaction(tx), flags)); | ||||
for (int i = 0; i < CBlockIndex::nMedianTimeSpan; i++) { | for (int i = 0; i < CBlockIndex::nMedianTimeSpan; i++) { | ||||
// Trick the MedianTimePast. | // Trick the MedianTimePast. | ||||
::ChainActive() | m_node.chainman->ActiveTip() | ||||
.Tip() | ->GetAncestor(m_node.chainman->ActiveHeight() - i) | ||||
->GetAncestor(::ChainActive().Tip()->nHeight - i) | |||||
->nTime += 512; | ->nTime += 512; | ||||
} | } | ||||
// Sequence locks pass 512 seconds later. | // Sequence locks pass 512 seconds later. | ||||
BOOST_CHECK( | BOOST_CHECK( | ||||
SequenceLocks(CTransaction(tx), flags, prevheights, | SequenceLocks(CTransaction(tx), flags, prevheights, | ||||
CreateBlockIndex(::ChainActive().Tip()->nHeight + 1))); | CreateBlockIndex(m_node.chainman->ActiveHeight() + 1, | ||||
m_node.chainman->ActiveTip()))); | |||||
for (int i = 0; i < CBlockIndex::nMedianTimeSpan; i++) { | for (int i = 0; i < CBlockIndex::nMedianTimeSpan; i++) { | ||||
// Undo tricked MTP. | // Undo tricked MTP. | ||||
::ChainActive() | ::ChainActive() | ||||
.Tip() | .Tip() | ||||
->GetAncestor(::ChainActive().Tip()->nHeight - i) | ->GetAncestor(::ChainActive().Tip()->nHeight - i) | ||||
->nTime -= 512; | ->nTime -= 512; | ||||
} | } | ||||
▲ Show 20 Lines • Show All 178 Lines • Show Last 20 Lines |