Skip to content

Commit e587bc3

Browse files
committed
Implement helper class for CTxMemPoolEntry constructor
This is only for unit tests.
1 parent 87ee0e2 commit e587bc3

File tree

5 files changed

+89
-47
lines changed

5 files changed

+89
-47
lines changed

src/test/mempool_tests.cpp

Lines changed: 37 additions & 32 deletions
Original file line numberDiff line numberDiff line change
@@ -17,6 +17,7 @@ BOOST_AUTO_TEST_CASE(MempoolRemoveTest)
1717
{
1818
// Test CTxMemPool::remove functionality
1919

20+
TestMemPoolEntryHelper entry;
2021
// Parent transaction with three children,
2122
// and three grand-children:
2223
CMutableTransaction txParent;
@@ -60,17 +61,17 @@ BOOST_AUTO_TEST_CASE(MempoolRemoveTest)
6061
BOOST_CHECK_EQUAL(removed.size(), 0);
6162

6263
// Just the parent:
63-
testPool.addUnchecked(txParent.GetHash(), CTxMemPoolEntry(txParent, 0, 0, 0.0, 1));
64+
testPool.addUnchecked(txParent.GetHash(), entry.FromTx(txParent));
6465
testPool.remove(txParent, removed, true);
6566
BOOST_CHECK_EQUAL(removed.size(), 1);
6667
removed.clear();
6768

6869
// Parent, children, grandchildren:
69-
testPool.addUnchecked(txParent.GetHash(), CTxMemPoolEntry(txParent, 0, 0, 0.0, 1));
70+
testPool.addUnchecked(txParent.GetHash(), entry.FromTx(txParent));
7071
for (int i = 0; i < 3; i++)
7172
{
72-
testPool.addUnchecked(txChild[i].GetHash(), CTxMemPoolEntry(txChild[i], 0, 0, 0.0, 1));
73-
testPool.addUnchecked(txGrandChild[i].GetHash(), CTxMemPoolEntry(txGrandChild[i], 0, 0, 0.0, 1));
73+
testPool.addUnchecked(txChild[i].GetHash(), entry.FromTx(txChild[i]));
74+
testPool.addUnchecked(txGrandChild[i].GetHash(), entry.FromTx(txGrandChild[i]));
7475
}
7576
// Remove Child[0], GrandChild[0] should be removed:
7677
testPool.remove(txChild[0], removed, true);
@@ -90,8 +91,8 @@ BOOST_AUTO_TEST_CASE(MempoolRemoveTest)
9091
// Add children and grandchildren, but NOT the parent (simulate the parent being in a block)
9192
for (int i = 0; i < 3; i++)
9293
{
93-
testPool.addUnchecked(txChild[i].GetHash(), CTxMemPoolEntry(txChild[i], 0, 0, 0.0, 1));
94-
testPool.addUnchecked(txGrandChild[i].GetHash(), CTxMemPoolEntry(txGrandChild[i], 0, 0, 0.0, 1));
94+
testPool.addUnchecked(txChild[i].GetHash(), entry.FromTx(txChild[i]));
95+
testPool.addUnchecked(txGrandChild[i].GetHash(), entry.FromTx(txGrandChild[i]));
9596
}
9697
// Now remove the parent, as might happen if a block-re-org occurs but the parent cannot be
9798
// put into the mempool (maybe because it is non-standard):
@@ -114,41 +115,45 @@ void CheckSort(CTxMemPool &pool, std::vector<std::string> &sortedOrder)
114115
BOOST_AUTO_TEST_CASE(MempoolIndexingTest)
115116
{
116117
CTxMemPool pool(CFeeRate(0));
118+
TestMemPoolEntryHelper entry;
119+
entry.hadNoDependencies = true;
117120

118121
/* 3rd highest fee */
119122
CMutableTransaction tx1 = CMutableTransaction();
120123
tx1.vout.resize(1);
121124
tx1.vout[0].scriptPubKey = CScript() << OP_11 << OP_EQUAL;
122125
tx1.vout[0].nValue = 10 * COIN;
123-
pool.addUnchecked(tx1.GetHash(), CTxMemPoolEntry(tx1, 10000LL, 0, 10.0, 1, true));
126+
pool.addUnchecked(tx1.GetHash(), entry.Fee(10000LL).Priority(10.0).FromTx(tx1));
124127

125128
/* highest fee */
126129
CMutableTransaction tx2 = CMutableTransaction();
127130
tx2.vout.resize(1);
128131
tx2.vout[0].scriptPubKey = CScript() << OP_11 << OP_EQUAL;
129132
tx2.vout[0].nValue = 2 * COIN;
130-
pool.addUnchecked(tx2.GetHash(), CTxMemPoolEntry(tx2, 20000LL, 0, 9.0, 1, true));
133+
pool.addUnchecked(tx2.GetHash(), entry.Fee(20000LL).Priority(9.0).FromTx(tx2));
131134

132135
/* lowest fee */
133136
CMutableTransaction tx3 = CMutableTransaction();
134137
tx3.vout.resize(1);
135138
tx3.vout[0].scriptPubKey = CScript() << OP_11 << OP_EQUAL;
136139
tx3.vout[0].nValue = 5 * COIN;
137-
pool.addUnchecked(tx3.GetHash(), CTxMemPoolEntry(tx3, 0LL, 0, 100.0, 1, true));
140+
pool.addUnchecked(tx3.GetHash(), entry.Fee(0LL).Priority(100.0).FromTx(tx3));
138141

139142
/* 2nd highest fee */
140143
CMutableTransaction tx4 = CMutableTransaction();
141144
tx4.vout.resize(1);
142145
tx4.vout[0].scriptPubKey = CScript() << OP_11 << OP_EQUAL;
143146
tx4.vout[0].nValue = 6 * COIN;
144-
pool.addUnchecked(tx4.GetHash(), CTxMemPoolEntry(tx4, 15000LL, 0, 1.0, 1, true));
147+
pool.addUnchecked(tx4.GetHash(), entry.Fee(15000LL).Priority(1.0).FromTx(tx4));
145148

146149
/* equal fee rate to tx1, but newer */
147150
CMutableTransaction tx5 = CMutableTransaction();
148151
tx5.vout.resize(1);
149152
tx5.vout[0].scriptPubKey = CScript() << OP_11 << OP_EQUAL;
150153
tx5.vout[0].nValue = 11 * COIN;
151-
pool.addUnchecked(tx5.GetHash(), CTxMemPoolEntry(tx5, 10000LL, 1, 10.0, 1, true));
154+
entry.nTime = 1;
155+
entry.dPriority = 10.0;
156+
pool.addUnchecked(tx5.GetHash(), entry.Fee(10000LL).FromTx(tx5));
152157
BOOST_CHECK_EQUAL(pool.size(), 5);
153158

154159
std::vector<std::string> sortedOrder;
@@ -166,7 +171,7 @@ BOOST_AUTO_TEST_CASE(MempoolIndexingTest)
166171
tx6.vout.resize(1);
167172
tx6.vout[0].scriptPubKey = CScript() << OP_11 << OP_EQUAL;
168173
tx6.vout[0].nValue = 20 * COIN;
169-
pool.addUnchecked(tx6.GetHash(), CTxMemPoolEntry(tx6, 0LL, 1, 10.0, 1, true));
174+
pool.addUnchecked(tx6.GetHash(), entry.Fee(0LL).FromTx(tx6));
170175
BOOST_CHECK_EQUAL(pool.size(), 6);
171176
// Check that at this point, tx6 is sorted low
172177
sortedOrder.insert(sortedOrder.begin(), tx6.GetHash().ToString());
@@ -186,11 +191,10 @@ BOOST_AUTO_TEST_CASE(MempoolIndexingTest)
186191

187192
CTxMemPool::setEntries setAncestorsCalculated;
188193
std::string dummy;
189-
CTxMemPoolEntry entry7(tx7, 2000000LL, 1, 10.0, 1, true);
190-
BOOST_CHECK_EQUAL(pool.CalculateMemPoolAncestors(entry7, setAncestorsCalculated, 100, 1000000, 1000, 1000000, dummy), true);
194+
BOOST_CHECK_EQUAL(pool.CalculateMemPoolAncestors(entry.Fee(2000000LL).FromTx(tx7), setAncestorsCalculated, 100, 1000000, 1000, 1000000, dummy), true);
191195
BOOST_CHECK(setAncestorsCalculated == setAncestors);
192196

193-
pool.addUnchecked(tx7.GetHash(), CTxMemPoolEntry(tx7, 2000000LL, 1, 10.0, 1, true), setAncestors);
197+
pool.addUnchecked(tx7.GetHash(), entry.FromTx(tx7), setAncestors);
194198
BOOST_CHECK_EQUAL(pool.size(), 7);
195199

196200
// Now tx6 should be sorted higher (high fee child): tx7, tx6, tx2, ...
@@ -208,7 +212,7 @@ BOOST_AUTO_TEST_CASE(MempoolIndexingTest)
208212
tx8.vout[0].scriptPubKey = CScript() << OP_11 << OP_EQUAL;
209213
tx8.vout[0].nValue = 10 * COIN;
210214
setAncestors.insert(pool.mapTx.find(tx7.GetHash()));
211-
pool.addUnchecked(tx8.GetHash(), CTxMemPoolEntry(tx8, 0LL, 2, 10.0, 1, true), setAncestors);
215+
pool.addUnchecked(tx8.GetHash(), entry.Fee(0LL).Time(2).FromTx(tx8), setAncestors);
212216

213217
// Now tx8 should be sorted low, but tx6/tx both high
214218
sortedOrder.insert(sortedOrder.begin(), tx8.GetHash().ToString());
@@ -222,7 +226,7 @@ BOOST_AUTO_TEST_CASE(MempoolIndexingTest)
222226
tx9.vout.resize(1);
223227
tx9.vout[0].scriptPubKey = CScript() << OP_11 << OP_EQUAL;
224228
tx9.vout[0].nValue = 1 * COIN;
225-
pool.addUnchecked(tx9.GetHash(), CTxMemPoolEntry(tx9, 0LL, 3, 10.0, 1, true), setAncestors);
229+
pool.addUnchecked(tx9.GetHash(), entry.Fee(0LL).Time(3).FromTx(tx9), setAncestors);
226230

227231
// tx9 should be sorted low
228232
BOOST_CHECK_EQUAL(pool.size(), 9);
@@ -245,11 +249,10 @@ BOOST_AUTO_TEST_CASE(MempoolIndexingTest)
245249
tx10.vout[0].nValue = 10 * COIN;
246250

247251
setAncestorsCalculated.clear();
248-
CTxMemPoolEntry entry10(tx10, 200000LL, 4, 10.0, 1, true);
249-
BOOST_CHECK_EQUAL(pool.CalculateMemPoolAncestors(entry10, setAncestorsCalculated, 100, 1000000, 1000, 1000000, dummy), true);
252+
BOOST_CHECK_EQUAL(pool.CalculateMemPoolAncestors(entry.Fee(200000LL).Time(4).FromTx(tx10), setAncestorsCalculated, 100, 1000000, 1000, 1000000, dummy), true);
250253
BOOST_CHECK(setAncestorsCalculated == setAncestors);
251254

252-
pool.addUnchecked(tx10.GetHash(), CTxMemPoolEntry(tx10, 200000LL, 4, 10.0, 1, true), setAncestors);
255+
pool.addUnchecked(tx10.GetHash(), entry.FromTx(tx10), setAncestors);
253256

254257
/**
255258
* tx8 and tx9 should both now be sorted higher
@@ -284,22 +287,24 @@ BOOST_AUTO_TEST_CASE(MempoolIndexingTest)
284287
BOOST_AUTO_TEST_CASE(MempoolSizeLimitTest)
285288
{
286289
CTxMemPool pool(CFeeRate(1000));
290+
TestMemPoolEntryHelper entry;
291+
entry.dPriority = 10.0;
287292

288293
CMutableTransaction tx1 = CMutableTransaction();
289294
tx1.vin.resize(1);
290295
tx1.vin[0].scriptSig = CScript() << OP_1;
291296
tx1.vout.resize(1);
292297
tx1.vout[0].scriptPubKey = CScript() << OP_1 << OP_EQUAL;
293298
tx1.vout[0].nValue = 10 * COIN;
294-
pool.addUnchecked(tx1.GetHash(), CTxMemPoolEntry(tx1, 10000LL, 0, 10.0, 1, pool.HasNoInputsOf(tx1)));
299+
pool.addUnchecked(tx1.GetHash(), entry.Fee(10000LL).FromTx(tx1, &pool));
295300

296301
CMutableTransaction tx2 = CMutableTransaction();
297302
tx2.vin.resize(1);
298303
tx2.vin[0].scriptSig = CScript() << OP_2;
299304
tx2.vout.resize(1);
300305
tx2.vout[0].scriptPubKey = CScript() << OP_2 << OP_EQUAL;
301306
tx2.vout[0].nValue = 10 * COIN;
302-
pool.addUnchecked(tx2.GetHash(), CTxMemPoolEntry(tx2, 5000LL, 0, 10.0, 1, pool.HasNoInputsOf(tx2)));
307+
pool.addUnchecked(tx2.GetHash(), entry.Fee(5000LL).FromTx(tx2, &pool));
303308

304309
pool.TrimToSize(pool.DynamicMemoryUsage()); // should do nothing
305310
BOOST_CHECK(pool.exists(tx1.GetHash()));
@@ -309,15 +314,15 @@ BOOST_AUTO_TEST_CASE(MempoolSizeLimitTest)
309314
BOOST_CHECK(pool.exists(tx1.GetHash()));
310315
BOOST_CHECK(!pool.exists(tx2.GetHash()));
311316

312-
pool.addUnchecked(tx2.GetHash(), CTxMemPoolEntry(tx2, 5000LL, 0, 10.0, 1, pool.HasNoInputsOf(tx2)));
317+
pool.addUnchecked(tx2.GetHash(), entry.FromTx(tx2, &pool));
313318
CMutableTransaction tx3 = CMutableTransaction();
314319
tx3.vin.resize(1);
315320
tx3.vin[0].prevout = COutPoint(tx2.GetHash(), 0);
316321
tx3.vin[0].scriptSig = CScript() << OP_2;
317322
tx3.vout.resize(1);
318323
tx3.vout[0].scriptPubKey = CScript() << OP_3 << OP_EQUAL;
319324
tx3.vout[0].nValue = 10 * COIN;
320-
pool.addUnchecked(tx3.GetHash(), CTxMemPoolEntry(tx3, 20000LL, 0, 10.0, 1, pool.HasNoInputsOf(tx3)));
325+
pool.addUnchecked(tx3.GetHash(), entry.Fee(20000LL).FromTx(tx3, &pool));
321326

322327
pool.TrimToSize(pool.DynamicMemoryUsage() * 3 / 4); // tx3 should pay for tx2 (CPFP)
323328
BOOST_CHECK(!pool.exists(tx1.GetHash()));
@@ -380,10 +385,10 @@ BOOST_AUTO_TEST_CASE(MempoolSizeLimitTest)
380385
tx7.vout[1].scriptPubKey = CScript() << OP_7 << OP_EQUAL;
381386
tx7.vout[1].nValue = 10 * COIN;
382387

383-
pool.addUnchecked(tx4.GetHash(), CTxMemPoolEntry(tx4, 7000LL, 0, 10.0, 1, pool.HasNoInputsOf(tx4)));
384-
pool.addUnchecked(tx5.GetHash(), CTxMemPoolEntry(tx5, 1000LL, 0, 10.0, 1, pool.HasNoInputsOf(tx5)));
385-
pool.addUnchecked(tx6.GetHash(), CTxMemPoolEntry(tx6, 1100LL, 0, 10.0, 1, pool.HasNoInputsOf(tx6)));
386-
pool.addUnchecked(tx7.GetHash(), CTxMemPoolEntry(tx7, 9000LL, 0, 10.0, 1, pool.HasNoInputsOf(tx7)));
388+
pool.addUnchecked(tx4.GetHash(), entry.Fee(7000LL).FromTx(tx4, &pool));
389+
pool.addUnchecked(tx5.GetHash(), entry.Fee(1000LL).FromTx(tx5, &pool));
390+
pool.addUnchecked(tx6.GetHash(), entry.Fee(1100LL).FromTx(tx6, &pool));
391+
pool.addUnchecked(tx7.GetHash(), entry.Fee(9000LL).FromTx(tx7, &pool));
387392

388393
// we only require this remove, at max, 2 txn, because its not clear what we're really optimizing for aside from that
389394
pool.TrimToSize(pool.DynamicMemoryUsage() - 1);
@@ -392,17 +397,17 @@ BOOST_AUTO_TEST_CASE(MempoolSizeLimitTest)
392397
BOOST_CHECK(!pool.exists(tx7.GetHash()));
393398

394399
if (!pool.exists(tx5.GetHash()))
395-
pool.addUnchecked(tx5.GetHash(), CTxMemPoolEntry(tx5, 1000LL, 0, 10.0, 1, pool.HasNoInputsOf(tx5)));
396-
pool.addUnchecked(tx7.GetHash(), CTxMemPoolEntry(tx7, 9000LL, 0, 10.0, 1, pool.HasNoInputsOf(tx7)));
400+
pool.addUnchecked(tx5.GetHash(), entry.Fee(1000LL).FromTx(tx5, &pool));
401+
pool.addUnchecked(tx7.GetHash(), entry.Fee(9000LL).FromTx(tx7, &pool));
397402

398403
pool.TrimToSize(pool.DynamicMemoryUsage() / 2); // should maximize mempool size by only removing 5/7
399404
BOOST_CHECK(pool.exists(tx4.GetHash()));
400405
BOOST_CHECK(!pool.exists(tx5.GetHash()));
401406
BOOST_CHECK(pool.exists(tx6.GetHash()));
402407
BOOST_CHECK(!pool.exists(tx7.GetHash()));
403408

404-
pool.addUnchecked(tx5.GetHash(), CTxMemPoolEntry(tx5, 1000LL, 0, 10.0, 1, pool.HasNoInputsOf(tx5)));
405-
pool.addUnchecked(tx7.GetHash(), CTxMemPoolEntry(tx7, 9000LL, 0, 10.0, 1, pool.HasNoInputsOf(tx7)));
409+
pool.addUnchecked(tx5.GetHash(), entry.Fee(1000LL).FromTx(tx5, &pool));
410+
pool.addUnchecked(tx7.GetHash(), entry.Fee(9000LL).FromTx(tx7, &pool));
406411

407412
std::vector<CTransaction> vtx;
408413
std::list<CTransaction> conflicts;

src/test/miner_tests.cpp

Lines changed: 16 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -65,6 +65,10 @@ BOOST_AUTO_TEST_CASE(CreateNewBlock_validity)
6565
CMutableTransaction tx,tx2;
6666
CScript script;
6767
uint256 hash;
68+
TestMemPoolEntryHelper entry;
69+
entry.nFee = 11;
70+
entry.dPriority = 111.0;
71+
entry.nHeight = 11;
6872

6973
LOCK(cs_main);
7074
fCheckpointsEnabled = false;
@@ -114,7 +118,7 @@ BOOST_AUTO_TEST_CASE(CreateNewBlock_validity)
114118
{
115119
tx.vout[0].nValue -= 1000000;
116120
hash = tx.GetHash();
117-
mempool.addUnchecked(hash, CTxMemPoolEntry(tx, 11, GetTime(), 111.0, 11));
121+
mempool.addUnchecked(hash, entry.Time(GetTime()).FromTx(tx));
118122
tx.vin[0].prevout.hash = hash;
119123
}
120124
BOOST_CHECK(pblocktemplate = CreateNewBlock(chainparams, scriptPubKey));
@@ -134,7 +138,7 @@ BOOST_AUTO_TEST_CASE(CreateNewBlock_validity)
134138
{
135139
tx.vout[0].nValue -= 10000000;
136140
hash = tx.GetHash();
137-
mempool.addUnchecked(hash, CTxMemPoolEntry(tx, 11, GetTime(), 111.0, 11));
141+
mempool.addUnchecked(hash, entry.Time(GetTime()).FromTx(tx));
138142
tx.vin[0].prevout.hash = hash;
139143
}
140144
BOOST_CHECK(pblocktemplate = CreateNewBlock(chainparams, scriptPubKey));
@@ -143,7 +147,7 @@ BOOST_AUTO_TEST_CASE(CreateNewBlock_validity)
143147

144148
// orphan in mempool
145149
hash = tx.GetHash();
146-
mempool.addUnchecked(hash, CTxMemPoolEntry(tx, 11, GetTime(), 111.0, 11));
150+
mempool.addUnchecked(hash, entry.Time(GetTime()).FromTx(tx));
147151
BOOST_CHECK(pblocktemplate = CreateNewBlock(chainparams, scriptPubKey));
148152
delete pblocktemplate;
149153
mempool.clear();
@@ -153,15 +157,15 @@ BOOST_AUTO_TEST_CASE(CreateNewBlock_validity)
153157
tx.vin[0].prevout.hash = txFirst[1]->GetHash();
154158
tx.vout[0].nValue = 4900000000LL;
155159
hash = tx.GetHash();
156-
mempool.addUnchecked(hash, CTxMemPoolEntry(tx, 11, GetTime(), 111.0, 11));
160+
mempool.addUnchecked(hash, entry.Time(GetTime()).FromTx(tx));
157161
tx.vin[0].prevout.hash = hash;
158162
tx.vin.resize(2);
159163
tx.vin[1].scriptSig = CScript() << OP_1;
160164
tx.vin[1].prevout.hash = txFirst[0]->GetHash();
161165
tx.vin[1].prevout.n = 0;
162166
tx.vout[0].nValue = 5900000000LL;
163167
hash = tx.GetHash();
164-
mempool.addUnchecked(hash, CTxMemPoolEntry(tx, 11, GetTime(), 111.0, 11));
168+
mempool.addUnchecked(hash, entry.Time(GetTime()).FromTx(tx));
165169
BOOST_CHECK(pblocktemplate = CreateNewBlock(chainparams, scriptPubKey));
166170
delete pblocktemplate;
167171
mempool.clear();
@@ -172,7 +176,7 @@ BOOST_AUTO_TEST_CASE(CreateNewBlock_validity)
172176
tx.vin[0].scriptSig = CScript() << OP_0 << OP_1;
173177
tx.vout[0].nValue = 0;
174178
hash = tx.GetHash();
175-
mempool.addUnchecked(hash, CTxMemPoolEntry(tx, 11, GetTime(), 111.0, 11));
179+
mempool.addUnchecked(hash, entry.Time(GetTime()).FromTx(tx));
176180
BOOST_CHECK(pblocktemplate = CreateNewBlock(chainparams, scriptPubKey));
177181
delete pblocktemplate;
178182
mempool.clear();
@@ -185,12 +189,12 @@ BOOST_AUTO_TEST_CASE(CreateNewBlock_validity)
185189
script = CScript() << OP_0;
186190
tx.vout[0].scriptPubKey = GetScriptForDestination(CScriptID(script));
187191
hash = tx.GetHash();
188-
mempool.addUnchecked(hash, CTxMemPoolEntry(tx, 11, GetTime(), 111.0, 11));
192+
mempool.addUnchecked(hash, entry.Time(GetTime()).FromTx(tx));
189193
tx.vin[0].prevout.hash = hash;
190194
tx.vin[0].scriptSig = CScript() << (std::vector<unsigned char>)script;
191195
tx.vout[0].nValue -= 1000000;
192196
hash = tx.GetHash();
193-
mempool.addUnchecked(hash, CTxMemPoolEntry(tx, 11, GetTime(), 111.0, 11));
197+
mempool.addUnchecked(hash, entry.Time(GetTime()).FromTx(tx));
194198
BOOST_CHECK(pblocktemplate = CreateNewBlock(chainparams, scriptPubKey));
195199
delete pblocktemplate;
196200
mempool.clear();
@@ -201,10 +205,10 @@ BOOST_AUTO_TEST_CASE(CreateNewBlock_validity)
201205
tx.vout[0].nValue = 4900000000LL;
202206
tx.vout[0].scriptPubKey = CScript() << OP_1;
203207
hash = tx.GetHash();
204-
mempool.addUnchecked(hash, CTxMemPoolEntry(tx, 11, GetTime(), 111.0, 11));
208+
mempool.addUnchecked(hash, entry.Time(GetTime()).FromTx(tx));
205209
tx.vout[0].scriptPubKey = CScript() << OP_2;
206210
hash = tx.GetHash();
207-
mempool.addUnchecked(hash, CTxMemPoolEntry(tx, 11, GetTime(), 111.0, 11));
211+
mempool.addUnchecked(hash, entry.Time(GetTime()).FromTx(tx));
208212
BOOST_CHECK(pblocktemplate = CreateNewBlock(chainparams, scriptPubKey));
209213
delete pblocktemplate;
210214
mempool.clear();
@@ -230,7 +234,7 @@ BOOST_AUTO_TEST_CASE(CreateNewBlock_validity)
230234
tx.vout[0].scriptPubKey = CScript() << OP_1;
231235
tx.nLockTime = chainActive.Tip()->nHeight+1;
232236
hash = tx.GetHash();
233-
mempool.addUnchecked(hash, CTxMemPoolEntry(tx, 11, GetTime(), 111.0, 11));
237+
mempool.addUnchecked(hash, entry.Time(GetTime()).FromTx(tx));
234238
BOOST_CHECK(!CheckFinalTx(tx, LOCKTIME_MEDIAN_TIME_PAST));
235239

236240
// time locked
@@ -244,7 +248,7 @@ BOOST_AUTO_TEST_CASE(CreateNewBlock_validity)
244248
tx2.vout[0].scriptPubKey = CScript() << OP_1;
245249
tx2.nLockTime = chainActive.Tip()->GetMedianTimePast()+1;
246250
hash = tx2.GetHash();
247-
mempool.addUnchecked(hash, CTxMemPoolEntry(tx2, 11, GetTime(), 111.0, 11));
251+
mempool.addUnchecked(hash, entry.Time(GetTime()).FromTx(tx2));
248252
BOOST_CHECK(!CheckFinalTx(tx2, LOCKTIME_MEDIAN_TIME_PAST));
249253

250254
BOOST_CHECK(pblocktemplate = CreateNewBlock(chainparams, scriptPubKey));

src/test/policyestimator_tests.cpp

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -16,6 +16,7 @@ BOOST_FIXTURE_TEST_SUITE(policyestimator_tests, BasicTestingSetup)
1616
BOOST_AUTO_TEST_CASE(BlockPolicyEstimates)
1717
{
1818
CTxMemPool mpool(CFeeRate(1000));
19+
TestMemPoolEntryHelper entry;
1920
CAmount basefee(2000);
2021
double basepri = 1e6;
2122
CAmount deltaFee(100);
@@ -63,7 +64,7 @@ BOOST_AUTO_TEST_CASE(BlockPolicyEstimates)
6364
for (int k = 0; k < 5; k++) { // add 4 fee txs for every priority tx
6465
tx.vin[0].prevout.n = 10000*blocknum+100*j+k; // make transaction unique
6566
uint256 hash = tx.GetHash();
66-
mpool.addUnchecked(hash, CTxMemPoolEntry(tx, feeV[k/4][j], GetTime(), priV[k/4][j], blocknum, mpool.HasNoInputsOf(tx)));
67+
mpool.addUnchecked(hash, entry.Fee(feeV[k/4][j]).Time(GetTime()).Priority(priV[k/4][j]).Height(blocknum).FromTx(tx, &mpool));
6768
txHashes[j].push_back(hash);
6869
}
6970
}
@@ -132,7 +133,7 @@ BOOST_AUTO_TEST_CASE(BlockPolicyEstimates)
132133
for (int k = 0; k < 5; k++) { // add 4 fee txs for every priority tx
133134
tx.vin[0].prevout.n = 10000*blocknum+100*j+k;
134135
uint256 hash = tx.GetHash();
135-
mpool.addUnchecked(hash, CTxMemPoolEntry(tx, feeV[k/4][j], GetTime(), priV[k/4][j], blocknum, mpool.HasNoInputsOf(tx)));
136+
mpool.addUnchecked(hash, entry.Fee(feeV[k/4][j]).Time(GetTime()).Priority(priV[k/4][j]).Height(blocknum).FromTx(tx, &mpool));
136137
txHashes[j].push_back(hash);
137138
}
138139
}
@@ -168,7 +169,7 @@ BOOST_AUTO_TEST_CASE(BlockPolicyEstimates)
168169
for (int k = 0; k < 5; k++) { // add 4 fee txs for every priority tx
169170
tx.vin[0].prevout.n = 10000*blocknum+100*j+k;
170171
uint256 hash = tx.GetHash();
171-
mpool.addUnchecked(hash, CTxMemPoolEntry(tx, feeV[k/4][j], GetTime(), priV[k/4][j], blocknum, mpool.HasNoInputsOf(tx)));
172+
mpool.addUnchecked(hash, entry.Fee(feeV[k/4][j]).Time(GetTime()).Priority(priV[k/4][j]).Height(blocknum).FromTx(tx, &mpool));
172173
CTransaction btx;
173174
if (mpool.lookup(hash, btx))
174175
block.push_back(btx);

src/test/test_bitcoin.cpp

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -15,6 +15,7 @@
1515
#include "pubkey.h"
1616
#include "random.h"
1717
#include "txdb.h"
18+
#include "txmempool.h"
1819
#include "ui_interface.h"
1920
#include "util.h"
2021
#ifdef ENABLE_WALLET
@@ -140,6 +141,12 @@ TestChain100Setup::~TestChain100Setup()
140141
{
141142
}
142143

144+
145+
CTxMemPoolEntry TestMemPoolEntryHelper::FromTx(CMutableTransaction &tx, CTxMemPool *pool) {
146+
return CTxMemPoolEntry(tx, nFee, nTime, dPriority, nHeight,
147+
pool ? pool->HasNoInputsOf(tx) : hadNoDependencies);
148+
}
149+
143150
void Shutdown(void* parg)
144151
{
145152
exit(0);

0 commit comments

Comments
 (0)