Skip to content

Commit 277b472

Browse files
committed
Run miner_tests with fixed options
1 parent 48faf0b commit 277b472

File tree

1 file changed

+28
-19
lines changed

1 file changed

+28
-19
lines changed

src/test/miner_tests.cpp

Lines changed: 28 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -27,6 +27,15 @@ BOOST_FIXTURE_TEST_SUITE(miner_tests, TestingSetup)
2727

2828
static CFeeRate blockMinFeeRate = CFeeRate(DEFAULT_BLOCK_MIN_TX_FEE);
2929

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+
3039
static
3140
struct {
3241
unsigned char extranonce;
@@ -110,7 +119,7 @@ void TestPackageSelection(const CChainParams& chainparams, CScript scriptPubKey,
110119
uint256 hashHighFeeTx = tx.GetHash();
111120
mempool.addUnchecked(hashHighFeeTx, entry.Fee(50000).Time(GetTime()).SpendsCoinbase(false).FromTx(tx));
112121

113-
std::unique_ptr<CBlockTemplate> pblocktemplate = BlockAssembler(chainparams).CreateNewBlock(scriptPubKey);
122+
std::unique_ptr<CBlockTemplate> pblocktemplate = AssemblerForTest(chainparams).CreateNewBlock(scriptPubKey);
114123
BOOST_CHECK(pblocktemplate->block.vtx[1]->GetHash() == hashParentTx);
115124
BOOST_CHECK(pblocktemplate->block.vtx[2]->GetHash() == hashHighFeeTx);
116125
BOOST_CHECK(pblocktemplate->block.vtx[3]->GetHash() == hashMediumFeeTx);
@@ -130,7 +139,7 @@ void TestPackageSelection(const CChainParams& chainparams, CScript scriptPubKey,
130139
tx.vout[0].nValue = 5000000000LL - 1000 - 50000 - feeToUse;
131140
uint256 hashLowFeeTx = tx.GetHash();
132141
mempool.addUnchecked(hashLowFeeTx, entry.Fee(feeToUse).FromTx(tx));
133-
pblocktemplate = BlockAssembler(chainparams).CreateNewBlock(scriptPubKey);
142+
pblocktemplate = AssemblerForTest(chainparams).CreateNewBlock(scriptPubKey);
134143
// Verify that the free tx and the low fee tx didn't get selected
135144
for (size_t i=0; i<pblocktemplate->block.vtx.size(); ++i) {
136145
BOOST_CHECK(pblocktemplate->block.vtx[i]->GetHash() != hashFreeTx);
@@ -144,7 +153,7 @@ void TestPackageSelection(const CChainParams& chainparams, CScript scriptPubKey,
144153
tx.vout[0].nValue -= 2; // Now we should be just over the min relay fee
145154
hashLowFeeTx = tx.GetHash();
146155
mempool.addUnchecked(hashLowFeeTx, entry.Fee(feeToUse+2).FromTx(tx));
147-
pblocktemplate = BlockAssembler(chainparams).CreateNewBlock(scriptPubKey);
156+
pblocktemplate = AssemblerForTest(chainparams).CreateNewBlock(scriptPubKey);
148157
BOOST_CHECK(pblocktemplate->block.vtx[4]->GetHash() == hashFreeTx);
149158
BOOST_CHECK(pblocktemplate->block.vtx[5]->GetHash() == hashLowFeeTx);
150159

@@ -165,7 +174,7 @@ void TestPackageSelection(const CChainParams& chainparams, CScript scriptPubKey,
165174
tx.vout[0].nValue = 5000000000LL - 100000000 - feeToUse;
166175
uint256 hashLowFeeTx2 = tx.GetHash();
167176
mempool.addUnchecked(hashLowFeeTx2, entry.Fee(feeToUse).SpendsCoinbase(false).FromTx(tx));
168-
pblocktemplate = BlockAssembler(chainparams).CreateNewBlock(scriptPubKey);
177+
pblocktemplate = AssemblerForTest(chainparams).CreateNewBlock(scriptPubKey);
169178

170179
// Verify that this tx isn't selected.
171180
for (size_t i=0; i<pblocktemplate->block.vtx.size(); ++i) {
@@ -178,7 +187,7 @@ void TestPackageSelection(const CChainParams& chainparams, CScript scriptPubKey,
178187
tx.vin[0].prevout.n = 1;
179188
tx.vout[0].nValue = 100000000 - 10000; // 10k satoshi fee
180189
mempool.addUnchecked(tx.GetHash(), entry.Fee(10000).FromTx(tx));
181-
pblocktemplate = BlockAssembler(chainparams).CreateNewBlock(scriptPubKey);
190+
pblocktemplate = AssemblerForTest(chainparams).CreateNewBlock(scriptPubKey);
182191
BOOST_CHECK(pblocktemplate->block.vtx[8]->GetHash() == hashLowFeeTx2);
183192
}
184193

@@ -201,7 +210,7 @@ BOOST_AUTO_TEST_CASE(CreateNewBlock_validity)
201210
fCheckpointsEnabled = false;
202211

203212
// Simple block creation, nothing special yet:
204-
BOOST_CHECK(pblocktemplate = BlockAssembler(chainparams).CreateNewBlock(scriptPubKey));
213+
BOOST_CHECK(pblocktemplate = AssemblerForTest(chainparams).CreateNewBlock(scriptPubKey));
205214

206215
// We can't make transactions until we have inputs
207216
// Therefore, load 100 blocks :)
@@ -232,7 +241,7 @@ BOOST_AUTO_TEST_CASE(CreateNewBlock_validity)
232241
}
233242

234243
// 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));
236245

237246
const CAmount BLOCKSUBSIDY = 50*COIN;
238247
const CAmount LOWFEE = CENT;
@@ -256,7 +265,7 @@ BOOST_AUTO_TEST_CASE(CreateNewBlock_validity)
256265
mempool.addUnchecked(hash, entry.Fee(LOWFEE).Time(GetTime()).SpendsCoinbase(spendsCoinbase).FromTx(tx));
257266
tx.vin[0].prevout.hash = hash;
258267
}
259-
BOOST_CHECK_THROW(BlockAssembler(chainparams).CreateNewBlock(scriptPubKey), std::runtime_error);
268+
BOOST_CHECK_THROW(AssemblerForTest(chainparams).CreateNewBlock(scriptPubKey), std::runtime_error);
260269
mempool.clear();
261270

262271
tx.vin[0].prevout.hash = txFirst[0]->GetHash();
@@ -270,7 +279,7 @@ BOOST_AUTO_TEST_CASE(CreateNewBlock_validity)
270279
mempool.addUnchecked(hash, entry.Fee(LOWFEE).Time(GetTime()).SpendsCoinbase(spendsCoinbase).SigOpsCost(80).FromTx(tx));
271280
tx.vin[0].prevout.hash = hash;
272281
}
273-
BOOST_CHECK(pblocktemplate = BlockAssembler(chainparams).CreateNewBlock(scriptPubKey));
282+
BOOST_CHECK(pblocktemplate = AssemblerForTest(chainparams).CreateNewBlock(scriptPubKey));
274283
mempool.clear();
275284

276285
// block size > limit
@@ -290,13 +299,13 @@ BOOST_AUTO_TEST_CASE(CreateNewBlock_validity)
290299
mempool.addUnchecked(hash, entry.Fee(LOWFEE).Time(GetTime()).SpendsCoinbase(spendsCoinbase).FromTx(tx));
291300
tx.vin[0].prevout.hash = hash;
292301
}
293-
BOOST_CHECK(pblocktemplate = BlockAssembler(chainparams).CreateNewBlock(scriptPubKey));
302+
BOOST_CHECK(pblocktemplate = AssemblerForTest(chainparams).CreateNewBlock(scriptPubKey));
294303
mempool.clear();
295304

296305
// orphan in mempool, template creation fails
297306
hash = tx.GetHash();
298307
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);
300309
mempool.clear();
301310

302311
// child with higher priority than parent
@@ -313,7 +322,7 @@ BOOST_AUTO_TEST_CASE(CreateNewBlock_validity)
313322
tx.vout[0].nValue = tx.vout[0].nValue+BLOCKSUBSIDY-HIGHERFEE; //First txn output + fresh coinbase - new txn fee
314323
hash = tx.GetHash();
315324
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));
317326
mempool.clear();
318327

