MCPcopy Create free account
hub / github.com/ElementsProject/elements / BOOST_AUTO_TEST_CASE

Function BOOST_AUTO_TEST_CASE

src/test/policyestimator_tests.cpp:17–181  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

15BOOST_FIXTURE_TEST_SUITE(policyestimator_tests, BasicTestingSetup)
16
17BOOST_AUTO_TEST_CASE(BlockPolicyEstimates)
18{
19 CBlockPolicyEstimator feeEst;
20 CTxMemPool mpool(&feeEst);
21 LOCK2(cs_main, mpool.cs);
22 TestMemPoolEntryHelper entry;
23 CAmount basefee(2000);
24 CAmount deltaFee(100);
25 std::vector<CAmount> feeV;
26
27 // Populate vectors of increasing fees
28 for (int j = 0; j < 10; j++) {
29 feeV.push_back(basefee * (j+1));
30 }
31
32 // Store the hashes of transactions that have been
33 // added to the mempool by their associate fee
34 // txHashes[j] is populated with transactions either of
35 // fee = basefee * (j+1)
36 std::vector<uint256> txHashes[10];
37
38 // Create a transaction template
39 CScript garbage;
40 for (unsigned int i = 0; i < 128; i++)
41 garbage.push_back('X');
42 CMutableTransaction tx;
43 tx.vin.resize(1);
44 tx.vin[0].scriptSig = garbage;
45 tx.vout.resize(1);
46 tx.vout[0].nValue=0LL;
47 CFeeRate baseRate(basefee, GetVirtualTransactionSize(CTransaction(tx)));
48
49 // Create a fake block
50 std::vector<CTransactionRef> block;
51 int blocknum = 0;
52
53 // Loop through 200 blocks
54 // At a decay .9952 and 4 fee transactions per block
55 // This makes the tx count about 2.5 per bucket, well above the 0.1 threshold
56 while (blocknum < 200) {
57 for (int j = 0; j < 10; j++) { // For each fee
58 for (int k = 0; k < 4; k++) { // add 4 fee txs
59 tx.vin[0].prevout.n = 10000*blocknum+100*j+k; // make transaction unique
60 uint256 hash = tx.GetHash();
61 mpool.addUnchecked(entry.Fee(feeV[j]).Time(GetTime()).Height(blocknum).FromTx(tx));
62 txHashes[j].push_back(hash);
63 }
64 }
65 //Create blocks where higher fee txs are included more often
66 for (int h = 0; h <= blocknum%10; h++) {
67 // 10/10 blocks add highest fee transactions
68 // 9/10 blocks add 2nd highest and so on until ...
69 // 1/10 blocks add lowest fee transactions
70 while (txHashes[9-h].size()) {
71 CTransactionRef ptx = mpool.get(txHashes[9-h].back());
72 if (ptx)
73 block.push_back(ptx);
74 txHashes[9-h].pop_back();

Callers

nothing calls this directly

Calls 15

GetTimeFunction · 0.85
addUncheckedMethod · 0.80
FromTxMethod · 0.80
HeightMethod · 0.80
estimateFeeMethod · 0.80
GetFeePerKMethod · 0.80
CTransactionClass · 0.50
CFeeRateClass · 0.50
push_backMethod · 0.45
resizeMethod · 0.45
GetHashMethod · 0.45

Tested by

no test coverage detected