Changeset View
Changeset View
Standalone View
Standalone View
src/test/miner_tests.cpp
Show First 20 Lines • Show All 82 Lines • ▼ Show 20 Lines | static struct { | ||||
{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 index; | CBlockIndex index; | ||||
index.nHeight = nHeight; | index.nHeight = nHeight; | ||||
index.pprev = chainActive.Tip(); | index.pprev = ::ChainActive().Tip(); | ||||
return index; | return index; | ||||
} | } | ||||
static bool TestSequenceLocks(const CTransaction &tx, int flags) | static bool TestSequenceLocks(const CTransaction &tx, int flags) | ||||
EXCLUSIVE_LOCKS_REQUIRED(cs_main) { | EXCLUSIVE_LOCKS_REQUIRED(cs_main) { | ||||
LOCK(::g_mempool.cs); | LOCK(::g_mempool.cs); | ||||
return CheckSequenceLocks(::g_mempool, tx, flags); | return CheckSequenceLocks(::g_mempool, tx, flags); | ||||
} | } | ||||
▲ Show 20 Lines • Show All 139 Lines • ▼ Show 20 Lines | void TestCoinbaseMessageEB(uint64_t eb, std::string cbmsg) { | ||||
std::unique_ptr<CBlockTemplate> pblocktemplate = | std::unique_ptr<CBlockTemplate> pblocktemplate = | ||||
BlockAssembler(config, g_mempool).CreateNewBlock(scriptPubKey); | BlockAssembler(config, g_mempool).CreateNewBlock(scriptPubKey); | ||||
CBlock *pblock = &pblocktemplate->block; | CBlock *pblock = &pblocktemplate->block; | ||||
// IncrementExtraNonce creates a valid coinbase and merkleRoot | // IncrementExtraNonce creates a valid coinbase and merkleRoot | ||||
unsigned int extraNonce = 0; | unsigned int extraNonce = 0; | ||||
IncrementExtraNonce(pblock, chainActive.Tip(), config.GetMaxBlockSize(), | IncrementExtraNonce(pblock, ::ChainActive().Tip(), config.GetMaxBlockSize(), | ||||
extraNonce); | extraNonce); | ||||
unsigned int nHeight = chainActive.Tip()->nHeight + 1; | unsigned int nHeight = ::ChainActive().Tip()->nHeight + 1; | ||||
std::vector<uint8_t> vec(cbmsg.begin(), cbmsg.end()); | std::vector<uint8_t> vec(cbmsg.begin(), cbmsg.end()); | ||||
BOOST_CHECK(pblock->vtx[0]->vin[0].scriptSig == | BOOST_CHECK(pblock->vtx[0]->vin[0].scriptSig == | ||||
((CScript() << nHeight << CScriptNum(extraNonce) << vec) + | ((CScript() << nHeight << CScriptNum(extraNonce) << vec) + | ||||
COINBASE_FLAGS)); | COINBASE_FLAGS)); | ||||
} | } | ||||
// Coinbase scriptSig has to contains the correct EB value | // Coinbase scriptSig has to contains the correct EB value | ||||
// converted to MB, rounded down to the first decimal | // converted to MB, rounded down to the first decimal | ||||
Show All 32 Lines | BOOST_AUTO_TEST_CASE(CreateNewBlock_validity) { | ||||
int baseheight = 0; | int baseheight = 0; | ||||
std::vector<CTransactionRef> txFirst; | std::vector<CTransactionRef> txFirst; | ||||
for (size_t i = 0; i < sizeof(blockinfo) / sizeof(*blockinfo); ++i) { | for (size_t i = 0; i < sizeof(blockinfo) / sizeof(*blockinfo); ++i) { | ||||
// pointer for convenience. | // pointer for convenience. | ||||
CBlock *pblock = &pblocktemplate->block; | CBlock *pblock = &pblocktemplate->block; | ||||
{ | { | ||||
LOCK(cs_main); | LOCK(cs_main); | ||||
pblock->nVersion = 1; | pblock->nVersion = 1; | ||||
pblock->nTime = chainActive.Tip()->GetMedianTimePast() + 1; | pblock->nTime = ::ChainActive().Tip()->GetMedianTimePast() + 1; | ||||
CMutableTransaction txCoinbase(*pblock->vtx[0]); | CMutableTransaction txCoinbase(*pblock->vtx[0]); | ||||
txCoinbase.nVersion = 1; | txCoinbase.nVersion = 1; | ||||
txCoinbase.vin[0].scriptSig = CScript(); | txCoinbase.vin[0].scriptSig = CScript(); | ||||
txCoinbase.vin[0].scriptSig.push_back(blockinfo[i].extranonce); | txCoinbase.vin[0].scriptSig.push_back(blockinfo[i].extranonce); | ||||
txCoinbase.vin[0].scriptSig.push_back(chainActive.Height()); | txCoinbase.vin[0].scriptSig.push_back(::ChainActive().Height()); | ||||
txCoinbase.vout.resize(1); | txCoinbase.vout.resize(1); | ||||
txCoinbase.vout[0].scriptPubKey = CScript(); | txCoinbase.vout[0].scriptPubKey = CScript(); | ||||
pblock->vtx[0] = MakeTransactionRef(std::move(txCoinbase)); | pblock->vtx[0] = MakeTransactionRef(std::move(txCoinbase)); | ||||
if (txFirst.size() == 0) { | if (txFirst.size() == 0) { | ||||
baseheight = chainActive.Height(); | baseheight = ::ChainActive().Height(); | ||||
} | } | ||||
if (txFirst.size() < 4) { | if (txFirst.size() < 4) { | ||||
txFirst.push_back(pblock->vtx[0]); | txFirst.push_back(pblock->vtx[0]); | ||||
} | } | ||||
pblock->hashMerkleRoot = BlockMerkleRoot(*pblock); | pblock->hashMerkleRoot = BlockMerkleRoot(*pblock); | ||||
pblock->nNonce = blockinfo[i].nonce; | pblock->nNonce = blockinfo[i].nonce; | ||||
} | } | ||||
std::shared_ptr<const CBlock> shared_pblock = | std::shared_ptr<const CBlock> shared_pblock = | ||||
▲ Show 20 Lines • Show All 144 Lines • ▼ Show 20 Lines | BOOST_AUTO_TEST_CASE(CreateNewBlock_validity) { | ||||
g_mempool.addUnchecked( | g_mempool.addUnchecked( | ||||
entry.Fee(HIGHFEE).Time(GetTime()).SpendsCoinbase(true).FromTx(tx)); | entry.Fee(HIGHFEE).Time(GetTime()).SpendsCoinbase(true).FromTx(tx)); | ||||
BOOST_CHECK_EXCEPTION( | BOOST_CHECK_EXCEPTION( | ||||
AssemblerForTest(chainparams, g_mempool).CreateNewBlock(scriptPubKey), | AssemblerForTest(chainparams, g_mempool).CreateNewBlock(scriptPubKey), | ||||
std::runtime_error, HasReason("bad-txns-inputs-missingorspent")); | std::runtime_error, HasReason("bad-txns-inputs-missingorspent")); | ||||
g_mempool.clear(); | g_mempool.clear(); | ||||
// Subsidy changing. | // Subsidy changing. | ||||
int nHeight = chainActive.Height(); | int nHeight = ::ChainActive().Height(); | ||||
// Create an actual 209999-long block chain (without valid blocks). | // Create an actual 209999-long block chain (without valid blocks). | ||||
while (chainActive.Tip()->nHeight < 209999) { | while (::ChainActive().Tip()->nHeight < 209999) { | ||||
CBlockIndex *prev = chainActive.Tip(); | CBlockIndex *prev = ::ChainActive().Tip(); | ||||
CBlockIndex *next = new CBlockIndex(); | CBlockIndex *next = new CBlockIndex(); | ||||
next->phashBlock = new BlockHash(InsecureRand256()); | next->phashBlock = new BlockHash(InsecureRand256()); | ||||
pcoinsTip->SetBestBlock(next->GetBlockHash()); | pcoinsTip->SetBestBlock(next->GetBlockHash()); | ||||
next->pprev = prev; | next->pprev = prev; | ||||
next->nHeight = prev->nHeight + 1; | next->nHeight = prev->nHeight + 1; | ||||
next->BuildSkip(); | next->BuildSkip(); | ||||
chainActive.SetTip(next); | ::ChainActive().SetTip(next); | ||||
} | } | ||||
BOOST_CHECK(pblocktemplate = AssemblerForTest(chainparams, g_mempool) | BOOST_CHECK(pblocktemplate = AssemblerForTest(chainparams, g_mempool) | ||||
.CreateNewBlock(scriptPubKey)); | .CreateNewBlock(scriptPubKey)); | ||||
// Extend to a 210000-long block chain. | // Extend to a 210000-long block chain. | ||||
while (chainActive.Tip()->nHeight < 210000) { | while (::ChainActive().Tip()->nHeight < 210000) { | ||||
CBlockIndex *prev = chainActive.Tip(); | CBlockIndex *prev = ::ChainActive().Tip(); | ||||
CBlockIndex *next = new CBlockIndex(); | CBlockIndex *next = new CBlockIndex(); | ||||
next->phashBlock = new BlockHash(InsecureRand256()); | next->phashBlock = new BlockHash(InsecureRand256()); | ||||
pcoinsTip->SetBestBlock(next->GetBlockHash()); | pcoinsTip->SetBestBlock(next->GetBlockHash()); | ||||
next->pprev = prev; | next->pprev = prev; | ||||
next->nHeight = prev->nHeight + 1; | next->nHeight = prev->nHeight + 1; | ||||
next->BuildSkip(); | next->BuildSkip(); | ||||
chainActive.SetTip(next); | ::ChainActive().SetTip(next); | ||||
} | } | ||||
BOOST_CHECK(pblocktemplate = AssemblerForTest(chainparams, g_mempool) | BOOST_CHECK(pblocktemplate = AssemblerForTest(chainparams, g_mempool) | ||||
.CreateNewBlock(scriptPubKey)); | .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; | ||||
Show All 12 Lines | g_mempool.addUnchecked( | ||||
entry.Fee(LOWFEE).Time(GetTime()).SpendsCoinbase(false).FromTx(tx)); | entry.Fee(LOWFEE).Time(GetTime()).SpendsCoinbase(false).FromTx(tx)); | ||||
// Should throw blk-bad-inputs | // Should throw blk-bad-inputs | ||||
BOOST_CHECK_EXCEPTION( | BOOST_CHECK_EXCEPTION( | ||||
AssemblerForTest(chainparams, g_mempool).CreateNewBlock(scriptPubKey), | AssemblerForTest(chainparams, g_mempool).CreateNewBlock(scriptPubKey), | ||||
std::runtime_error, HasReason("blk-bad-inputs")); | std::runtime_error, HasReason("blk-bad-inputs")); | ||||
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) { | ||||
CBlockIndex *del = chainActive.Tip(); | CBlockIndex *del = ::ChainActive().Tip(); | ||||
chainActive.SetTip(del->pprev); | ::ChainActive().SetTip(del->pprev); | ||||
pcoinsTip->SetBestBlock(del->pprev->GetBlockHash()); | pcoinsTip->SetBestBlock(del->pprev->GetBlockHash()); | ||||
delete del->phashBlock; | delete del->phashBlock; | ||||
delete del; | delete del; | ||||
} | } | ||||
// non-final txs in mempool | // non-final txs in mempool | ||||
SetMockTime(chainActive.Tip()->GetMedianTimePast() + 1); | SetMockTime(::ChainActive().Tip()->GetMedianTimePast() + 1); | ||||
uint32_t flags = LOCKTIME_VERIFY_SEQUENCE | LOCKTIME_MEDIAN_TIME_PAST; | uint32_t flags = LOCKTIME_VERIFY_SEQUENCE | LOCKTIME_MEDIAN_TIME_PAST; | ||||
// height map | // height map | ||||
std::vector<int> prevheights; | std::vector<int> prevheights; | ||||
// Relative height locked. | // Relative height locked. | ||||
tx.nVersion = 2; | tx.nVersion = 2; | ||||
tx.vin.resize(1); | tx.vin.resize(1); | ||||
prevheights.resize(1); | prevheights.resize(1); | ||||
// Only 1 transaction. | // Only 1 transaction. | ||||
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; | ||||
// 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; | ||||
txid = tx.GetId(); | txid = tx.GetId(); | ||||
g_mempool.addUnchecked( | g_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; | CValidationState 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( | ||||
SequenceLocks(CTransaction(tx), flags, &prevheights, | SequenceLocks(CTransaction(tx), flags, &prevheights, | ||||
CreateBlockIndex(chainActive.Tip()->nHeight + 2))); | CreateBlockIndex(::ChainActive().Tip()->nHeight + 2))); | ||||
// 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) + | ||||
1); | 1); | ||||
prevheights[0] = baseheight + 2; | prevheights[0] = baseheight + 2; | ||||
txid = tx.GetId(); | txid = tx.GetId(); | ||||
g_mempool.addUnchecked(entry.Time(GetTime()).FromTx(tx)); | g_mempool.addUnchecked(entry.Time(GetTime()).FromTx(tx)); | ||||
{ | { | ||||
// Locktime passes. | // Locktime passes. | ||||
CValidationState state; | CValidationState 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++) { | ||||
// Trick the MedianTimePast. | // Trick the MedianTimePast. | ||||
chainActive.Tip()->GetAncestor(chainActive.Tip()->nHeight - i)->nTime += | ::ChainActive() | ||||
512; | .Tip() | ||||
->GetAncestor(::ChainActive().Tip()->nHeight - i) | |||||
->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(::ChainActive().Tip()->nHeight + 1))); | ||||
for (int i = 0; i < CBlockIndex::nMedianTimeSpan; i++) { | for (int i = 0; i < CBlockIndex::nMedianTimeSpan; i++) { | ||||
// Undo tricked MTP. | // Undo tricked MTP. | ||||
chainActive.Tip()->GetAncestor(chainActive.Tip()->nHeight - i)->nTime -= | ::ChainActive() | ||||
512; | .Tip() | ||||
->GetAncestor(::ChainActive().Tip()->nHeight - i) | |||||
->nTime -= 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; | ||||
txid = tx.GetId(); | txid = tx.GetId(); | ||||
g_mempool.addUnchecked(entry.Time(GetTime()).FromTx(tx)); | g_mempool.addUnchecked(entry.Time(GetTime()).FromTx(tx)); | ||||
{ | { | ||||
// Locktime fails. | // Locktime fails. | ||||
CValidationState state; | CValidationState 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; | CValidationState 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(); | ||||
g_mempool.addUnchecked(entry.Time(GetTime()).FromTx(tx)); | g_mempool.addUnchecked(entry.Time(GetTime()).FromTx(tx)); | ||||
{ | { | ||||
// Locktime fails. | // Locktime fails. | ||||
CValidationState state; | CValidationState 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; | CValidationState state; | ||||
int64_t nMedianTimePast = chainActive.Tip()->GetMedianTimePast() + 1; | int64_t nMedianTimePast = | ||||
::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; | CValidationState state; | ||||
BOOST_CHECK(ContextualCheckTransactionForCurrentBlock( | BOOST_CHECK(ContextualCheckTransactionForCurrentBlock( | ||||
params, CTransaction(tx), state, flags)); | params, CTransaction(tx), state, flags)); | ||||
Show All 19 Lines | BOOST_AUTO_TEST_CASE(CreateNewBlock_validity) { | ||||
// into the template because we still check IsFinalTx in CreateNewBlock, but | // into the template because we still check IsFinalTx in CreateNewBlock, but | ||||
// relative locked txs will if inconsistently added to g_mempool. For now | // relative locked txs will if inconsistently added to g_mempool. For now | ||||
// these will still generate a valid template until BIP68 soft fork. | // these will still generate a valid template until BIP68 soft fork. | ||||
BOOST_CHECK_EQUAL(pblocktemplate->block.vtx.size(), 3UL); | BOOST_CHECK_EQUAL(pblocktemplate->block.vtx.size(), 3UL); | ||||
// However if we advance height by 1 and time by 512, all of them should be | // However if we advance height by 1 and time by 512, all of them should be | ||||
// mined. | // mined. | ||||
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() | ||||
512; | .Tip() | ||||
->GetAncestor(::ChainActive().Tip()->nHeight - i) | |||||
->nTime += 512; | |||||
} | } | ||||
chainActive.Tip()->nHeight++; | ::ChainActive().Tip()->nHeight++; | ||||
SetMockTime(chainActive.Tip()->GetMedianTimePast() + 1); | SetMockTime(::ChainActive().Tip()->GetMedianTimePast() + 1); | ||||
BOOST_CHECK(pblocktemplate = AssemblerForTest(chainparams, g_mempool) | BOOST_CHECK(pblocktemplate = AssemblerForTest(chainparams, g_mempool) | ||||
.CreateNewBlock(scriptPubKey)); | .CreateNewBlock(scriptPubKey)); | ||||
BOOST_CHECK_EQUAL(pblocktemplate->block.vtx.size(), 5UL); | BOOST_CHECK_EQUAL(pblocktemplate->block.vtx.size(), 5UL); | ||||
chainActive.Tip()->nHeight--; | ::ChainActive().Tip()->nHeight--; | ||||
SetMockTime(0); | SetMockTime(0); | ||||
g_mempool.clear(); | g_mempool.clear(); | ||||
TestPackageSelection(chainparams, scriptPubKey, txFirst); | TestPackageSelection(chainparams, scriptPubKey, txFirst); | ||||
fCheckpointsEnabled = true; | fCheckpointsEnabled = true; | ||||
} | } | ||||
▲ Show 20 Lines • Show All 58 Lines • Show Last 20 Lines |