18
18
19
19
#include " test/test_bitcoin.h"
20
20
21
+ #include < memory>
22
+
21
23
#include < boost/test/unit_test.hpp>
22
24
23
25
BOOST_FIXTURE_TEST_SUITE (miner_tests, TestingSetup)
@@ -105,7 +107,7 @@ void TestPackageSelection(const CChainParams& chainparams, CScript scriptPubKey,
105
107
uint256 hashHighFeeTx = tx.GetHash ();
106
108
mempool.addUnchecked (hashHighFeeTx, entry.Fee (50000 ).Time (GetTime ()).SpendsCoinbase (false ).FromTx (tx));
107
109
108
- CBlockTemplate * pblocktemplate = BlockAssembler (chainparams).CreateNewBlock (scriptPubKey);
110
+ std::unique_ptr< CBlockTemplate> pblocktemplate = BlockAssembler (chainparams).CreateNewBlock (scriptPubKey);
109
111
BOOST_CHECK (pblocktemplate->block .vtx [1 ].GetHash () == hashParentTx);
110
112
BOOST_CHECK (pblocktemplate->block .vtx [2 ].GetHash () == hashHighFeeTx);
111
113
BOOST_CHECK (pblocktemplate->block .vtx [3 ].GetHash () == hashMediumFeeTx);
@@ -184,7 +186,7 @@ BOOST_AUTO_TEST_CASE(CreateNewBlock_validity)
184
186
// Note that by default, these tests run with size accounting enabled.
185
187
const CChainParams& chainparams = Params (CBaseChainParams::MAIN);
186
188
CScript scriptPubKey = CScript () << ParseHex (" 04678afdb0fe5548271967f1a67130b7105cd6a828e03909a67962e0ea1f61deb649f6bc3f4cef38c4f35504e51ec112de5c384df7ba0b8d578a4c702b6bf11d5f" ) << OP_CHECKSIG;
187
- CBlockTemplate * pblocktemplate;
189
+ std::unique_ptr< CBlockTemplate> pblocktemplate;
188
190
CMutableTransaction tx,tx2;
189
191
CScript script;
190
192
uint256 hash;
@@ -226,11 +228,9 @@ BOOST_AUTO_TEST_CASE(CreateNewBlock_validity)
226
228
BOOST_CHECK (state.IsValid ());
227
229
pblock->hashPrevBlock = pblock->GetHash ();
228
230
}
229
- delete pblocktemplate;
230
231
231
232
// Just to make sure we can still make simple blocks
232
233
BOOST_CHECK (pblocktemplate = BlockAssembler (chainparams).CreateNewBlock (scriptPubKey));
233
- delete pblocktemplate;
234
234
235
235
const CAmount BLOCKSUBSIDY = 50 *COIN;
236
236
const CAmount LOWFEE = CENT;
@@ -269,7 +269,6 @@ BOOST_AUTO_TEST_CASE(CreateNewBlock_validity)
269
269
tx.vin [0 ].prevout .hash = hash;
270
270
}
271
271
BOOST_CHECK (pblocktemplate = BlockAssembler (chainparams).CreateNewBlock (scriptPubKey));
272
- delete pblocktemplate;
273
272
mempool.clear ();
274
273
275
274
// block size > limit
@@ -290,7 +289,6 @@ BOOST_AUTO_TEST_CASE(CreateNewBlock_validity)
290
289
tx.vin [0 ].prevout .hash = hash;
291
290
}
292
291
BOOST_CHECK (pblocktemplate = BlockAssembler (chainparams).CreateNewBlock (scriptPubKey));
293
- delete pblocktemplate;
294
292
mempool.clear ();
295
293
296
294
// orphan in mempool, template creation fails
@@ -314,7 +312,6 @@ BOOST_AUTO_TEST_CASE(CreateNewBlock_validity)
314
312
hash = tx.GetHash ();
315
313
mempool.addUnchecked (hash, entry.Fee (HIGHERFEE).Time (GetTime ()).SpendsCoinbase (true ).FromTx (tx));
316
314
BOOST_CHECK (pblocktemplate = BlockAssembler (chainparams).CreateNewBlock (scriptPubKey));
317
- delete pblocktemplate;
318
315
mempool.clear ();
319
316
320
317
// coinbase in mempool, template creation fails
@@ -372,7 +369,6 @@ BOOST_AUTO_TEST_CASE(CreateNewBlock_validity)
372
369
chainActive.SetTip (next);
373
370
}
374
371
BOOST_CHECK (pblocktemplate = BlockAssembler (chainparams).CreateNewBlock (scriptPubKey));
375
- delete pblocktemplate;
376
372
// Extend to a 210000-long block chain.
377
373
while (chainActive.Tip ()->nHeight < 210000 ) {
378
374
CBlockIndex* prev = chainActive.Tip ();
@@ -385,7 +381,6 @@ BOOST_AUTO_TEST_CASE(CreateNewBlock_validity)
385
381
chainActive.SetTip (next);
386
382
}
387
383
BOOST_CHECK (pblocktemplate = BlockAssembler (chainparams).CreateNewBlock (scriptPubKey));
388
- delete pblocktemplate;
389
384
// Delete the dummy blocks again.
390
385
while (chainActive.Tip ()->nHeight > nHeight) {
391
386
CBlockIndex* del = chainActive.Tip ();
@@ -478,7 +473,6 @@ BOOST_AUTO_TEST_CASE(CreateNewBlock_validity)
478
473
// but relative locked txs will if inconsistently added to mempool.
479
474
// For now these will still generate a valid template until BIP68 soft fork
480
475
BOOST_CHECK_EQUAL (pblocktemplate->block .vtx .size (), 3 );
481
- delete pblocktemplate;
482
476
// However if we advance height by 1 and time by 512, all of them should be mined
483
477
for (int i = 0 ; i < CBlockIndex::nMedianTimeSpan; i++)
484
478
chainActive.Tip ()->GetAncestor (chainActive.Tip ()->nHeight - i)->nTime += 512 ; // Trick the MedianTimePast
@@ -487,7 +481,6 @@ BOOST_AUTO_TEST_CASE(CreateNewBlock_validity)
487
481
488
482
BOOST_CHECK (pblocktemplate = BlockAssembler (chainparams).CreateNewBlock (scriptPubKey));
489
483
BOOST_CHECK_EQUAL (pblocktemplate->block .vtx .size (), 5 );
490
- delete pblocktemplate;
491
484
492
485
chainActive.Tip ()->nHeight --;
493
486
SetMockTime (0 );
0 commit comments