-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathpolicyestimator_tests.cpp
More file actions
100 lines (82 loc) · 3.19 KB
/
Copy pathpolicyestimator_tests.cpp
File metadata and controls
100 lines (82 loc) · 3.19 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
// Copyright (c) 2011-2016 The Bitcoin Core developers
// Copyright (c) 2021 The Bitcoin developers
// Distributed under the MIT software license, see the accompanying
// file COPYING or http://www.opensource.org/licenses/mit-license.php.
#include <policy/fees.h>
#include <policy/policy.h>
#include <txmempool.h>
#include <uint256.h>
#include <util/system.h>
#include <test/setup_common.h>
#include <boost/test/unit_test.hpp>
BOOST_FIXTURE_TEST_SUITE(policyestimator_tests, BasicTestingSetup)
BOOST_AUTO_TEST_CASE(MempoolMinimumFeeEstimate) {
CTxMemPool mpool;
LOCK2(cs_main, mpool.cs);
TestMemPoolEntryHelper entry;
// Create a transaction template
CScript garbage;
for (unsigned int i = 0; i < 128; i++) {
garbage.push_back('X');
}
CMutableTransaction tx;
tx.vin.resize(1);
tx.vin[0].scriptSig = garbage;
tx.vout.resize(1);
tx.vout[0].nValue = Amount::zero();
// Create a fake block
std::vector<CTransactionRef> block;
int blocknum = 0;
// Loop through 200 blocks adding transactions so we have a estimateFee
// that is calculable.
while (blocknum < 200) {
for (int64_t j = 0; j < 100; j++) {
// make transaction unique
tx.vin[0].nSequence = 10000 * blocknum + j;
TxId txid = tx.GetId();
mpool.addUnchecked(
entry.Fee((j + 1) * DEFAULT_BLOCK_MIN_TX_FEE_PER_KB)
.Time(GetTime())
.FromTx(tx));
CTransactionRef ptx = mpool.get(txid);
block.push_back(ptx);
}
++blocknum;
mpool.removeForBlock(block);
block.clear();
}
// Check that the estimate is above the rolling minimum fee. This should be
// true since we have not trimmed the mempool.
BOOST_CHECK(mpool.GetMinFee(1) <= mpool.estimateFee());
// Check that estimateFee returns the minimum rolling fee even when the
// mempool grows very quickly and no blocks have been mined.
// Add a bunch of low fee transactions which are not in the mempool
// And have zero fees.
CMutableTransaction mtx;
tx.vin.resize(1);
tx.vin[0].scriptSig = garbage;
tx.vout.resize(1);
block.clear();
// Add tons of transactions to the mempool,
// but don't mine them.
for (int64_t i = 0; i < 10000; i++) {
// Mutate the hash
tx.vin[0].nSequence = 10000 * blocknum + i;
// Add new transaction to the mempool with a increasing fee
// The average should end up as 1/2 * 100 *
// DEFAULT_BLOCK_MIN_TX_FEE_PER_KB
mpool.addUnchecked(entry.Fee((i + 1) * DEFAULT_BLOCK_MIN_TX_FEE_PER_KB)
.Time(GetTime())
.FromTx(tx));
}
// Trim to size. GetMinFee should be more than 10000 *
// DEFAULT_BLOCK_MIN_TX_FEE_PER_KB But the estimateFee should be
// unchanged.
mpool.TrimToSize(1);
BOOST_CHECK(mpool.GetMinFee(1) >=
CFeeRate(10000 * DEFAULT_BLOCK_MIN_TX_FEE_PER_KB,
CTransaction(tx).GetTotalSize()));
BOOST_CHECK_MESSAGE(mpool.estimateFee() == mpool.GetMinFee(1),
"Confirm blocks has failed");
}
BOOST_AUTO_TEST_SUITE_END()