Changeset View
Changeset View
Standalone View
Standalone View
src/test/miner_tests.cpp
Show First 20 Lines • Show All 94 Lines • ▼ Show 20 Lines | void TestPackageSelection(Config &config, CScript scriptPubKey, | ||||
tx.vin.resize(1); | tx.vin.resize(1); | ||||
tx.vin[0].scriptSig = CScript() << OP_1; | tx.vin[0].scriptSig = CScript() << 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 = int64_t(5000000000LL - 1000) * SATOSHI; | tx.vout[0].nValue = int64_t(5000000000LL - 1000) * SATOSHI; | ||||
// This tx has a low fee: 1000 satoshis. | // This tx has a low fee: 1000 satoshis. | ||||
// Save this txid for later use. | // Save this txid for later use. | ||||
TxId parentTxId = tx.GetId(); | TxId parentTxId = tx.GetId(); | ||||
g_mempool.addUnchecked(parentTxId, | g_mempool.addUnchecked(parentTxId, entry.Fee(1000 * SATOSHI) | ||||
entry.Fee(1000 * SATOSHI) | |||||
.Time(GetTime()) | .Time(GetTime()) | ||||
.SpendsCoinbase(true) | .SpendsCoinbase(true) | ||||
.FromTx(tx)); | .FromTx(tx)); | ||||
// This tx has a medium fee: 10000 satoshis. | // This tx has a medium fee: 10000 satoshis. | ||||
tx.vin[0].prevout = COutPoint(txFirst[1]->GetId(), 0); | tx.vin[0].prevout = COutPoint(txFirst[1]->GetId(), 0); | ||||
tx.vout[0].nValue = int64_t(5000000000LL - 10000) * SATOSHI; | tx.vout[0].nValue = int64_t(5000000000LL - 10000) * SATOSHI; | ||||
TxId mediumFeeTxId = tx.GetId(); | TxId mediumFeeTxId = tx.GetId(); | ||||
g_mempool.addUnchecked(mediumFeeTxId, | g_mempool.addUnchecked(mediumFeeTxId, entry.Fee(10000 * SATOSHI) | ||||
entry.Fee(10000 * SATOSHI) | |||||
.Time(GetTime()) | .Time(GetTime()) | ||||
.SpendsCoinbase(true) | .SpendsCoinbase(true) | ||||
.FromTx(tx)); | .FromTx(tx)); | ||||
// This tx has a high fee, but depends on the first transaction. | // This tx has a high fee, but depends on the first transaction. | ||||
tx.vin[0].prevout = COutPoint(parentTxId, 0); | tx.vin[0].prevout = COutPoint(parentTxId, 0); | ||||
// 50k satoshi fee. | // 50k satoshi fee. | ||||
tx.vout[0].nValue = int64_t(5000000000LL - 1000 - 50000) * SATOSHI; | tx.vout[0].nValue = int64_t(5000000000LL - 1000 - 50000) * SATOSHI; | ||||
TxId highFeeTxId = tx.GetId(); | TxId highFeeTxId = tx.GetId(); | ||||
g_mempool.addUnchecked(highFeeTxId, | g_mempool.addUnchecked(highFeeTxId, entry.Fee(50000 * SATOSHI) | ||||
entry.Fee(50000 * SATOSHI) | |||||
.Time(GetTime()) | .Time(GetTime()) | ||||
.SpendsCoinbase(false) | .SpendsCoinbase(false) | ||||
.FromTx(tx)); | .FromTx(tx)); | ||||
std::unique_ptr<CBlockTemplate> pblocktemplate = | std::unique_ptr<CBlockTemplate> pblocktemplate = | ||||
BlockAssembler(config, g_mempool).CreateNewBlock(scriptPubKey); | BlockAssembler(config, g_mempool).CreateNewBlock(scriptPubKey); | ||||
BOOST_CHECK(pblocktemplate->block.vtx[1]->GetId() == parentTxId); | BOOST_CHECK(pblocktemplate->block.vtx[1]->GetId() == parentTxId); | ||||
BOOST_CHECK(pblocktemplate->block.vtx[2]->GetId() == highFeeTxId); | BOOST_CHECK(pblocktemplate->block.vtx[2]->GetId() == highFeeTxId); | ||||
BOOST_CHECK(pblocktemplate->block.vtx[3]->GetId() == mediumFeeTxId); | BOOST_CHECK(pblocktemplate->block.vtx[3]->GetId() == mediumFeeTxId); | ||||
// Test that a package below the block min tx fee doesn't get included | // Test that a package below the block min tx fee doesn't get included | ||||
▲ Show 20 Lines • Show All 189 Lines • ▼ Show 20 Lines | BOOST_AUTO_TEST_CASE(CreateNewBlock_validity) { | ||||
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(); | hash = tx.GetId(); | ||||
// Only first tx spends coinbase. | // Only first tx spends coinbase. | ||||
bool spendsCoinbase = (i == 0) ? true : false; | bool spendsCoinbase = (i == 0) ? true : false; | ||||
// 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, | g_mempool.addUnchecked(hash, entry.Fee(LOWFEE) | ||||
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(hash, 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(); | hash = tx.GetId(); | ||||
// Only first tx spends coinbase. | // Only first tx spends coinbase. | ||||
bool spendsCoinbase = (i == 0) ? true : false; | bool spendsCoinbase = (i == 0) ? true : false; | ||||
// 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, | g_mempool.addUnchecked(hash, entry.Fee(LOWFEE) | ||||
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(hash, 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(); | hash = tx.GetId(); | ||||
// Only first tx spends coinbase. | // Only first tx spends coinbase. | ||||
bool spendsCoinbase = (i == 0) ? true : false; | bool spendsCoinbase = (i == 0) ? true : false; | ||||
g_mempool.addUnchecked(hash, | g_mempool.addUnchecked(hash, entry.Fee(LOWFEE) | ||||
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(hash, 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. | ||||
▲ Show 20 Lines • Show All 380 Lines • Show Last 20 Lines |