Changeset View
Changeset View
Standalone View
Standalone View
src/test/policyestimator_tests.cpp
Show All 23 Lines | BOOST_AUTO_TEST_CASE(BlockPolicyEstimates) { | ||||
// Populate vectors of increasing fees | // Populate vectors of increasing fees | ||||
for (int j = 0; j < 10; j++) { | for (int j = 0; j < 10; j++) { | ||||
feeV.push_back(basefee * (j + 1)); | feeV.push_back(basefee * (j + 1)); | ||||
} | } | ||||
// Store the hashes of transactions that have been added to the mempool by | // Store the hashes of transactions that have been added to the mempool by | ||||
// their associate fee txHashes[j] is populated with transactions either of | // their associate fee txHashes[j] is populated with transactions either of | ||||
// fee = basefee * (j+1) | // fee = basefee * (j+1) | ||||
std::vector<uint256> txHashes[10]; | std::vector<txhash_t> txHashes[10]; | ||||
// Create a transaction template | // Create a transaction template | ||||
CScript garbage; | CScript garbage; | ||||
for (unsigned int i = 0; i < 128; i++) | for (unsigned int i = 0; i < 128; i++) | ||||
garbage.push_back('X'); | garbage.push_back('X'); | ||||
CMutableTransaction tx; | CMutableTransaction tx; | ||||
tx.vin.resize(1); | tx.vin.resize(1); | ||||
tx.vin[0].scriptSig = garbage; | tx.vin[0].scriptSig = garbage; | ||||
Show All 10 Lines | BOOST_AUTO_TEST_CASE(BlockPolicyEstimates) { | ||||
// This makes the tx count about 1.33 per bucket, above the 1 threshold | // This makes the tx count about 1.33 per bucket, above the 1 threshold | ||||
while (blocknum < 200) { | while (blocknum < 200) { | ||||
// For each fee | // For each fee | ||||
for (int j = 0; j < 10; j++) { | for (int j = 0; j < 10; j++) { | ||||
// add 4 fee txs | // add 4 fee txs | ||||
for (int k = 0; k < 4; k++) { | for (int k = 0; k < 4; k++) { | ||||
// make transaction unique | // make transaction unique | ||||
tx.vin[0].prevout.n = 10000 * blocknum + 100 * j + k; | tx.vin[0].prevout.n = 10000 * blocknum + 100 * j + k; | ||||
uint256 hash = tx.GetId(); | txhash_t hash = tx.GetHash(); | ||||
mpool.addUnchecked(hash, entry.Fee(feeV[j]) | mpool.addUnchecked(hash, entry.Fee(feeV[j]) | ||||
.Time(GetTime()) | .Time(GetTime()) | ||||
.Priority(0) | .Priority(0) | ||||
.Height(blocknum) | .Height(blocknum) | ||||
.FromTx(tx, &mpool)); | .FromTx(tx, &mpool)); | ||||
txHashes[j].push_back(hash); | txHashes[j].push_back(hash); | ||||
} | } | ||||
} | } | ||||
▲ Show 20 Lines • Show All 79 Lines • ▼ Show 20 Lines | BOOST_AUTO_TEST_CASE(BlockPolicyEstimates) { | ||||
// Mine 15 more blocks with lots of transactions happening and not getting | // Mine 15 more blocks with lots of transactions happening and not getting | ||||
// mined. Estimates should go up | // mined. Estimates should go up | ||||
while (blocknum < 265) { | while (blocknum < 265) { | ||||
// For each fee multiple | // For each fee multiple | ||||
for (int j = 0; j < 10; j++) { | for (int j = 0; j < 10; j++) { | ||||
// add 4 fee txs | // add 4 fee txs | ||||
for (int k = 0; k < 4; k++) { | for (int k = 0; k < 4; k++) { | ||||
tx.vin[0].prevout.n = 10000 * blocknum + 100 * j + k; | tx.vin[0].prevout.n = 10000 * blocknum + 100 * j + k; | ||||
uint256 txid = tx.GetId(); | txhash_t txhash = tx.GetHash(); | ||||
mpool.addUnchecked(txid, entry.Fee(feeV[j]) | mpool.addUnchecked(txhash, entry.Fee(feeV[j]) | ||||
.Time(GetTime()) | .Time(GetTime()) | ||||
.Priority(0) | .Priority(0) | ||||
.Height(blocknum) | .Height(blocknum) | ||||
.FromTx(tx, &mpool)); | .FromTx(tx, &mpool)); | ||||
txHashes[j].push_back(txid); | txHashes[j].push_back(txhash); | ||||
} | } | ||||
} | } | ||||
mpool.removeForBlock(block, ++blocknum); | mpool.removeForBlock(block, ++blocknum); | ||||
} | } | ||||
int answerFound; | int answerFound; | ||||
for (int i = 1; i < 10; i++) { | for (int i = 1; i < 10; i++) { | ||||
BOOST_CHECK(mpool.estimateFee(i) == CFeeRate(0) || | BOOST_CHECK(mpool.estimateFee(i) == CFeeRate(0) || | ||||
Show All 23 Lines | BOOST_AUTO_TEST_CASE(BlockPolicyEstimates) { | ||||
// Mine 200 more blocks where everything is mined every block | // Mine 200 more blocks where everything is mined every block | ||||
// Estimates should be below original estimates | // Estimates should be below original estimates | ||||
while (blocknum < 465) { | while (blocknum < 465) { | ||||
// For each fee multiple | // For each fee multiple | ||||
for (int j = 0; j < 10; j++) { | for (int j = 0; j < 10; j++) { | ||||
// add 4 fee txs | // add 4 fee txs | ||||
for (int k = 0; k < 4; k++) { | for (int k = 0; k < 4; k++) { | ||||
tx.vin[0].prevout.n = 10000 * blocknum + 100 * j + k; | tx.vin[0].prevout.n = 10000 * blocknum + 100 * j + k; | ||||
uint256 txid = tx.GetId(); | txhash_t txhash = tx.GetHash(); | ||||
mpool.addUnchecked(txid, entry.Fee(feeV[j]) | mpool.addUnchecked(txhash, entry.Fee(feeV[j]) | ||||
.Time(GetTime()) | .Time(GetTime()) | ||||
.Priority(0) | .Priority(0) | ||||
.Height(blocknum) | .Height(blocknum) | ||||
.FromTx(tx, &mpool)); | .FromTx(tx, &mpool)); | ||||
CTransactionRef ptx = mpool.get(txid); | CTransactionRef ptx = mpool.get(txhash); | ||||
if (ptx) block.push_back(ptx); | if (ptx) block.push_back(ptx); | ||||
} | } | ||||
} | } | ||||
mpool.removeForBlock(block, ++blocknum); | mpool.removeForBlock(block, ++blocknum); | ||||
block.clear(); | block.clear(); | ||||
} | } | ||||
BOOST_CHECK(mpool.estimateFee(1) == CFeeRate(0)); | BOOST_CHECK(mpool.estimateFee(1) == CFeeRate(0)); | ||||
for (int i = 2; i < 10; i++) { | for (int i = 2; i < 10; i++) { | ||||
BOOST_CHECK(mpool.estimateFee(i).GetFeePerK() < | BOOST_CHECK(mpool.estimateFee(i).GetFeePerK() < | ||||
origFeeEst[i - 1] - deltaFee); | origFeeEst[i - 1] - deltaFee); | ||||
} | } | ||||
// Test that if the mempool is limited, estimateSmartFee won't return a | // Test that if the mempool is limited, estimateSmartFee won't return a | ||||
// value below the mempool min fee and that estimateSmartPriority returns | // value below the mempool min fee and that estimateSmartPriority returns | ||||
// essentially an infinite value | // essentially an infinite value | ||||
mpool.addUnchecked( | mpool.addUnchecked( | ||||
tx.GetId(), | tx.GetHash(), | ||||
entry.Fee(feeV[5]).Time(GetTime()).Priority(0).Height(blocknum).FromTx( | entry.Fee(feeV[5]).Time(GetTime()).Priority(0).Height(blocknum).FromTx( | ||||
tx, &mpool)); | tx, &mpool)); | ||||
// evict that transaction which should set a mempool min fee of | // evict that transaction which should set a mempool min fee of | ||||
// minRelayTxFee + feeV[5] | // minRelayTxFee + feeV[5] | ||||
mpool.TrimToSize(1); | mpool.TrimToSize(1); | ||||
BOOST_CHECK(mpool.GetMinFee(1).GetFeePerK() > feeV[5]); | BOOST_CHECK(mpool.GetMinFee(1).GetFeePerK() > feeV[5]); | ||||
for (int i = 1; i < 10; i++) { | for (int i = 1; i < 10; i++) { | ||||
BOOST_CHECK(mpool.estimateSmartFee(i).GetFeePerK() >= | BOOST_CHECK(mpool.estimateSmartFee(i).GetFeePerK() >= | ||||
mpool.estimateFee(i).GetFeePerK()); | mpool.estimateFee(i).GetFeePerK()); | ||||
BOOST_CHECK(mpool.estimateSmartFee(i).GetFeePerK() >= | BOOST_CHECK(mpool.estimateSmartFee(i).GetFeePerK() >= | ||||
mpool.GetMinFee(1).GetFeePerK()); | mpool.GetMinFee(1).GetFeePerK()); | ||||
BOOST_CHECK(mpool.estimateSmartPriority(i) == INF_PRIORITY); | BOOST_CHECK(mpool.estimateSmartPriority(i) == INF_PRIORITY); | ||||
} | } | ||||
} | } | ||||
BOOST_AUTO_TEST_SUITE_END() | BOOST_AUTO_TEST_SUITE_END() |