Changeset View
Changeset View
Standalone View
Standalone View
src/test/policyestimator_tests.cpp
// Copyright (c) 2011-2016 The Bitcoin Core developers | // Copyright (c) 2011-2016 The Bitcoin Core developers | ||||
// Distributed under the MIT software license, see the accompanying | // Distributed under the MIT software license, see the accompanying | ||||
// file COPYING or http://www.opensource.org/licenses/mit-license.php. | // file COPYING or http://www.opensource.org/licenses/mit-license.php. | ||||
#include "policy/policy.h" | |||||
#include "policy/fees.h" | #include "policy/fees.h" | ||||
#include "policy/policy.h" | |||||
#include "txmempool.h" | #include "txmempool.h" | ||||
#include "uint256.h" | #include "uint256.h" | ||||
#include "util.h" | #include "util.h" | ||||
#include "test/test_bitcoin.h" | #include "test/test_bitcoin.h" | ||||
#include <boost/test/unit_test.hpp> | #include <boost/test/unit_test.hpp> | ||||
Show All 37 Lines | BOOST_AUTO_TEST_CASE(BlockPolicyEstimates) { | ||||
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(); | uint256 hash = tx.GetId(); | ||||
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); | ||||
} | } | ||||
} | } | ||||
// Create blocks where higher fee txs are included more often | // Create blocks where higher fee txs are included more often | ||||
for (int h = 0; h <= blocknum % 10; h++) { | for (int h = 0; h <= blocknum % 10; h++) { | ||||
// 10/10 blocks add highest fee transactions | // 10/10 blocks add highest fee transactions | ||||
// 9/10 blocks add 2nd highest and so on until ... | // 9/10 blocks add 2nd highest and so on until ... | ||||
// 1/10 blocks add lowest fee transactions | // 1/10 blocks add lowest fee transactions | ||||
▲ Show 20 Lines • Show All 75 Lines • ▼ Show 20 Lines | BOOST_AUTO_TEST_CASE(BlockPolicyEstimates) { | ||||
// 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(); | uint256 txid = tx.GetId(); | ||||
mpool.addUnchecked(txid, entry.Fee(feeV[j]) | mpool.addUnchecked(txid, | ||||
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(txid); | ||||
} | } | ||||
} | } | ||||
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++) { | ||||
Show All 26 Lines | BOOST_AUTO_TEST_CASE(BlockPolicyEstimates) { | ||||
// 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(); | uint256 txid = tx.GetId(); | ||||
mpool.addUnchecked(txid, entry.Fee(feeV[j]) | mpool.addUnchecked(txid, | ||||
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(txid); | ||||
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(Amount(0))); | BOOST_CHECK(mpool.estimateFee(1) == CFeeRate(Amount(0))); | ||||
Show All 27 Lines |