Changeset View
Changeset View
Standalone View
Standalone View
src/test/miner_tests.cpp
Show First 20 Lines • Show All 113 Lines • ▼ Show 20 Lines | static void TestPackageSelection(const CChainParams &chainparams, | ||||
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, entry.Fee(1000 * SATOSHI) | g_mempool.addUnchecked(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, entry.Fee(10000 * SATOSHI) | g_mempool.addUnchecked(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, entry.Fee(50000 * SATOSHI) | g_mempool.addUnchecked(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 = | ||||
AssemblerForTest(chainparams, g_mempool).CreateNewBlock(scriptPubKey); | AssemblerForTest(chainparams, 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 | ||||
tx.vin[0].prevout = COutPoint(highFeeTxId, 0); | tx.vin[0].prevout = COutPoint(highFeeTxId, 0); | ||||
// 0 fee. | // 0 fee. | ||||
tx.vout[0].nValue = int64_t(5000000000LL - 1000 - 50000) * SATOSHI; | tx.vout[0].nValue = int64_t(5000000000LL - 1000 - 50000) * SATOSHI; | ||||
TxId freeTxId = tx.GetId(); | TxId freeTxId = tx.GetId(); | ||||
g_mempool.addUnchecked(freeTxId, entry.Fee(Amount::zero()).FromTx(tx)); | g_mempool.addUnchecked(entry.Fee(Amount::zero()).FromTx(tx)); | ||||
size_t freeTxSize = GetSerializeSize(tx, PROTOCOL_VERSION); | size_t freeTxSize = GetSerializeSize(tx, PROTOCOL_VERSION); | ||||
// Calculate a fee on child transaction that will put the package just | // Calculate a fee on child transaction that will put the package just | ||||
// below the block min tx fee (assuming 1 child tx of the same size). | // below the block min tx fee (assuming 1 child tx of the same size). | ||||
Amount feeToUse = blockMinFeeRate.GetFee(2 * freeTxSize) - SATOSHI; | Amount feeToUse = blockMinFeeRate.GetFee(2 * freeTxSize) - SATOSHI; | ||||
tx.vin[0].prevout = COutPoint(freeTxId, 0); | tx.vin[0].prevout = COutPoint(freeTxId, 0); | ||||
tx.vout[0].nValue = | tx.vout[0].nValue = | ||||
int64_t(5000000000LL - 1000 - 50000) * SATOSHI - feeToUse; | int64_t(5000000000LL - 1000 - 50000) * SATOSHI - feeToUse; | ||||
TxId lowFeeTxId = tx.GetId(); | TxId lowFeeTxId = tx.GetId(); | ||||
g_mempool.addUnchecked(lowFeeTxId, entry.Fee(feeToUse).FromTx(tx)); | g_mempool.addUnchecked(entry.Fee(feeToUse).FromTx(tx)); | ||||
pblocktemplate = | pblocktemplate = | ||||
AssemblerForTest(chainparams, g_mempool).CreateNewBlock(scriptPubKey); | AssemblerForTest(chainparams, g_mempool).CreateNewBlock(scriptPubKey); | ||||
// Verify that the free tx and the low fee tx didn't get selected. | // Verify that the free tx and the low fee tx didn't get selected. | ||||
for (const auto &txn : pblocktemplate->block.vtx) { | for (const auto &txn : pblocktemplate->block.vtx) { | ||||
BOOST_CHECK(txn->GetId() != freeTxId); | BOOST_CHECK(txn->GetId() != freeTxId); | ||||
BOOST_CHECK(txn->GetId() != lowFeeTxId); | BOOST_CHECK(txn->GetId() != lowFeeTxId); | ||||
} | } | ||||
// Test that packages above the min relay fee do get included, even if one | // Test that packages above the min relay fee do get included, even if one | ||||
// of the transactions is below the min relay fee. Remove the low fee | // of the transactions is below the min relay fee. Remove the low fee | ||||
// transaction and replace with a higher fee transaction | // transaction and replace with a higher fee transaction | ||||
g_mempool.removeRecursive(CTransaction(tx)); | g_mempool.removeRecursive(CTransaction(tx)); | ||||
// Now we should be just over the min relay fee. | // Now we should be just over the min relay fee. | ||||
tx.vout[0].nValue -= 2 * SATOSHI; | tx.vout[0].nValue -= 2 * SATOSHI; | ||||
lowFeeTxId = tx.GetId(); | lowFeeTxId = tx.GetId(); | ||||
g_mempool.addUnchecked(lowFeeTxId, | g_mempool.addUnchecked(entry.Fee(feeToUse + 2 * SATOSHI).FromTx(tx)); | ||||
entry.Fee(feeToUse + 2 * SATOSHI).FromTx(tx)); | |||||
pblocktemplate = | pblocktemplate = | ||||
AssemblerForTest(chainparams, g_mempool).CreateNewBlock(scriptPubKey); | AssemblerForTest(chainparams, g_mempool).CreateNewBlock(scriptPubKey); | ||||
BOOST_CHECK(pblocktemplate->block.vtx[4]->GetId() == freeTxId); | BOOST_CHECK(pblocktemplate->block.vtx[4]->GetId() == freeTxId); | ||||
BOOST_CHECK(pblocktemplate->block.vtx[5]->GetId() == lowFeeTxId); | BOOST_CHECK(pblocktemplate->block.vtx[5]->GetId() == lowFeeTxId); | ||||
// Test that transaction selection properly updates ancestor fee | // Test that transaction selection properly updates ancestor fee | ||||
// calculations as ancestor transactions get included in a block. Add a | // calculations as ancestor transactions get included in a block. Add a | ||||
// 0-fee transaction that has 2 outputs. | // 0-fee transaction that has 2 outputs. | ||||
tx.vin[0].prevout = COutPoint(txFirst[2]->GetId(), 0); | tx.vin[0].prevout = COutPoint(txFirst[2]->GetId(), 0); | ||||
tx.vout.resize(2); | tx.vout.resize(2); | ||||
tx.vout[0].nValue = int64_t(5000000000LL - 100000000) * SATOSHI; | tx.vout[0].nValue = int64_t(5000000000LL - 100000000) * SATOSHI; | ||||
// 1BCC output. | // 1BCC output. | ||||
tx.vout[1].nValue = 100000000 * SATOSHI; | tx.vout[1].nValue = 100000000 * SATOSHI; | ||||
TxId freeTxId2 = tx.GetId(); | TxId freeTxId2 = tx.GetId(); | ||||
g_mempool.addUnchecked( | g_mempool.addUnchecked( | ||||
freeTxId2, entry.Fee(Amount::zero()).SpendsCoinbase(true).FromTx(tx)); | entry.Fee(Amount::zero()).SpendsCoinbase(true).FromTx(tx)); | ||||
// This tx can't be mined by itself. | // This tx can't be mined by itself. | ||||
tx.vin[0].prevout = COutPoint(freeTxId2, 0); | tx.vin[0].prevout = COutPoint(freeTxId2, 0); | ||||
tx.vout.resize(1); | tx.vout.resize(1); | ||||
feeToUse = blockMinFeeRate.GetFee(freeTxSize); | feeToUse = blockMinFeeRate.GetFee(freeTxSize); | ||||
tx.vout[0].nValue = int64_t(5000000000LL - 100000000) * SATOSHI - feeToUse; | tx.vout[0].nValue = int64_t(5000000000LL - 100000000) * SATOSHI - feeToUse; | ||||
TxId lowFeeTxId2 = tx.GetId(); | TxId lowFeeTxId2 = tx.GetId(); | ||||
g_mempool.addUnchecked( | g_mempool.addUnchecked( | ||||
lowFeeTxId2, entry.Fee(feeToUse).SpendsCoinbase(false).FromTx(tx)); | entry.Fee(feeToUse).SpendsCoinbase(false).FromTx(tx)); | ||||
pblocktemplate = | pblocktemplate = | ||||
AssemblerForTest(chainparams, g_mempool).CreateNewBlock(scriptPubKey); | AssemblerForTest(chainparams, g_mempool).CreateNewBlock(scriptPubKey); | ||||
// Verify that this tx isn't selected. | // Verify that this tx isn't selected. | ||||
for (const auto &txn : pblocktemplate->block.vtx) { | for (const auto &txn : pblocktemplate->block.vtx) { | ||||
BOOST_CHECK(txn->GetId() != freeTxId2); | BOOST_CHECK(txn->GetId() != freeTxId2); | ||||
BOOST_CHECK(txn->GetId() != lowFeeTxId2); | BOOST_CHECK(txn->GetId() != lowFeeTxId2); | ||||
} | } | ||||
// This tx will be mineable, and should cause lowFeeTxId2 to be selected as | // This tx will be mineable, and should cause lowFeeTxId2 to be selected as | ||||
// well. | // well. | ||||
tx.vin[0].prevout = COutPoint(freeTxId2, 1); | tx.vin[0].prevout = COutPoint(freeTxId2, 1); | ||||
// 10k satoshi fee. | // 10k satoshi fee. | ||||
tx.vout[0].nValue = (100000000 - 10000) * SATOSHI; | tx.vout[0].nValue = (100000000 - 10000) * SATOSHI; | ||||
g_mempool.addUnchecked(tx.GetId(), entry.Fee(10000 * SATOSHI).FromTx(tx)); | g_mempool.addUnchecked(entry.Fee(10000 * SATOSHI).FromTx(tx)); | ||||
pblocktemplate = | pblocktemplate = | ||||
AssemblerForTest(chainparams, g_mempool).CreateNewBlock(scriptPubKey); | AssemblerForTest(chainparams, g_mempool).CreateNewBlock(scriptPubKey); | ||||
BOOST_CHECK(pblocktemplate->block.vtx[8]->GetId() == lowFeeTxId2); | BOOST_CHECK(pblocktemplate->block.vtx[8]->GetId() == lowFeeTxId2); | ||||
} | } | ||||
void TestCoinbaseMessageEB(uint64_t eb, std::string cbmsg) { | void TestCoinbaseMessageEB(uint64_t eb, std::string cbmsg) { | ||||
GlobalConfig config; | GlobalConfig config; | ||||
config.SetMaxBlockSize(eb); | config.SetMaxBlockSize(eb); | ||||
▲ Show 20 Lines • Show All 108 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; | ||||
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; | ||||
// 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(txid, entry.Fee(LOWFEE) | g_mempool.addUnchecked(entry.Fee(LOWFEE) | ||||
.Time(GetTime()) | .Time(GetTime()) | ||||
.SpendsCoinbase(spendsCoinbase) | .SpendsCoinbase(spendsCoinbase) | ||||
.FromTx(tx)); | .FromTx(tx)); | ||||
tx.vin[0].prevout = COutPoint(txid, 0); | tx.vin[0].prevout = COutPoint(txid, 0); | ||||
} | } | ||||
BOOST_CHECK_EXCEPTION( | BOOST_CHECK_EXCEPTION( | ||||
AssemblerForTest(chainparams, g_mempool).CreateNewBlock(scriptPubKey), | AssemblerForTest(chainparams, g_mempool).CreateNewBlock(scriptPubKey), | ||||
std::runtime_error, HasReason("bad-blk-sigops")); | std::runtime_error, HasReason("bad-blk-sigops")); | ||||
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; | ||||
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; | ||||
// 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(txid, entry.Fee(LOWFEE) | g_mempool.addUnchecked(entry.Fee(LOWFEE) | ||||
.Time(GetTime()) | .Time(GetTime()) | ||||
.SpendsCoinbase(spendsCoinbase) | .SpendsCoinbase(spendsCoinbase) | ||||
.SigOpCount(20) | .SigOpCount(20) | ||||
.FromTx(tx)); | .FromTx(tx)); | ||||
tx.vin[0].prevout = COutPoint(txid, 0); | tx.vin[0].prevout = COutPoint(txid, 0); | ||||
} | } | ||||
BOOST_CHECK(pblocktemplate = AssemblerForTest(chainparams, g_mempool) | BOOST_CHECK(pblocktemplate = AssemblerForTest(chainparams, g_mempool) | ||||
.CreateNewBlock(scriptPubKey)); | .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; | ||||
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(txid, entry.Fee(LOWFEE) | g_mempool.addUnchecked(entry.Fee(LOWFEE) | ||||
.Time(GetTime()) | .Time(GetTime()) | ||||
.SpendsCoinbase(spendsCoinbase) | .SpendsCoinbase(spendsCoinbase) | ||||
.FromTx(tx)); | .FromTx(tx)); | ||||
tx.vin[0].prevout = COutPoint(txid, 0); | tx.vin[0].prevout = COutPoint(txid, 0); | ||||
} | } | ||||
BOOST_CHECK(pblocktemplate = AssemblerForTest(chainparams, g_mempool) | BOOST_CHECK(pblocktemplate = AssemblerForTest(chainparams, g_mempool) | ||||
.CreateNewBlock(scriptPubKey)); | .CreateNewBlock(scriptPubKey)); | ||||
g_mempool.clear(); | g_mempool.clear(); | ||||
// Orphan in mempool, template creation fails. | // Orphan in mempool, template creation fails. | ||||
TxId txid = tx.GetId(); | g_mempool.addUnchecked(entry.Fee(LOWFEE).Time(GetTime()).FromTx(tx)); | ||||
g_mempool.addUnchecked(txid, entry.Fee(LOWFEE).Time(GetTime()).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(); | ||||
// 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; | ||||
txid = tx.GetId(); | TxId txid = tx.GetId(); | ||||
g_mempool.addUnchecked( | g_mempool.addUnchecked( | ||||
txid, | |||||
entry.Fee(HIGHFEE).Time(GetTime()).SpendsCoinbase(true).FromTx(tx)); | entry.Fee(HIGHFEE).Time(GetTime()).SpendsCoinbase(true).FromTx(tx)); | ||||
tx.vin[0].prevout = COutPoint(txid, 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; | ||||
txid = tx.GetId(); | txid = tx.GetId(); | ||||
g_mempool.addUnchecked( | g_mempool.addUnchecked( | ||||
txid, | |||||
entry.Fee(HIGHERFEE).Time(GetTime()).SpendsCoinbase(true).FromTx(tx)); | entry.Fee(HIGHERFEE).Time(GetTime()).SpendsCoinbase(true).FromTx(tx)); | ||||
BOOST_CHECK(pblocktemplate = AssemblerForTest(chainparams, g_mempool) | BOOST_CHECK(pblocktemplate = AssemblerForTest(chainparams, g_mempool) | ||||
.CreateNewBlock(scriptPubKey)); | .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(); | ||||
txid = 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( | ||||
txid, | |||||
entry.Fee(LOWFEE).Time(GetTime()).SpendsCoinbase(false).FromTx(tx)); | entry.Fee(LOWFEE).Time(GetTime()).SpendsCoinbase(false).FromTx(tx)); | ||||
// Should throw bad-tx-coinbase | // Should throw bad-tx-coinbase | ||||
BOOST_CHECK_EXCEPTION( | BOOST_CHECK_EXCEPTION( | ||||
AssemblerForTest(chainparams, g_mempool).CreateNewBlock(scriptPubKey), | AssemblerForTest(chainparams, g_mempool).CreateNewBlock(scriptPubKey), | ||||
std::runtime_error, HasReason("bad-tx-coinbase")); | std::runtime_error, HasReason("bad-tx-coinbase")); | ||||
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; | ||||
txid = tx.GetId(); | txid = tx.GetId(); | ||||
g_mempool.addUnchecked( | g_mempool.addUnchecked( | ||||
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; | ||||
txid = tx.GetId(); | txid = tx.GetId(); | ||||
g_mempool.addUnchecked( | g_mempool.addUnchecked( | ||||
txid, | |||||
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(); | ||||
Show All 28 Lines | BOOST_AUTO_TEST_CASE(CreateNewBlock_validity) { | ||||
// 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)); | ||||
txid = tx.GetId(); | txid = tx.GetId(); | ||||
g_mempool.addUnchecked( | g_mempool.addUnchecked( | ||||
txid, | |||||
entry.Fee(LOWFEE).Time(GetTime()).SpendsCoinbase(true).FromTx(tx)); | entry.Fee(LOWFEE).Time(GetTime()).SpendsCoinbase(true).FromTx(tx)); | ||||
tx.vin[0].prevout = COutPoint(txid, 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; | ||||
txid = tx.GetId(); | txid = tx.GetId(); | ||||
g_mempool.addUnchecked( | g_mempool.addUnchecked( | ||||
txid, | |||||
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. | ||||
Show All 22 Lines | BOOST_AUTO_TEST_CASE(CreateNewBlock_validity) { | ||||
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( | ||||
txid, | |||||
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( | ||||
Show All 12 Lines | BOOST_AUTO_TEST_CASE(CreateNewBlock_validity) { | ||||
// 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(txid, 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)); | ||||
} | } | ||||
Show All 16 Lines | BOOST_AUTO_TEST_CASE(CreateNewBlock_validity) { | ||||
} | } | ||||
// 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(txid, 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"); | ||||
} | } | ||||
Show All 11 Lines | BOOST_AUTO_TEST_CASE(CreateNewBlock_validity) { | ||||
} | } | ||||
// 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(txid, 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"); | ||||
} | } | ||||
▲ Show 20 Lines • Show All 128 Lines • Show Last 20 Lines |