Changeset View
Changeset View
Standalone View
Standalone View
src/test/miner_tests.cpp
Show First 20 Lines • Show All 536 Lines • ▼ Show 20 Lines | BOOST_AUTO_TEST_CASE(CreateNewBlock_validity) { | ||||
tx.vout[0].nValue = BLOCKSUBSIDY - HIGHFEE; | tx.vout[0].nValue = BLOCKSUBSIDY - HIGHFEE; | ||||
tx.vout[0].scriptPubKey = CScript() << OP_1; | tx.vout[0].scriptPubKey = CScript() << OP_1; | ||||
tx.nLockTime = 0; | tx.nLockTime = 0; | ||||
txid = tx.GetId(); | txid = tx.GetId(); | ||||
g_mempool.addUnchecked( | g_mempool.addUnchecked( | ||||
txid, | txid, | ||||
entry.Fee(HIGHFEE).Time(GetTime()).SpendsCoinbase(true).FromTx(tx)); | entry.Fee(HIGHFEE).Time(GetTime()).SpendsCoinbase(true).FromTx(tx)); | ||||
const Consensus::Params ¶ms = config.GetChainParams().GetConsensus(); | |||||
{ | { | ||||
// Locktime passes. | // Locktime passes. | ||||
CValidationState state; | CValidationState state; | ||||
BOOST_CHECK(ContextualCheckTransactionForCurrentBlock( | BOOST_CHECK(ContextualCheckTransactionForCurrentBlock( | ||||
config, 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( | ||||
SequenceLocks(CTransaction(tx), flags, &prevheights, | SequenceLocks(CTransaction(tx), flags, &prevheights, | ||||
CreateBlockIndex(chainActive.Tip()->nHeight + 2))); | CreateBlockIndex(chainActive.Tip()->nHeight + 2))); | ||||
Show All 9 Lines | BOOST_AUTO_TEST_CASE(CreateNewBlock_validity) { | ||||
prevheights[0] = baseheight + 2; | prevheights[0] = baseheight + 2; | ||||
txid = tx.GetId(); | txid = tx.GetId(); | ||||
g_mempool.addUnchecked(txid, entry.Time(GetTime()).FromTx(tx)); | g_mempool.addUnchecked(txid, entry.Time(GetTime()).FromTx(tx)); | ||||
{ | { | ||||
// Locktime passes. | // Locktime passes. | ||||
CValidationState state; | CValidationState state; | ||||
BOOST_CHECK(ContextualCheckTransactionForCurrentBlock( | BOOST_CHECK(ContextualCheckTransactionForCurrentBlock( | ||||
config, 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++) { | ||||
// Trick the MedianTimePast. | // Trick the MedianTimePast. | ||||
chainActive.Tip()->GetAncestor(chainActive.Tip()->nHeight - i)->nTime += | chainActive.Tip()->GetAncestor(chainActive.Tip()->nHeight - i)->nTime += | ||||
Show All 16 Lines | BOOST_AUTO_TEST_CASE(CreateNewBlock_validity) { | ||||
tx.nLockTime = chainActive.Tip()->nHeight + 1; | tx.nLockTime = chainActive.Tip()->nHeight + 1; | ||||
txid = tx.GetId(); | txid = tx.GetId(); | ||||
g_mempool.addUnchecked(txid, entry.Time(GetTime()).FromTx(tx)); | g_mempool.addUnchecked(txid, entry.Time(GetTime()).FromTx(tx)); | ||||
{ | { | ||||
// Locktime fails. | // Locktime fails. | ||||
CValidationState state; | CValidationState state; | ||||
BOOST_CHECK(!ContextualCheckTransactionForCurrentBlock( | BOOST_CHECK(!ContextualCheckTransactionForCurrentBlock( | ||||
config, 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; | CValidationState state; | ||||
int64_t nMedianTimePast = chainActive.Tip()->GetMedianTimePast(); | int64_t nMedianTimePast = chainActive.Tip()->GetMedianTimePast(); | ||||
BOOST_CHECK(ContextualCheckTransaction( | BOOST_CHECK(ContextualCheckTransaction( | ||||
config, 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(); | ||||
g_mempool.addUnchecked(txid, entry.Time(GetTime()).FromTx(tx)); | g_mempool.addUnchecked(txid, entry.Time(GetTime()).FromTx(tx)); | ||||
{ | { | ||||
// Locktime fails. | // Locktime fails. | ||||
CValidationState state; | CValidationState state; | ||||
BOOST_CHECK(!ContextualCheckTransactionForCurrentBlock( | BOOST_CHECK(!ContextualCheckTransactionForCurrentBlock( | ||||
config, 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; | CValidationState state; | ||||
int64_t nMedianTimePast = chainActive.Tip()->GetMedianTimePast() + 1; | int64_t nMedianTimePast = chainActive.Tip()->GetMedianTimePast() + 1; | ||||
BOOST_CHECK(ContextualCheckTransaction( | BOOST_CHECK(ContextualCheckTransaction( | ||||
config, 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; | CValidationState state; | ||||
BOOST_CHECK(ContextualCheckTransactionForCurrentBlock( | BOOST_CHECK(ContextualCheckTransactionForCurrentBlock( | ||||
config, 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. | ||||
BOOST_CHECK(!TestSequenceLocks(CTransaction(tx), flags)); | BOOST_CHECK(!TestSequenceLocks(CTransaction(tx), flags)); | ||||
tx.vin[0].nSequence = CTxIn::SEQUENCE_LOCKTIME_TYPE_FLAG; | tx.vin[0].nSequence = CTxIn::SEQUENCE_LOCKTIME_TYPE_FLAG; | ||||
▲ Show 20 Lines • Show All 98 Lines • Show Last 20 Lines |