Changeset View
Changeset View
Standalone View
Standalone View
src/test/miner_tests.cpp
Show First 20 Lines • Show All 249 Lines • ▼ Show 20 Lines | BOOST_AUTO_TEST_CASE(CreateNewBlock_validity) { | ||||
CScript scriptPubKey = | CScript scriptPubKey = | ||||
CScript() << ParseHex("04678afdb0fe5548271967f1a67130b7105cd6a828e03909" | CScript() << ParseHex("04678afdb0fe5548271967f1a67130b7105cd6a828e03909" | ||||
"a67962e0ea1f61deb649f6bc3f4cef38c4f35504e51ec112" | "a67962e0ea1f61deb649f6bc3f4cef38c4f35504e51ec112" | ||||
"de5c384df7ba0b8d578a4c702b6bf11d5f") | "de5c384df7ba0b8d578a4c702b6bf11d5f") | ||||
<< OP_CHECKSIG; | << OP_CHECKSIG; | ||||
std::unique_ptr<CBlockTemplate> pblocktemplate; | std::unique_ptr<CBlockTemplate> pblocktemplate; | ||||
CMutableTransaction tx, tx2; | CMutableTransaction tx, tx2; | ||||
CScript script; | CScript script; | ||||
uint256 hash; | |||||
TestMemPoolEntryHelper entry; | TestMemPoolEntryHelper entry; | ||||
entry.nFee = 11 * SATOSHI; | entry.nFee = 11 * SATOSHI; | ||||
entry.dPriority = 111.0; | entry.dPriority = 111.0; | ||||
entry.nHeight = 11; | entry.nHeight = 11; | ||||
fCheckpointsEnabled = false; | fCheckpointsEnabled = false; | ||||
GlobalConfig config; | GlobalConfig config; | ||||
▲ Show 20 Lines • Show All 54 Lines • ▼ Show 20 Lines | BOOST_AUTO_TEST_CASE(CreateNewBlock_validity) { | ||||
// NOTE: OP_NOP is used to force 20 SigOps for the CHECKMULTISIG | // NOTE: OP_NOP is used to force 20 SigOps for the CHECKMULTISIG | ||||
tx.vin[0].scriptSig = CScript() << OP_0 << OP_0 << OP_0 << OP_NOP | tx.vin[0].scriptSig = CScript() << OP_0 << OP_0 << OP_0 << OP_NOP | ||||
<< OP_CHECKMULTISIG << OP_1; | << OP_CHECKMULTISIG << OP_1; | ||||
tx.vin[0].prevout = COutPoint(txFirst[0]->GetId(), 0); | tx.vin[0].prevout = COutPoint(txFirst[0]->GetId(), 0); | ||||
tx.vout.resize(1); | tx.vout.resize(1); | ||||
tx.vout[0].nValue = BLOCKSUBSIDY; | tx.vout[0].nValue = BLOCKSUBSIDY; | ||||
for (unsigned int i = 0; i < 1001; ++i) { | for (unsigned int i = 0; i < 1001; ++i) { | ||||
tx.vout[0].nValue -= LOWFEE; | tx.vout[0].nValue -= LOWFEE; | ||||
hash = tx.GetId(); | const TxId txid = tx.GetId(); | ||||
// Only first tx spends coinbase. | // Only first tx spends coinbase. | ||||
bool spendsCoinbase = i == 0; | bool spendsCoinbase = i == 0; | ||||
// If we don't set the # of sig ops in the CTxMemPoolEntry, template | // If we don't set the # of sig ops in the CTxMemPoolEntry, template | ||||
// creation fails. | // creation fails. | ||||
g_mempool.addUnchecked(hash, entry.Fee(LOWFEE) | g_mempool.addUnchecked(txid, entry.Fee(LOWFEE) | ||||
.Time(GetTime()) | .Time(GetTime()) | ||||
.SpendsCoinbase(spendsCoinbase) | .SpendsCoinbase(spendsCoinbase) | ||||
.FromTx(tx)); | .FromTx(tx)); | ||||
tx.vin[0].prevout = COutPoint(hash, 0); | tx.vin[0].prevout = COutPoint(txid, 0); | ||||
} | } | ||||
BOOST_CHECK_THROW( | BOOST_CHECK_THROW( | ||||
BlockAssembler(config, g_mempool).CreateNewBlock(scriptPubKey), | BlockAssembler(config, g_mempool).CreateNewBlock(scriptPubKey), | ||||
std::runtime_error); | std::runtime_error); | ||||
g_mempool.clear(); | g_mempool.clear(); | ||||
tx.vin[0].prevout = COutPoint(txFirst[0]->GetId(), 0); | tx.vin[0].prevout = COutPoint(txFirst[0]->GetId(), 0); | ||||
tx.vout[0].nValue = BLOCKSUBSIDY; | tx.vout[0].nValue = BLOCKSUBSIDY; | ||||
for (unsigned int i = 0; i < 1001; ++i) { | for (unsigned int i = 0; i < 1001; ++i) { | ||||
tx.vout[0].nValue -= LOWFEE; | tx.vout[0].nValue -= LOWFEE; | ||||
hash = tx.GetId(); | const TxId txid = tx.GetId(); | ||||
// Only first tx spends coinbase. | // Only first tx spends coinbase. | ||||
bool spendsCoinbase = i == 0; | bool spendsCoinbase = i == 0; | ||||
// If we do set the # of sig ops in the CTxMemPoolEntry, template | // If we do set the # of sig ops in the CTxMemPoolEntry, template | ||||
// creation passes. | // creation passes. | ||||
g_mempool.addUnchecked(hash, entry.Fee(LOWFEE) | g_mempool.addUnchecked(txid, entry.Fee(LOWFEE) | ||||
.Time(GetTime()) | .Time(GetTime()) | ||||
.SpendsCoinbase(spendsCoinbase) | .SpendsCoinbase(spendsCoinbase) | ||||
.SigOpsCost(80) | .SigOpsCost(80) | ||||
.FromTx(tx)); | .FromTx(tx)); | ||||
tx.vin[0].prevout = COutPoint(hash, 0); | tx.vin[0].prevout = COutPoint(txid, 0); | ||||
} | } | ||||
BOOST_CHECK( | BOOST_CHECK( | ||||
pblocktemplate = | pblocktemplate = | ||||
BlockAssembler(config, g_mempool).CreateNewBlock(scriptPubKey)); | BlockAssembler(config, g_mempool).CreateNewBlock(scriptPubKey)); | ||||
g_mempool.clear(); | g_mempool.clear(); | ||||
// block size > limit | // block size > limit | ||||
tx.vin[0].scriptSig = CScript(); | tx.vin[0].scriptSig = CScript(); | ||||
// 18 * (520char + DROP) + OP_1 = 9433 bytes | // 18 * (520char + DROP) + OP_1 = 9433 bytes | ||||
std::vector<uint8_t> vchData(520); | std::vector<uint8_t> vchData(520); | ||||
for (unsigned int i = 0; i < 18; ++i) { | for (unsigned int i = 0; i < 18; ++i) { | ||||
tx.vin[0].scriptSig << vchData << OP_DROP; | tx.vin[0].scriptSig << vchData << OP_DROP; | ||||
} | } | ||||
tx.vin[0].scriptSig << OP_1; | tx.vin[0].scriptSig << OP_1; | ||||
tx.vin[0].prevout = COutPoint(txFirst[0]->GetId(), 0); | tx.vin[0].prevout = COutPoint(txFirst[0]->GetId(), 0); | ||||
tx.vout[0].nValue = BLOCKSUBSIDY; | tx.vout[0].nValue = BLOCKSUBSIDY; | ||||
for (unsigned int i = 0; i < 128; ++i) { | for (unsigned int i = 0; i < 128; ++i) { | ||||
tx.vout[0].nValue -= LOWFEE; | tx.vout[0].nValue -= LOWFEE; | ||||
hash = tx.GetId(); | const TxId txid = tx.GetId(); | ||||
// Only first tx spends coinbase. | // Only first tx spends coinbase. | ||||
bool spendsCoinbase = i == 0; | bool spendsCoinbase = i == 0; | ||||
g_mempool.addUnchecked(hash, entry.Fee(LOWFEE) | g_mempool.addUnchecked(txid, entry.Fee(LOWFEE) | ||||
.Time(GetTime()) | .Time(GetTime()) | ||||
.SpendsCoinbase(spendsCoinbase) | .SpendsCoinbase(spendsCoinbase) | ||||
.FromTx(tx)); | .FromTx(tx)); | ||||
tx.vin[0].prevout = COutPoint(hash, 0); | tx.vin[0].prevout = COutPoint(txid, 0); | ||||
} | } | ||||
BOOST_CHECK( | BOOST_CHECK( | ||||
pblocktemplate = | pblocktemplate = | ||||
BlockAssembler(config, g_mempool).CreateNewBlock(scriptPubKey)); | BlockAssembler(config, g_mempool).CreateNewBlock(scriptPubKey)); | ||||
g_mempool.clear(); | g_mempool.clear(); | ||||
// Orphan in mempool, template creation fails. | // Orphan in mempool, template creation fails. | ||||
hash = tx.GetId(); | TxId txid = tx.GetId(); | ||||
g_mempool.addUnchecked(hash, entry.Fee(LOWFEE).Time(GetTime()).FromTx(tx)); | g_mempool.addUnchecked(txid, entry.Fee(LOWFEE).Time(GetTime()).FromTx(tx)); | ||||
BOOST_CHECK_THROW( | BOOST_CHECK_THROW( | ||||
BlockAssembler(config, g_mempool).CreateNewBlock(scriptPubKey), | BlockAssembler(config, g_mempool).CreateNewBlock(scriptPubKey), | ||||
std::runtime_error); | std::runtime_error); | ||||
g_mempool.clear(); | g_mempool.clear(); | ||||
// Child with higher priority than parent. | // Child with higher priority than parent. | ||||
tx.vin[0].scriptSig = CScript() << OP_1; | tx.vin[0].scriptSig = CScript() << OP_1; | ||||
tx.vin[0].prevout = COutPoint(txFirst[1]->GetId(), 0); | tx.vin[0].prevout = COutPoint(txFirst[1]->GetId(), 0); | ||||
tx.vout[0].nValue = BLOCKSUBSIDY - HIGHFEE; | tx.vout[0].nValue = BLOCKSUBSIDY - HIGHFEE; | ||||
hash = tx.GetId(); | txid = tx.GetId(); | ||||
g_mempool.addUnchecked( | g_mempool.addUnchecked( | ||||
hash, | txid, | ||||
entry.Fee(HIGHFEE).Time(GetTime()).SpendsCoinbase(true).FromTx(tx)); | entry.Fee(HIGHFEE).Time(GetTime()).SpendsCoinbase(true).FromTx(tx)); | ||||
tx.vin[0].prevout = COutPoint(hash, 0); | tx.vin[0].prevout = COutPoint(txid, 0); | ||||
tx.vin.resize(2); | tx.vin.resize(2); | ||||
tx.vin[1].scriptSig = CScript() << OP_1; | tx.vin[1].scriptSig = CScript() << OP_1; | ||||
tx.vin[1].prevout = COutPoint(txFirst[0]->GetId(), 0); | tx.vin[1].prevout = COutPoint(txFirst[0]->GetId(), 0); | ||||
// First txn output + fresh coinbase - new txn fee. | // First txn output + fresh coinbase - new txn fee. | ||||
tx.vout[0].nValue = tx.vout[0].nValue + BLOCKSUBSIDY - HIGHERFEE; | tx.vout[0].nValue = tx.vout[0].nValue + BLOCKSUBSIDY - HIGHERFEE; | ||||
hash = tx.GetId(); | txid = tx.GetId(); | ||||
g_mempool.addUnchecked( | g_mempool.addUnchecked( | ||||
hash, | txid, | ||||
entry.Fee(HIGHERFEE).Time(GetTime()).SpendsCoinbase(true).FromTx(tx)); | entry.Fee(HIGHERFEE).Time(GetTime()).SpendsCoinbase(true).FromTx(tx)); | ||||
BOOST_CHECK( | BOOST_CHECK( | ||||
pblocktemplate = | pblocktemplate = | ||||
BlockAssembler(config, g_mempool).CreateNewBlock(scriptPubKey)); | BlockAssembler(config, g_mempool).CreateNewBlock(scriptPubKey)); | ||||
g_mempool.clear(); | g_mempool.clear(); | ||||
// Coinbase in mempool, template creation fails. | // Coinbase in mempool, template creation fails. | ||||
tx.vin.resize(1); | tx.vin.resize(1); | ||||
tx.vin[0].prevout = COutPoint(); | tx.vin[0].prevout = COutPoint(); | ||||
tx.vin[0].scriptSig = CScript() << OP_0 << OP_1; | tx.vin[0].scriptSig = CScript() << OP_0 << OP_1; | ||||
tx.vout[0].nValue = Amount::zero(); | tx.vout[0].nValue = Amount::zero(); | ||||
hash = tx.GetId(); | txid = tx.GetId(); | ||||
// Give it a fee so it'll get mined. | // Give it a fee so it'll get mined. | ||||
g_mempool.addUnchecked( | g_mempool.addUnchecked( | ||||
hash, | txid, | ||||
entry.Fee(LOWFEE).Time(GetTime()).SpendsCoinbase(false).FromTx(tx)); | entry.Fee(LOWFEE).Time(GetTime()).SpendsCoinbase(false).FromTx(tx)); | ||||
BOOST_CHECK_THROW( | BOOST_CHECK_THROW( | ||||
BlockAssembler(config, g_mempool).CreateNewBlock(scriptPubKey), | BlockAssembler(config, g_mempool).CreateNewBlock(scriptPubKey), | ||||
std::runtime_error); | std::runtime_error); | ||||
g_mempool.clear(); | g_mempool.clear(); | ||||
// Double spend txn pair in mempool, template creation fails. | // Double spend txn pair in mempool, template creation fails. | ||||
tx.vin[0].prevout = COutPoint(txFirst[0]->GetId(), 0); | tx.vin[0].prevout = COutPoint(txFirst[0]->GetId(), 0); | ||||
tx.vin[0].scriptSig = CScript() << OP_1; | tx.vin[0].scriptSig = CScript() << OP_1; | ||||
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; | ||||
hash = tx.GetId(); | txid = tx.GetId(); | ||||
g_mempool.addUnchecked( | g_mempool.addUnchecked( | ||||
hash, | txid, | ||||
entry.Fee(HIGHFEE).Time(GetTime()).SpendsCoinbase(true).FromTx(tx)); | entry.Fee(HIGHFEE).Time(GetTime()).SpendsCoinbase(true).FromTx(tx)); | ||||
tx.vout[0].scriptPubKey = CScript() << OP_2; | tx.vout[0].scriptPubKey = CScript() << OP_2; | ||||
hash = tx.GetId(); | txid = tx.GetId(); | ||||
g_mempool.addUnchecked( | g_mempool.addUnchecked( | ||||
hash, | txid, | ||||
entry.Fee(HIGHFEE).Time(GetTime()).SpendsCoinbase(true).FromTx(tx)); | entry.Fee(HIGHFEE).Time(GetTime()).SpendsCoinbase(true).FromTx(tx)); | ||||
BOOST_CHECK_THROW( | BOOST_CHECK_THROW( | ||||
BlockAssembler(config, g_mempool).CreateNewBlock(scriptPubKey), | BlockAssembler(config, g_mempool).CreateNewBlock(scriptPubKey), | ||||
std::runtime_error); | std::runtime_error); | ||||
g_mempool.clear(); | g_mempool.clear(); | ||||
// Subsidy changing. | // Subsidy changing. | ||||
int nHeight = chainActive.Height(); | int nHeight = chainActive.Height(); | ||||
Show All 27 Lines | BOOST_CHECK( | ||||
BlockAssembler(config, g_mempool).CreateNewBlock(scriptPubKey)); | BlockAssembler(config, g_mempool).CreateNewBlock(scriptPubKey)); | ||||
// Invalid p2sh txn in mempool, template creation fails | // Invalid p2sh txn in mempool, template creation fails | ||||
tx.vin[0].prevout = COutPoint(txFirst[0]->GetId(), 0); | tx.vin[0].prevout = COutPoint(txFirst[0]->GetId(), 0); | ||||
tx.vin[0].scriptSig = CScript() << OP_1; | tx.vin[0].scriptSig = CScript() << OP_1; | ||||
tx.vout[0].nValue = BLOCKSUBSIDY - LOWFEE; | tx.vout[0].nValue = BLOCKSUBSIDY - LOWFEE; | ||||
script = CScript() << OP_0; | script = CScript() << OP_0; | ||||
tx.vout[0].scriptPubKey = GetScriptForDestination(CScriptID(script)); | tx.vout[0].scriptPubKey = GetScriptForDestination(CScriptID(script)); | ||||
hash = tx.GetId(); | txid = tx.GetId(); | ||||
g_mempool.addUnchecked( | g_mempool.addUnchecked( | ||||
hash, | txid, | ||||
entry.Fee(LOWFEE).Time(GetTime()).SpendsCoinbase(true).FromTx(tx)); | entry.Fee(LOWFEE).Time(GetTime()).SpendsCoinbase(true).FromTx(tx)); | ||||
tx.vin[0].prevout = COutPoint(hash, 0); | tx.vin[0].prevout = COutPoint(txid, 0); | ||||
tx.vin[0].scriptSig = CScript() | tx.vin[0].scriptSig = CScript() | ||||
<< std::vector<uint8_t>(script.begin(), script.end()); | << std::vector<uint8_t>(script.begin(), script.end()); | ||||
tx.vout[0].nValue -= LOWFEE; | tx.vout[0].nValue -= LOWFEE; | ||||
hash = tx.GetId(); | txid = tx.GetId(); | ||||
g_mempool.addUnchecked( | g_mempool.addUnchecked( | ||||
hash, | txid, | ||||
entry.Fee(LOWFEE).Time(GetTime()).SpendsCoinbase(false).FromTx(tx)); | entry.Fee(LOWFEE).Time(GetTime()).SpendsCoinbase(false).FromTx(tx)); | ||||
BOOST_CHECK_THROW( | BOOST_CHECK_THROW( | ||||
BlockAssembler(config, g_mempool).CreateNewBlock(scriptPubKey), | BlockAssembler(config, g_mempool).CreateNewBlock(scriptPubKey), | ||||
std::runtime_error); | std::runtime_error); | ||||
g_mempool.clear(); | g_mempool.clear(); | ||||
// Delete the dummy blocks again. | // Delete the dummy blocks again. | ||||
while (chainActive.Tip()->nHeight > nHeight) { | while (chainActive.Tip()->nHeight > nHeight) { | ||||
Show All 19 Lines | BOOST_AUTO_TEST_CASE(CreateNewBlock_validity) { | ||||
tx.vin[0].scriptSig = CScript() << OP_1; | tx.vin[0].scriptSig = CScript() << OP_1; | ||||
// txFirst[0] is the 2nd block | // txFirst[0] is the 2nd block | ||||
tx.vin[0].nSequence = chainActive.Tip()->nHeight + 1; | tx.vin[0].nSequence = chainActive.Tip()->nHeight + 1; | ||||
prevheights[0] = baseheight + 1; | prevheights[0] = baseheight + 1; | ||||
tx.vout.resize(1); | tx.vout.resize(1); | ||||
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; | ||||
hash = tx.GetId(); | txid = tx.GetId(); | ||||
g_mempool.addUnchecked( | g_mempool.addUnchecked( | ||||
hash, | txid, | ||||
entry.Fee(HIGHFEE).Time(GetTime()).SpendsCoinbase(true).FromTx(tx)); | entry.Fee(HIGHFEE).Time(GetTime()).SpendsCoinbase(true).FromTx(tx)); | ||||
{ | { | ||||
// Locktime passes. | // Locktime passes. | ||||
CValidationState state; | CValidationState state; | ||||
BOOST_CHECK(ContextualCheckTransactionForCurrentBlock( | BOOST_CHECK(ContextualCheckTransactionForCurrentBlock( | ||||
config, CTransaction(tx), state, flags)); | config, CTransaction(tx), state, flags)); | ||||
} | } | ||||
Show All 9 Lines | BOOST_AUTO_TEST_CASE(CreateNewBlock_validity) { | ||||
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) + | ||||
1); | 1); | ||||
prevheights[0] = baseheight + 2; | prevheights[0] = baseheight + 2; | ||||
hash = tx.GetId(); | txid = tx.GetId(); | ||||
g_mempool.addUnchecked(hash, 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)); | config, CTransaction(tx), state, flags)); | ||||
} | } | ||||
Show All 15 Lines | for (int i = 0; i < CBlockIndex::nMedianTimeSpan; i++) { | ||||
512; | 512; | ||||
} | } | ||||
// Absolute height locked. | // Absolute height locked. | ||||
tx.vin[0].prevout = COutPoint(txFirst[2]->GetId(), 0); | tx.vin[0].prevout = COutPoint(txFirst[2]->GetId(), 0); | ||||
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; | ||||
hash = tx.GetId(); | txid = tx.GetId(); | ||||
g_mempool.addUnchecked(hash, 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)); | config, CTransaction(tx), state, flags)); | ||||
BOOST_CHECK_EQUAL(state.GetRejectReason(), "bad-txns-nonfinal"); | BOOST_CHECK_EQUAL(state.GetRejectReason(), "bad-txns-nonfinal"); | ||||
} | } | ||||
Show All 10 Lines | BOOST_CHECK(TestSequenceLocks(CTransaction(tx), flags)); | ||||
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; | ||||
hash = tx.GetId(); | txid = tx.GetId(); | ||||
g_mempool.addUnchecked(hash, 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)); | config, 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, | config, 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(hash, 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( | ||||
▲ Show 20 Lines • Show All 107 Lines • Show Last 20 Lines |