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);
@@ -183,7 +185,7 @@ BOOST_AUTO_TEST_CASE(CreateNewBlock_validity)
183
185
{
184
186
const CChainParams& chainparams = Params (CBaseChainParams::MAIN);
185
187
CScript scriptPubKey = CScript () << ParseHex (" 04678afdb0fe5548271967f1a67130b7105cd6a828e03909a67962e0ea1f61deb649f6bc3f4cef38c4f35504e51ec112de5c384df7ba0b8d578a4c702b6bf11d5f" ) << OP_CHECKSIG;
186
- CBlockTemplate * pblocktemplate;
188
+ std::unique_ptr< CBlockTemplate> pblocktemplate;
187
189
CMutableTransaction tx,tx2;
188
190
CScript script;
189
191
uint256 hash;
@@ -225,11 +227,9 @@ BOOST_AUTO_TEST_CASE(CreateNewBlock_validity)
225
227
BOOST_CHECK (state.IsValid ());
226
228
pblock->hashPrevBlock = pblock->GetHash ();
227
229
}
228
- delete pblocktemplate;
229
230
230
231
// Just to make sure we can still make simple blocks
231
232
BOOST_CHECK (pblocktemplate = BlockAssembler (chainparams).CreateNewBlock (scriptPubKey));
232
- delete pblocktemplate;
233
233
234
234
const CAmount BLOCKSUBSIDY = 50 *COIN;
235
235
const CAmount LOWFEE = CENT;
@@ -268,7 +268,6 @@ BOOST_AUTO_TEST_CASE(CreateNewBlock_validity)
268
268
tx.vin [0 ].prevout .hash = hash;
269
269
}
270
270
BOOST_CHECK (pblocktemplate = BlockAssembler (chainparams).CreateNewBlock (scriptPubKey));
271
- delete pblocktemplate;
272
271
mempool.clear ();
273
272
274
273
// block size > limit
@@ -289,7 +288,6 @@ BOOST_AUTO_TEST_CASE(CreateNewBlock_validity)
289
288
tx.vin [0 ].prevout .hash = hash;
290
289
}
291
290
BOOST_CHECK (pblocktemplate = BlockAssembler (chainparams).CreateNewBlock (scriptPubKey));
292
- delete pblocktemplate;
293
291
mempool.clear ();
294
292
295
293
// orphan in mempool, template creation fails
@@ -313,7 +311,6 @@ BOOST_AUTO_TEST_CASE(CreateNewBlock_validity)
313
311
hash = tx.GetHash ();
314
312
mempool.addUnchecked (hash, entry.Fee (HIGHERFEE).Time (GetTime ()).SpendsCoinbase (true ).FromTx (tx));
315
313
BOOST_CHECK (pblocktemplate = BlockAssembler (chainparams).CreateNewBlock (scriptPubKey));
316
- delete pblocktemplate;
317
314
mempool.clear ();
318
315
319
316
// coinbase in mempool, template creation fails
@@ -371,7 +368,6 @@ BOOST_AUTO_TEST_CASE(CreateNewBlock_validity)
371
368
chainActive.SetTip (next);
372
369
}
373
370
BOOST_CHECK (pblocktemplate = BlockAssembler (chainparams).CreateNewBlock (scriptPubKey));
374
- delete pblocktemplate;
375
371
// Extend to a 210000-long block chain.
376
372
while (chainActive.Tip ()->nHeight < 210000 ) {
377
373
CBlockIndex* prev = chainActive.Tip ();
@@ -384,7 +380,6 @@ BOOST_AUTO_TEST_CASE(CreateNewBlock_validity)
384
380
chainActive.SetTip (next);
385
381
}
386
382
BOOST_CHECK (pblocktemplate = BlockAssembler (chainparams).CreateNewBlock (scriptPubKey));
387
- delete pblocktemplate;
388
383
// Delete the dummy blocks again.
389
384
while (chainActive.Tip ()->nHeight > nHeight) {
390
385
CBlockIndex* del = chainActive.Tip ();
@@ -477,7 +472,6 @@ BOOST_AUTO_TEST_CASE(CreateNewBlock_validity)
477
472
// but relative locked txs will if inconsistently added to mempool.
478
473
// For now these will still generate a valid template until BIP68 soft fork
479
474
BOOST_CHECK_EQUAL (pblocktemplate->block .vtx .size (), 3 );
480
- delete pblocktemplate;
481
475
// However if we advance height by 1 and time by 512, all of them should be mined
482
476
for (int i = 0 ; i < CBlockIndex::nMedianTimeSpan; i++)
483
477
chainActive.Tip ()->GetAncestor (chainActive.Tip ()->nHeight - i)->nTime += 512 ; // Trick the MedianTimePast
@@ -486,7 +480,6 @@ BOOST_AUTO_TEST_CASE(CreateNewBlock_validity)
486
480
487
481
BOOST_CHECK (pblocktemplate = BlockAssembler (chainparams).CreateNewBlock (scriptPubKey));
488
482
BOOST_CHECK_EQUAL (pblocktemplate->block .vtx .size (), 5 );
489
- delete pblocktemplate;
490
483
491
484
chainActive.Tip ()->nHeight --;
492
485
SetMockTime (0 );
0 commit comments