Changeset View
Changeset View
Standalone View
Standalone View
src/test/miner_tests.cpp
Show First 20 Lines • Show All 430 Lines • ▼ Show 20 Lines | BOOST_AUTO_TEST_CASE(CreateNewBlock_validity) { | ||||
g_mempool.addUnchecked( | g_mempool.addUnchecked( | ||||
hash, | hash, | ||||
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(); | ||||
// Invalid (pre-p2sh) txn in mempool, template creation fails. | |||||
std::array<int64_t, CBlockIndex::nMedianTimeSpan> times; | |||||
for (int i = 0; i < CBlockIndex::nMedianTimeSpan; i++) { | |||||
// Trick the MedianTimePast. | |||||
times[i] = chainActive.Tip() | |||||
->GetAncestor(chainActive.Tip()->nHeight - i) | |||||
->nTime; | |||||
chainActive.Tip()->GetAncestor(chainActive.Tip()->nHeight - i)->nTime = | |||||
P2SH_ACTIVATION_TIME; | |||||
} | |||||
tx.vin[0].prevout = COutPoint(txFirst[0]->GetId(), 0); | |||||
tx.vin[0].scriptSig = CScript() << OP_1; | |||||
tx.vout[0].nValue = BLOCKSUBSIDY - LOWFEE; | |||||
script = CScript() << OP_0; | |||||
tx.vout[0].scriptPubKey = GetScriptForDestination(CScriptID(script)); | |||||
hash = tx.GetId(); | |||||
g_mempool.addUnchecked( | |||||
hash, | |||||
entry.Fee(LOWFEE).Time(GetTime()).SpendsCoinbase(true).FromTx(tx)); | |||||
tx.vin[0].prevout = COutPoint(hash, 0); | |||||
tx.vin[0].scriptSig = CScript() | |||||
<< std::vector<uint8_t>(script.begin(), script.end()); | |||||
tx.vout[0].nValue -= LOWFEE; | |||||
hash = tx.GetId(); | |||||
g_mempool.addUnchecked( | |||||
hash, | |||||
entry.Fee(LOWFEE).Time(GetTime()).SpendsCoinbase(false).FromTx(tx)); | |||||
BOOST_CHECK_THROW( | |||||
BlockAssembler(config, g_mempool).CreateNewBlock(scriptPubKey), | |||||
std::runtime_error); | |||||
g_mempool.clear(); | |||||
for (int i = 0; i < CBlockIndex::nMedianTimeSpan; i++) { | |||||
// Restore the MedianTimePast. | |||||
chainActive.Tip()->GetAncestor(chainActive.Tip()->nHeight - i)->nTime = | |||||
times[i]; | |||||
} | |||||
// 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(); | hash = tx.GetId(); | ||||
g_mempool.addUnchecked( | g_mempool.addUnchecked( | ||||
hash, | hash, | ||||
Show All 33 Lines | while (chainActive.Tip()->nHeight < 210000) { | ||||
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( | BOOST_CHECK( | ||||
pblocktemplate = | pblocktemplate = | ||||
BlockAssembler(config, g_mempool).CreateNewBlock(scriptPubKey)); | BlockAssembler(config, g_mempool).CreateNewBlock(scriptPubKey)); | ||||
// Invalid p2sh txn in mempool, template creation fails | |||||
tx.vin[0].prevout = COutPoint(txFirst[0]->GetId(), 0); | |||||
tx.vin[0].scriptSig = CScript() << OP_1; | |||||
tx.vout[0].nValue = BLOCKSUBSIDY - LOWFEE; | |||||
script = CScript() << OP_0; | |||||
tx.vout[0].scriptPubKey = GetScriptForDestination(CScriptID(script)); | |||||
hash = tx.GetId(); | |||||
g_mempool.addUnchecked( | |||||
hash, | |||||
entry.Fee(LOWFEE).Time(GetTime()).SpendsCoinbase(true).FromTx(tx)); | |||||
tx.vin[0].prevout = COutPoint(hash, 0); | |||||
tx.vin[0].scriptSig = CScript() | |||||
<< std::vector<uint8_t>(script.begin(), script.end()); | |||||
tx.vout[0].nValue -= LOWFEE; | |||||
hash = tx.GetId(); | |||||
g_mempool.addUnchecked( | |||||
hash, | |||||
entry.Fee(LOWFEE).Time(GetTime()).SpendsCoinbase(false).FromTx(tx)); | |||||
BOOST_CHECK_THROW( | |||||
BlockAssembler(config, g_mempool).CreateNewBlock(scriptPubKey), | |||||
std::runtime_error); | |||||
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; | ||||
} | } | ||||
▲ Show 20 Lines • Show All 250 Lines • Show Last 20 Lines |