319328
// coinbase in mempool, template creation fails
@@ -324,7 +333,7 @@ BOOST_AUTO_TEST_CASE(CreateNewBlock_validity)
324333
hash = tx.GetHash();
325334
// give it a fee so it'll get mined
326335
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);
328337
mempool.clear();
329338

330339
// invalid (pre-p2sh) txn in mempool, template creation fails
@@ -341,7 +350,7 @@ BOOST_AUTO_TEST_CASE(CreateNewBlock_validity)
341350
tx.vout[0].nValue -= LOWFEE;
342351
hash = tx.GetHash();
343352
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);
345354
mempool.clear();
346355

347356
// double spend txn pair in mempool, template creation fails
@@ -354,7 +363,7 @@ BOOST_AUTO_TEST_CASE(CreateNewBlock_validity)
354363
tx.vout[0].scriptPubKey = CScript() << OP_2;
355364
hash = tx.GetHash();
356365
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);
358367
mempool.clear();
359368

360369
// subsidy changing
@@ -370,7 +379,7 @@ BOOST_AUTO_TEST_CASE(CreateNewBlock_validity)
370379
next->BuildSkip();
371380
chainActive.SetTip(next);
372381
}
373-
BOOST_CHECK(pblocktemplate = BlockAssembler(chainparams).CreateNewBlock(scriptPubKey));
382+
BOOST_CHECK(pblocktemplate = AssemblerForTest(chainparams).CreateNewBlock(scriptPubKey));
374383
// Extend to a 210000-long block chain.
375384
while (chainActive.Tip()->nHeight < 210000) {
376385
CBlockIndex* prev = chainActive.Tip();
@@ -382,7 +391,7 @@ BOOST_AUTO_TEST_CASE(CreateNewBlock_validity)
382391
next->BuildSkip();
383392
chainActive.SetTip(next);
384393
}
385-
BOOST_CHECK(pblocktemplate = BlockAssembler(chainparams).CreateNewBlock(scriptPubKey));
394+
BOOST_CHECK(pblocktemplate = AssemblerForTest(chainparams).CreateNewBlock(scriptPubKey));
386395
// Delete the dummy blocks again.
387396
while (chainActive.Tip()->nHeight > nHeight) {
388397
CBlockIndex* del = chainActive.Tip();
@@ -468,7 +477,7 @@ BOOST_AUTO_TEST_CASE(CreateNewBlock_validity)
468477
tx.vin[0].nSequence = CTxIn::SEQUENCE_LOCKTIME_TYPE_FLAG | 1;
469478
BOOST_CHECK(!TestSequenceLocks(tx, flags)); // Sequence locks fail
470479

471-
BOOST_CHECK(pblocktemplate = BlockAssembler(chainparams).CreateNewBlock(scriptPubKey));
480+
BOOST_CHECK(pblocktemplate = AssemblerForTest(chainparams).CreateNewBlock(scriptPubKey));
472481

473482
// None of the of the absolute height/time locked tx should have made
474483
// it into the template because we still check IsFinalTx in CreateNewBlock,
@@ -481,7 +490,7 @@ BOOST_AUTO_TEST_CASE(CreateNewBlock_validity)
481490
chainActive.Tip()->nHeight++;
482491
SetMockTime(chainActive.Tip()->GetMedianTimePast() + 1);
483492

484-
BOOST_CHECK(pblocktemplate = BlockAssembler(chainparams).CreateNewBlock(scriptPubKey));
493+
BOOST_CHECK(pblocktemplate = AssemblerForTest(chainparams).CreateNewBlock(scriptPubKey));
485494
BOOST_CHECK_EQUAL(pblocktemplate->block.vtx.size(), 5);
486495

487496
chainActive.Tip()->nHeight--;

0 commit comments

Comments
 (0)