Changeset View
Changeset View
Standalone View
Standalone View
src/test/miner_tests.cpp
Show First 20 Lines • Show All 514 Lines • ▼ Show 20 Lines | BOOST_AUTO_TEST_CASE(CreateNewBlock_validity) { | ||||
txid = tx.GetId(); | txid = tx.GetId(); | ||||
m_node.mempool->addUnchecked( | m_node.mempool->addUnchecked( | ||||
entry.Fee(HIGHFEE).Time(GetTime()).SpendsCoinbase(true).FromTx(tx)); | entry.Fee(HIGHFEE).Time(GetTime()).SpendsCoinbase(true).FromTx(tx)); | ||||
const Consensus::Params ¶ms = chainparams.GetConsensus(); | const Consensus::Params ¶ms = chainparams.GetConsensus(); | ||||
{ | { | ||||
// Locktime passes. | // Locktime passes. | ||||
CValidationState state; | TxValidationState state; | ||||
BOOST_CHECK(ContextualCheckTransactionForCurrentBlock( | BOOST_CHECK(ContextualCheckTransactionForCurrentBlock( | ||||
params, CTransaction(tx), state, flags)); | 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( | ||||
Show All 9 Lines | tx.vin[0].nSequence = CTxIn::SEQUENCE_LOCKTIME_TYPE_FLAG | | ||||
CTxIn::SEQUENCE_LOCKTIME_GRANULARITY) + | CTxIn::SEQUENCE_LOCKTIME_GRANULARITY) + | ||||
1); | 1); | ||||
prevheights[0] = baseheight + 2; | prevheights[0] = baseheight + 2; | ||||
txid = tx.GetId(); | txid = tx.GetId(); | ||||
m_node.mempool->addUnchecked(entry.Time(GetTime()).FromTx(tx)); | m_node.mempool->addUnchecked(entry.Time(GetTime()).FromTx(tx)); | ||||
{ | { | ||||
// Locktime passes. | // Locktime passes. | ||||
CValidationState state; | TxValidationState state; | ||||
BOOST_CHECK(ContextualCheckTransactionForCurrentBlock( | BOOST_CHECK(ContextualCheckTransactionForCurrentBlock( | ||||
params, CTransaction(tx), state, flags)); | 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++) { | ||||
Show All 20 Lines | BOOST_AUTO_TEST_CASE(CreateNewBlock_validity) { | ||||
tx.vin[0].nSequence = CTxIn::SEQUENCE_FINAL - 1; | tx.vin[0].nSequence = CTxIn::SEQUENCE_FINAL - 1; | ||||
prevheights[0] = baseheight + 3; | prevheights[0] = baseheight + 3; | ||||
tx.nLockTime = ::ChainActive().Tip()->nHeight + 1; | tx.nLockTime = ::ChainActive().Tip()->nHeight + 1; | ||||
txid = tx.GetId(); | txid = tx.GetId(); | ||||
m_node.mempool->addUnchecked(entry.Time(GetTime()).FromTx(tx)); | m_node.mempool->addUnchecked(entry.Time(GetTime()).FromTx(tx)); | ||||
{ | { | ||||
// Locktime fails. | // Locktime fails. | ||||
CValidationState state; | TxValidationState state; | ||||
BOOST_CHECK(!ContextualCheckTransactionForCurrentBlock( | BOOST_CHECK(!ContextualCheckTransactionForCurrentBlock( | ||||
params, CTransaction(tx), state, flags)); | params, CTransaction(tx), state, flags)); | ||||
BOOST_CHECK_EQUAL(state.GetRejectReason(), "bad-txns-nonfinal"); | BOOST_CHECK_EQUAL(state.GetRejectReason(), "bad-txns-nonfinal"); | ||||
} | } | ||||
// Sequence locks pass. | // Sequence locks pass. | ||||
BOOST_CHECK(TestSequenceLocks(CTransaction(tx), flags)); | BOOST_CHECK(TestSequenceLocks(CTransaction(tx), flags)); | ||||
{ | { | ||||
// Locktime passes on 2nd block. | // Locktime passes on 2nd block. | ||||
CValidationState state; | TxValidationState state; | ||||
int64_t nMedianTimePast = ::ChainActive().Tip()->GetMedianTimePast(); | int64_t nMedianTimePast = ::ChainActive().Tip()->GetMedianTimePast(); | ||||
BOOST_CHECK(ContextualCheckTransaction( | BOOST_CHECK(ContextualCheckTransaction( | ||||
params, CTransaction(tx), state, ::ChainActive().Tip()->nHeight + 2, | params, CTransaction(tx), state, ::ChainActive().Tip()->nHeight + 2, | ||||
nMedianTimePast, nMedianTimePast)); | nMedianTimePast, nMedianTimePast)); | ||||
} | } | ||||
// Absolute time locked. | // Absolute time locked. | ||||
tx.vin[0].prevout = COutPoint(txFirst[3]->GetId(), 0); | tx.vin[0].prevout = COutPoint(txFirst[3]->GetId(), 0); | ||||
tx.nLockTime = ::ChainActive().Tip()->GetMedianTimePast(); | tx.nLockTime = ::ChainActive().Tip()->GetMedianTimePast(); | ||||
prevheights.resize(1); | prevheights.resize(1); | ||||
prevheights[0] = baseheight + 4; | prevheights[0] = baseheight + 4; | ||||
txid = tx.GetId(); | txid = tx.GetId(); | ||||
m_node.mempool->addUnchecked(entry.Time(GetTime()).FromTx(tx)); | m_node.mempool->addUnchecked(entry.Time(GetTime()).FromTx(tx)); | ||||
{ | { | ||||
// Locktime fails. | // Locktime fails. | ||||
CValidationState state; | TxValidationState state; | ||||
BOOST_CHECK(!ContextualCheckTransactionForCurrentBlock( | BOOST_CHECK(!ContextualCheckTransactionForCurrentBlock( | ||||
params, CTransaction(tx), state, flags)); | params, CTransaction(tx), state, flags)); | ||||
BOOST_CHECK_EQUAL(state.GetRejectReason(), "bad-txns-nonfinal"); | BOOST_CHECK_EQUAL(state.GetRejectReason(), "bad-txns-nonfinal"); | ||||
} | } | ||||
// Sequence locks pass. | // Sequence locks pass. | ||||
BOOST_CHECK(TestSequenceLocks(CTransaction(tx), flags)); | BOOST_CHECK(TestSequenceLocks(CTransaction(tx), flags)); | ||||
{ | { | ||||
// Locktime passes 1 second later. | // Locktime passes 1 second later. | ||||
CValidationState state; | TxValidationState state; | ||||
int64_t nMedianTimePast = | int64_t nMedianTimePast = | ||||
::ChainActive().Tip()->GetMedianTimePast() + 1; | ::ChainActive().Tip()->GetMedianTimePast() + 1; | ||||
BOOST_CHECK(ContextualCheckTransaction( | BOOST_CHECK(ContextualCheckTransaction( | ||||
params, CTransaction(tx), state, ::ChainActive().Tip()->nHeight + 1, | params, CTransaction(tx), state, ::ChainActive().Tip()->nHeight + 1, | ||||
nMedianTimePast, nMedianTimePast)); | nMedianTimePast, nMedianTimePast)); | ||||
} | } | ||||
// mempool-dependent transactions (not added) | // mempool-dependent transactions (not added) | ||||
tx.vin[0].prevout = COutPoint(txid, 0); | tx.vin[0].prevout = COutPoint(txid, 0); | ||||
prevheights[0] = ::ChainActive().Tip()->nHeight + 1; | prevheights[0] = ::ChainActive().Tip()->nHeight + 1; | ||||
tx.nLockTime = 0; | tx.nLockTime = 0; | ||||
tx.vin[0].nSequence = 0; | tx.vin[0].nSequence = 0; | ||||
{ | { | ||||
// Locktime passes. | // Locktime passes. | ||||
CValidationState state; | TxValidationState state; | ||||
BOOST_CHECK(ContextualCheckTransactionForCurrentBlock( | BOOST_CHECK(ContextualCheckTransactionForCurrentBlock( | ||||
params, CTransaction(tx), state, flags)); | params, CTransaction(tx), state, flags)); | ||||
} | } | ||||
// Sequence locks pass. | // Sequence locks pass. | ||||
BOOST_CHECK(TestSequenceLocks(CTransaction(tx), flags)); | BOOST_CHECK(TestSequenceLocks(CTransaction(tx), flags)); | ||||
tx.vin[0].nSequence = 1; | tx.vin[0].nSequence = 1; | ||||
// Sequence locks fail. | // Sequence locks fail. | ||||
▲ Show 20 Lines • Show All 105 Lines • Show Last 20 Lines |