@@ -27,6 +27,15 @@ BOOST_FIXTURE_TEST_SUITE(miner_tests, TestingSetup)
27
27
28
28
static CFeeRate blockMinFeeRate = CFeeRate(DEFAULT_BLOCK_MIN_TX_FEE);
29
29
30
+ static BlockAssembler AssemblerForTest (const CChainParams& params) {
31
+ BlockAssembler::Options options;
32
+
33
+ options.nBlockMaxWeight = MAX_BLOCK_WEIGHT;
34
+ options.nBlockMaxSize = MAX_BLOCK_SERIALIZED_SIZE;
35
+ options.blockMinFeeRate = blockMinFeeRate;
36
+ return BlockAssembler (params, options);
37
+ }
38
+
30
39
static
31
40
struct {
32
41
unsigned char extranonce;
@@ -110,7 +119,7 @@ void TestPackageSelection(const CChainParams& chainparams, CScript scriptPubKey,
110
119
uint256 hashHighFeeTx = tx.GetHash ();
111
120
mempool.addUnchecked (hashHighFeeTx, entry.Fee (50000 ).Time (GetTime ()).SpendsCoinbase (false ).FromTx (tx));
112
121
113
- std::unique_ptr<CBlockTemplate> pblocktemplate = BlockAssembler (chainparams).CreateNewBlock (scriptPubKey);
122
+ std::unique_ptr<CBlockTemplate> pblocktemplate = AssemblerForTest (chainparams).CreateNewBlock (scriptPubKey);
114
123
BOOST_CHECK (pblocktemplate->block .vtx [1 ]->GetHash () == hashParentTx);
115
124
BOOST_CHECK (pblocktemplate->block .vtx [2 ]->GetHash () == hashHighFeeTx);
116
125
BOOST_CHECK (pblocktemplate->block .vtx [3 ]->GetHash () == hashMediumFeeTx);
@@ -130,7 +139,7 @@ void TestPackageSelection(const CChainParams& chainparams, CScript scriptPubKey,
130
139
tx.vout [0 ].nValue = 5000000000LL - 1000 - 50000 - feeToUse;
131
140
uint256 hashLowFeeTx = tx.GetHash ();
132
141
mempool.addUnchecked (hashLowFeeTx, entry.Fee (feeToUse).FromTx (tx));
133
- pblocktemplate = BlockAssembler (chainparams).CreateNewBlock (scriptPubKey);
142
+ pblocktemplate = AssemblerForTest (chainparams).CreateNewBlock (scriptPubKey);
134
143
// Verify that the free tx and the low fee tx didn't get selected
135
144
for (size_t i=0 ; i<pblocktemplate->block .vtx .size (); ++i) {
136
145
BOOST_CHECK (pblocktemplate->block .vtx [i]->GetHash () != hashFreeTx);
@@ -144,7 +153,7 @@ void TestPackageSelection(const CChainParams& chainparams, CScript scriptPubKey,
144
153
tx.vout [0 ].nValue -= 2 ; // Now we should be just over the min relay fee
145
154
hashLowFeeTx = tx.GetHash ();
146
155
mempool.addUnchecked (hashLowFeeTx, entry.Fee (feeToUse+2 ).FromTx (tx));
147
- pblocktemplate = BlockAssembler (chainparams).CreateNewBlock (scriptPubKey);
156
+ pblocktemplate = AssemblerForTest (chainparams).CreateNewBlock (scriptPubKey);
148
157
BOOST_CHECK (pblocktemplate->block .vtx [4 ]->GetHash () == hashFreeTx);
149
158
BOOST_CHECK (pblocktemplate->block .vtx [5 ]->GetHash () == hashLowFeeTx);
150
159
@@ -165,7 +174,7 @@ void TestPackageSelection(const CChainParams& chainparams, CScript scriptPubKey,
165
174
tx.vout [0 ].nValue = 5000000000LL - 100000000 - feeToUse;
166
175
uint256 hashLowFeeTx2 = tx.GetHash ();
167
176
mempool.addUnchecked (hashLowFeeTx2, entry.Fee (feeToUse).SpendsCoinbase (false ).FromTx (tx));
168
- pblocktemplate = BlockAssembler (chainparams).CreateNewBlock (scriptPubKey);
177
+ pblocktemplate = AssemblerForTest (chainparams).CreateNewBlock (scriptPubKey);
169
178
170
179
// Verify that this tx isn't selected.
171
180
for (size_t i=0 ; i<pblocktemplate->block .vtx .size (); ++i) {
@@ -178,7 +187,7 @@ void TestPackageSelection(const CChainParams& chainparams, CScript scriptPubKey,
178
187
tx.vin [0 ].prevout .n = 1 ;
179
188
tx.vout [0 ].nValue = 100000000 - 10000 ; // 10k satoshi fee
180
189
mempool.addUnchecked (tx.GetHash (), entry.Fee (10000 ).FromTx (tx));
181
- pblocktemplate = BlockAssembler (chainparams).CreateNewBlock (scriptPubKey);
190
+ pblocktemplate = AssemblerForTest (chainparams).CreateNewBlock (scriptPubKey);
182
191
BOOST_CHECK (pblocktemplate->block .vtx [8 ]->GetHash () == hashLowFeeTx2);
183
192
}
184
193
@@ -201,7 +210,7 @@ BOOST_AUTO_TEST_CASE(CreateNewBlock_validity)
201
210
fCheckpointsEnabled = false ;
202
211
203
212
// Simple block creation, nothing special yet:
204
- BOOST_CHECK (pblocktemplate = BlockAssembler (chainparams).CreateNewBlock (scriptPubKey));
213
+ BOOST_CHECK (pblocktemplate = AssemblerForTest (chainparams).CreateNewBlock (scriptPubKey));
205
214
206
215
// We can't make transactions until we have inputs
207
216
// Therefore, load 100 blocks :)
@@ -232,7 +241,7 @@ BOOST_AUTO_TEST_CASE(CreateNewBlock_validity)
232
241
}
233
242
234
243
// Just to make sure we can still make simple blocks
235
- BOOST_CHECK (pblocktemplate = BlockAssembler (chainparams).CreateNewBlock (scriptPubKey));
244
+ BOOST_CHECK (pblocktemplate = AssemblerForTest (chainparams).CreateNewBlock (scriptPubKey));
236
245
237
246
const CAmount BLOCKSUBSIDY = 50 *COIN;
238
247
const CAmount LOWFEE = CENT;
@@ -256,7 +265,7 @@ BOOST_AUTO_TEST_CASE(CreateNewBlock_validity)
256
265
mempool.addUnchecked (hash, entry.Fee (LOWFEE).Time (GetTime ()).SpendsCoinbase (spendsCoinbase).FromTx (tx));
257
266
tx.vin [0 ].prevout .hash = hash;
258
267
}
259
- BOOST_CHECK_THROW (BlockAssembler (chainparams).CreateNewBlock (scriptPubKey), std::runtime_error);
268
+ BOOST_CHECK_THROW (AssemblerForTest (chainparams).CreateNewBlock (scriptPubKey), std::runtime_error);
260
269
mempool.clear ();
261
270
262
271
tx.vin [0 ].prevout .hash = txFirst[0 ]->GetHash ();
@@ -270,7 +279,7 @@ BOOST_AUTO_TEST_CASE(CreateNewBlock_validity)
270
279
mempool.addUnchecked (hash, entry.Fee (LOWFEE).Time (GetTime ()).SpendsCoinbase (spendsCoinbase).SigOpsCost (80 ).FromTx (tx));
271
280
tx.vin [0 ].prevout .hash = hash;
272
281
}
273
- BOOST_CHECK (pblocktemplate = BlockAssembler (chainparams).CreateNewBlock (scriptPubKey));
282
+ BOOST_CHECK (pblocktemplate = AssemblerForTest (chainparams).CreateNewBlock (scriptPubKey));
274
283
mempool.clear ();
275
284
276
285
// block size > limit
@@ -290,13 +299,13 @@ BOOST_AUTO_TEST_CASE(CreateNewBlock_validity)
290
299
mempool.addUnchecked (hash, entry.Fee (LOWFEE).Time (GetTime ()).SpendsCoinbase (spendsCoinbase).FromTx (tx));
291
300
tx.vin [0 ].prevout .hash = hash;
292
301
}
293
- BOOST_CHECK (pblocktemplate = BlockAssembler (chainparams).CreateNewBlock (scriptPubKey));
302
+ BOOST_CHECK (pblocktemplate = AssemblerForTest (chainparams).CreateNewBlock (scriptPubKey));
294
303
mempool.clear ();
295
304
296
305
// orphan in mempool, template creation fails
297
306
hash = tx.GetHash ();
298
307
mempool.addUnchecked (hash, entry.Fee (LOWFEE).Time (GetTime ()).FromTx (tx));
299
- BOOST_CHECK_THROW (BlockAssembler (chainparams).CreateNewBlock (scriptPubKey), std::runtime_error);
308
+ BOOST_CHECK_THROW (AssemblerForTest (chainparams).CreateNewBlock (scriptPubKey), std::runtime_error);
300
309
mempool.clear ();
301
310
302
311
// child with higher priority than parent
@@ -313,7 +322,7 @@ BOOST_AUTO_TEST_CASE(CreateNewBlock_validity)
313
322
tx.vout [0 ].nValue = tx.vout [0 ].nValue +BLOCKSUBSIDY-HIGHERFEE; // First txn output + fresh coinbase - new txn fee
314
323
hash = tx.GetHash ();
315
324
mempool.addUnchecked (hash, entry.Fee (HIGHERFEE).Time (GetTime ()).SpendsCoinbase (true ).FromTx (tx));
316
- BOOST_CHECK (pblocktemplate = BlockAssembler (chainparams).CreateNewBlock (scriptPubKey));
325
+ BOOST_CHECK (pblocktemplate = AssemblerForTest (chainparams).CreateNewBlock (scriptPubKey));
317
326
mempool.clear ();
318
327
319
328
// coinbase in mempool, template creation fails
@@ -324,7 +333,7 @@ BOOST_AUTO_TEST_CASE(CreateNewBlock_validity)
324
333
hash = tx.GetHash ();
325
334
// give it a fee so it'll get mined
326
335
mempool.addUnchecked (hash, entry.Fee (LOWFEE).Time (GetTime ()).SpendsCoinbase (false ).FromTx (tx));
327
- BOOST_CHECK_THROW (BlockAssembler (chainparams).CreateNewBlock (scriptPubKey), std::runtime_error);
336
+ BOOST_CHECK_THROW (AssemblerForTest (chainparams).CreateNewBlock (scriptPubKey), std::runtime_error);
328
337
mempool.clear ();
329
338
330
339
// invalid (pre-p2sh) txn in mempool, template creation fails
@@ -341,7 +350,7 @@ BOOST_AUTO_TEST_CASE(CreateNewBlock_validity)
341
350
tx.vout [0 ].nValue -= LOWFEE;
342
351
hash = tx.GetHash ();
343
352
mempool.addUnchecked (hash, entry.Fee (LOWFEE).Time (GetTime ()).SpendsCoinbase (false ).FromTx (tx));
344
- BOOST_CHECK_THROW (BlockAssembler (chainparams).CreateNewBlock (scriptPubKey), std::runtime_error);
353
+ BOOST_CHECK_THROW (AssemblerForTest (chainparams).CreateNewBlock (scriptPubKey), std::runtime_error);
345
354
mempool.clear ();
346
355
347
356
// double spend txn pair in mempool, template creation fails
@@ -354,7 +363,7 @@ BOOST_AUTO_TEST_CASE(CreateNewBlock_validity)
354
363
tx.vout [0 ].scriptPubKey = CScript () << OP_2;
355
364
hash = tx.GetHash ();
356
365
mempool.addUnchecked (hash, entry.Fee (HIGHFEE).Time (GetTime ()).SpendsCoinbase (true ).FromTx (tx));
357
- BOOST_CHECK_THROW (BlockAssembler (chainparams).CreateNewBlock (scriptPubKey), std::runtime_error);
366
+ BOOST_CHECK_THROW (AssemblerForTest (chainparams).CreateNewBlock (scriptPubKey), std::runtime_error);
358
367
mempool.clear ();
359
368
360
369
// subsidy changing
@@ -370,7 +379,7 @@ BOOST_AUTO_TEST_CASE(CreateNewBlock_validity)
370
379
next->BuildSkip ();
371
380
chainActive.SetTip (next);
372
381
}
373
- BOOST_CHECK (pblocktemplate = BlockAssembler (chainparams).CreateNewBlock (scriptPubKey));
382
+ BOOST_CHECK (pblocktemplate = AssemblerForTest (chainparams).CreateNewBlock (scriptPubKey));
374
383
// Extend to a 210000-long block chain.
375
384
while (chainActive.Tip ()->nHeight < 210000 ) {
376
385
CBlockIndex* prev = chainActive.Tip ();
@@ -382,7 +391,7 @@ BOOST_AUTO_TEST_CASE(CreateNewBlock_validity)
382
391
next->BuildSkip ();
383
392
chainActive.SetTip (next);
384
393
}
385
- BOOST_CHECK (pblocktemplate = BlockAssembler (chainparams).CreateNewBlock (scriptPubKey));
394
+ BOOST_CHECK (pblocktemplate = AssemblerForTest (chainparams).CreateNewBlock (scriptPubKey));
386
395
// Delete the dummy blocks again.
387
396
while (chainActive.Tip ()->nHeight > nHeight) {
388
397
CBlockIndex* del = chainActive.Tip ();
@@ -468,7 +477,7 @@ BOOST_AUTO_TEST_CASE(CreateNewBlock_validity)
468
477
tx.vin [0 ].nSequence = CTxIn::SEQUENCE_LOCKTIME_TYPE_FLAG | 1 ;
469
478
BOOST_CHECK (!TestSequenceLocks (tx, flags)); // Sequence locks fail
470
479
471
- BOOST_CHECK (pblocktemplate = BlockAssembler (chainparams).CreateNewBlock (scriptPubKey));
480
+ BOOST_CHECK (pblocktemplate = AssemblerForTest (chainparams).CreateNewBlock (scriptPubKey));
472
481
473
482
// None of the of the absolute height/time locked tx should have made
474
483
// it into the template because we still check IsFinalTx in CreateNewBlock,
@@ -481,7 +490,7 @@ BOOST_AUTO_TEST_CASE(CreateNewBlock_validity)
481
490
chainActive.Tip ()->nHeight ++;
482
491
SetMockTime (chainActive.Tip ()->GetMedianTimePast () + 1 );
483
492
484
- BOOST_CHECK (pblocktemplate = BlockAssembler (chainparams).CreateNewBlock (scriptPubKey));
493
+ BOOST_CHECK (pblocktemplate = AssemblerForTest (chainparams).CreateNewBlock (scriptPubKey));
485
494
BOOST_CHECK_EQUAL (pblocktemplate->block .vtx .size (), 5 );
486
495
487
496
chainActive.Tip ()->nHeight --;
0 commit comments