Changeset View
Changeset View
Standalone View
Standalone View
src/test/miner_tests.cpp
Show First 20 Lines • Show All 325 Lines • ▼ Show 20 Lines | BOOST_AUTO_TEST_CASE(CreateNewBlock_validity) { | ||||
BOOST_CHECK(pblocktemplate = AssemblerForTest(chainparams, g_mempool) | BOOST_CHECK(pblocktemplate = AssemblerForTest(chainparams, g_mempool) | ||||
.CreateNewBlock(scriptPubKey)); | .CreateNewBlock(scriptPubKey)); | ||||
const Amount BLOCKSUBSIDY = 50 * COIN; | const Amount BLOCKSUBSIDY = 50 * COIN; | ||||
const Amount LOWFEE = CENT; | const Amount LOWFEE = CENT; | ||||
const Amount HIGHFEE = COIN; | const Amount HIGHFEE = COIN; | ||||
const Amount HIGHERFEE = 4 * COIN; | const Amount HIGHERFEE = 4 * COIN; | ||||
// block sigops > limit: 1000 CHECKMULTISIG + 1 | |||||
tx.vin.resize(1); | |||||
// 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 | |||||
<< OP_CHECKMULTISIG << OP_1; | |||||
tx.vin[0].prevout = COutPoint(txFirst[0]->GetId(), 0); | |||||
tx.vout.resize(1); | |||||
tx.vout[0].nValue = BLOCKSUBSIDY; | |||||
for (unsigned int i = 0; i < 1001; ++i) { | |||||
tx.vout[0].nValue -= LOWFEE; | |||||
const TxId txid = tx.GetId(); | |||||
// Only first tx spends coinbase. | |||||
bool spendsCoinbase = i == 0; | |||||
// If we don't set the # of sig ops in the CTxMemPoolEntry, template | |||||
// creation fails. | |||||
g_mempool.addUnchecked(entry.Fee(LOWFEE) | |||||
.Time(GetTime()) | |||||
.SpendsCoinbase(spendsCoinbase) | |||||
.FromTx(tx)); | |||||
tx.vin[0].prevout = COutPoint(txid, 0); | |||||
} | |||||
BOOST_CHECK_EXCEPTION( | |||||
AssemblerForTest(chainparams, g_mempool).CreateNewBlock(scriptPubKey), | |||||
std::runtime_error, HasReason("bad-blk-sigops")); | |||||
g_mempool.clear(); | |||||
tx.vin[0].prevout = COutPoint(txFirst[0]->GetId(), 0); | |||||
tx.vout[0].nValue = BLOCKSUBSIDY; | |||||
for (unsigned int i = 0; i < 1001; ++i) { | |||||
tx.vout[0].nValue -= LOWFEE; | |||||
const TxId txid = tx.GetId(); | |||||
// Only first tx spends coinbase. | |||||
bool spendsCoinbase = i == 0; | |||||
// If we do set the # of sig ops in the CTxMemPoolEntry, template | |||||
// creation passes. | |||||
g_mempool.addUnchecked(entry.Fee(LOWFEE) | |||||
.Time(GetTime()) | |||||
.SpendsCoinbase(spendsCoinbase) | |||||
.SigOpCount(20) | |||||
.FromTx(tx)); | |||||
tx.vin[0].prevout = COutPoint(txid, 0); | |||||
} | |||||
BOOST_CHECK(pblocktemplate = AssemblerForTest(chainparams, g_mempool) | |||||
.CreateNewBlock(scriptPubKey)); | |||||
g_mempool.clear(); | |||||
// block size > limit | // block size > limit | ||||
tx.vin.resize(1); | |||||
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.resize(1); | |||||
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; | ||||
const TxId txid = 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(entry.Fee(LOWFEE) | g_mempool.addUnchecked(entry.Fee(LOWFEE) | ||||
.Time(GetTime()) | .Time(GetTime()) | ||||
▲ Show 20 Lines • Show All 384 Lines • Show Last 20 Lines |