Skip to content

Commit d10acd5

Browse files
committed
[Tests] move pwalletMain to wallet test fixture + use smart pointer
>>> inspired by bitcoin/bitcoin@49bd659 + bitcoin/bitcoin@f94c2ec
1 parent d6cf608 commit d10acd5

11 files changed

+121
-101
lines changed

src/test/librust/sapling_rpc_wallet_tests.cpp

Lines changed: 40 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -25,7 +25,6 @@
2525

2626
#include <univalue.h>
2727

28-
extern CWallet* pwalletMain;
2928

3029
extern UniValue CallRPC(std::string args); // Implemented in rpc_tests.cpp
3130

@@ -57,6 +56,8 @@ BOOST_FIXTURE_TEST_SUITE(sapling_rpc_wallet_tests, WalletTestingSetup)
5756
BOOST_AUTO_TEST_CASE(rpc_wallet_sapling_validateaddress)
5857
{
5958
SelectParams(CBaseChainParams::MAIN);
59+
vpwallets.insert(vpwallets.begin(), pwalletMain.get());
60+
6061
UniValue retValue;
6162

6263
// Check number of args
@@ -83,6 +84,8 @@ BOOST_AUTO_TEST_CASE(rpc_wallet_sapling_validateaddress)
8384
BOOST_CHECK_EQUAL(b, false);
8485
BOOST_CHECK_EQUAL(find_value(resultObj, "diversifier").get_str(), "e1fd627f1b9a8e4c7e6657");
8586
BOOST_CHECK_EQUAL(find_value(resultObj, "diversifiedtransmissionkey").get_str(), "d35e0d0897edbd3cf02b3d2327622a14c685534dbd2d3f4f4fa3e0e56cc2f008");
87+
88+
vpwallets.erase(vpwallets.begin());
8689
}
8790

8891
BOOST_AUTO_TEST_CASE(rpc_wallet_getbalance)
@@ -92,6 +95,7 @@ BOOST_AUTO_TEST_CASE(rpc_wallet_getbalance)
9295
pwalletMain->SetMinVersion(FEATURE_SAPLING);
9396
pwalletMain->SetupSPKM(false);
9497
}
98+
vpwallets.insert(vpwallets.begin(), pwalletMain.get());
9599

96100
BOOST_CHECK_THROW(CallRPC("getshieldbalance too many args"), std::runtime_error);
97101
BOOST_CHECK_THROW(CallRPC("getshieldbalance invalidaddress"), std::runtime_error);
@@ -111,6 +115,8 @@ BOOST_AUTO_TEST_CASE(rpc_wallet_getbalance)
111115
BOOST_CHECK_THROW(CallRPC("listreceivedbyshieldaddress DMKU6mc52un1MThGCsnNwAtEvncaTdAuaZ 0"), std::runtime_error);
112116
// don't have the spending key
113117
BOOST_CHECK_THROW(CallRPC("listreceivedbyshieldaddress ps1u87kylcmn28yclnx2uy0psnvuhs2xn608ukm6n2nshrpg2nzyu3n62ls8j77m9cgp40dx40evej 1"), std::runtime_error);
118+
119+
vpwallets.erase(vpwallets.begin());
114120
}
115121

116122
BOOST_AUTO_TEST_CASE(rpc_wallet_sapling_importkey_paymentaddress)
@@ -120,6 +126,7 @@ BOOST_AUTO_TEST_CASE(rpc_wallet_sapling_importkey_paymentaddress)
120126
pwalletMain->SetMinVersion(FEATURE_SAPLING);
121127
pwalletMain->SetupSPKM(false);
122128
}
129+
vpwallets.insert(vpwallets.begin(), pwalletMain.get());
123130

124131
auto testAddress = [](const std::string& key) {
125132
UniValue ret;
@@ -137,6 +144,7 @@ BOOST_AUTO_TEST_CASE(rpc_wallet_sapling_importkey_paymentaddress)
137144
"8uqmqlx8ccxpsw7ae243quhwr0zyekrrc520gs9z0j8pm954c3cev2yvp29vrc"
138145
"0zweu7stxkwhp593p6drheps9uhz9pvkrfgvpxzte8d60uzw0qxadnsc77tcd");
139146

147+
vpwallets.erase(vpwallets.begin());
140148
}
141149

142150
/*
@@ -149,6 +157,8 @@ BOOST_AUTO_TEST_CASE(rpc_wallet_sapling_importexport)
149157
pwalletMain->SetMinVersion(FEATURE_SAPLING);
150158
pwalletMain->SetupSPKM(false);
151159
}
160+
vpwallets.insert(vpwallets.begin(), pwalletMain.get());
161+
152162
UniValue retValue;
153163
int n1 = 1000; // number of times to import/export
154164
int n2 = 1000; // number of addresses to create and list
@@ -223,15 +233,17 @@ BOOST_AUTO_TEST_CASE(rpc_wallet_sapling_importexport)
223233
BOOST_CHECK((int) listaddrs.size() == numAddrs);
224234
BOOST_CHECK(myaddrs == listaddrs);
225235

236+
vpwallets.erase(vpwallets.begin());
226237
}
227238

228239
// Check if address is of given type and spendable from our wallet.
229-
void CheckHaveAddr(const libzcash::PaymentAddress& addr) {
240+
void CheckHaveAddr(std::unique_ptr<CWallet>& pwallet, const libzcash::PaymentAddress& addr)
241+
{
230242

231243
BOOST_CHECK(IsValidPaymentAddress(addr));
232244
auto addr_of_type = boost::get<libzcash::SaplingPaymentAddress>(&addr);
233245
BOOST_ASSERT(addr_of_type != nullptr);
234-
BOOST_CHECK(pwalletMain->HaveSpendingKeyForPaymentAddress(*addr_of_type));
246+
BOOST_CHECK(pwallet->HaveSpendingKeyForPaymentAddress(*addr_of_type));
235247
}
236248

237249
BOOST_AUTO_TEST_CASE(rpc_wallet_getnewshieldaddress)
@@ -241,12 +253,15 @@ BOOST_AUTO_TEST_CASE(rpc_wallet_getnewshieldaddress)
241253
pwalletMain->SetMinVersion(FEATURE_SAPLING);
242254
pwalletMain->SetupSPKM(false);
243255
}
256+
vpwallets.insert(vpwallets.begin(), pwalletMain.get());
244257

245258
// No parameter defaults to sapling address
246259
UniValue addr = CallRPC("getnewshieldaddress");
247-
CheckHaveAddr(KeyIO::DecodePaymentAddress(addr.get_str()));
260+
CheckHaveAddr(pwalletMain, KeyIO::DecodePaymentAddress(addr.get_str()));
248261
// Too many arguments will throw with the help
249262
BOOST_CHECK_THROW(CallRPC("getnewshieldaddress many args"), std::runtime_error);
263+
264+
vpwallets.erase(vpwallets.begin());
250265
}
251266

252267
BOOST_AUTO_TEST_CASE(rpc_shieldsendmany_parameters)
@@ -256,6 +271,7 @@ BOOST_AUTO_TEST_CASE(rpc_shieldsendmany_parameters)
256271
pwalletMain->SetMinVersion(FEATURE_SAPLING);
257272
pwalletMain->SetupSPKM(false);
258273
}
274+
vpwallets.insert(vpwallets.begin(), pwalletMain.get());
259275

260276
BOOST_CHECK_THROW(CallRPC("shieldsendmany"), std::runtime_error);
261277
BOOST_CHECK_THROW(CallRPC("shieldsendmany toofewargs"), std::runtime_error);
@@ -308,16 +324,20 @@ BOOST_AUTO_TEST_CASE(rpc_shieldsendmany_parameters)
308324
std::string zaddr1 = KeyIO::EncodePaymentAddress(pa);
309325
BOOST_CHECK_THROW(CallRPC(std::string("shieldsendmany DMKU6mc52un1MThGCsnNwAtEvncaTdAuaZ ")
310326
+ "[{\"address\":\"" + zaddr1 + "\", \"amount\":123.456}]"), std::runtime_error);
327+
328+
vpwallets.erase(vpwallets.begin());
311329
}
312330

331+
// TODO: test private methods
313332
BOOST_AUTO_TEST_CASE(saplingOperationTests)
314333
{
315334
{
316335
LOCK2(cs_main, pwalletMain->cs_wallet);
317336
pwalletMain->SetupSPKM(false);
318337
}
319-
320338
auto consensusParams = Params().GetConsensus();
339+
vpwallets.insert(vpwallets.begin(), pwalletMain.get());
340+
321341
UniValue retValue;
322342

323343
// add keys manually
@@ -330,7 +350,7 @@ BOOST_AUTO_TEST_CASE(saplingOperationTests)
330350
// there are no utxos to spend
331351
{
332352
std::vector<SendManyRecipient> recipients = { SendManyRecipient(zaddr1, COIN, "DEADBEEF") };
333-
SaplingOperation operation(consensusParams, 1, pwalletMain);
353+
SaplingOperation operation(consensusParams, 1, pwalletMain.get());
334354
operation.setFromAddress(taddr1);
335355
auto res = operation.setRecipients(recipients)->buildAndSend(ret);
336356
BOOST_CHECK(!res);
@@ -340,7 +360,7 @@ BOOST_AUTO_TEST_CASE(saplingOperationTests)
340360
// minconf cannot be zero when sending from zaddr
341361
{
342362
std::vector<SendManyRecipient> recipients = { SendManyRecipient(zaddr1, COIN, "DEADBEEF") };
343-
SaplingOperation operation(consensusParams, 1, pwalletMain);
363+
SaplingOperation operation(consensusParams, 1, pwalletMain.get());
344364
operation.setFromAddress(zaddr1);
345365
auto res = operation.setRecipients(recipients)->setMinDepth(0)->buildAndSend(ret);
346366
BOOST_CHECK(!res);
@@ -350,7 +370,7 @@ BOOST_AUTO_TEST_CASE(saplingOperationTests)
350370
// there are no unspent notes to spend
351371
{
352372
std::vector<SendManyRecipient> recipients = { SendManyRecipient(taddr1, COIN) };
353-
SaplingOperation operation(consensusParams, 1, pwalletMain);
373+
SaplingOperation operation(consensusParams, 1, pwalletMain.get());
354374
operation.setFromAddress(zaddr1);
355375
auto res = operation.setRecipients(recipients)->buildAndSend(ret);
356376
BOOST_CHECK(!res);
@@ -385,6 +405,8 @@ BOOST_AUTO_TEST_CASE(saplingOperationTests)
385405
const std::string& errStr = res.getError();
386406
BOOST_CHECK(errStr.find("too big") != std::string::npos);
387407
}
408+
409+
vpwallets.erase(vpwallets.begin());
388410
}
389411

390412

@@ -394,6 +416,7 @@ BOOST_AUTO_TEST_CASE(rpc_shieldsendmany_taddr_to_sapling)
394416
LOCK2(cs_main, pwalletMain->cs_wallet);
395417
pwalletMain->SetupSPKM(false);
396418
}
419+
vpwallets.insert(vpwallets.begin(), pwalletMain.get());
397420

398421
UniValue retValue;
399422

@@ -411,7 +434,7 @@ BOOST_AUTO_TEST_CASE(rpc_shieldsendmany_taddr_to_sapling)
411434
CMutableTransaction mtx;
412435
mtx.vout.emplace_back(5 * COIN, GetScriptForDestination(taddr));
413436
// Add to wallet and get the updated wtx
414-
CWalletTx wtxIn(pwalletMain, MakeTransactionRef(mtx));
437+
CWalletTx wtxIn(pwalletMain.get(), MakeTransactionRef(mtx));
415438
pwalletMain->LoadToWallet(wtxIn);
416439
CWalletTx& wtx = pwalletMain->mapWallet.at(mtx.GetHash());
417440

@@ -433,15 +456,15 @@ BOOST_AUTO_TEST_CASE(rpc_shieldsendmany_taddr_to_sapling)
433456
BOOST_CHECK_MESSAGE(pwalletMain->GetAvailableBalance() > 0, "tx not confirmed");
434457

435458
std::vector<SendManyRecipient> recipients = { SendManyRecipient(zaddr1, 1 * COIN, "ABCD") };
436-
SaplingOperation operation(consensusParams, nextBlockHeight, pwalletMain);
459+
SaplingOperation operation(consensusParams, nextBlockHeight, pwalletMain.get());
437460
operation.setFromAddress(taddr);
438461
BOOST_CHECK(operation.setRecipients(recipients)
439462
->setMinDepth(0)
440463
->build());
441464

442465
// try from auto-selected transparent address
443466
std::vector<SendManyRecipient> recipients2 = { SendManyRecipient(zaddr1, 1 * COIN, "ABCD") };
444-
SaplingOperation operation2(consensusParams, nextBlockHeight, pwalletMain);
467+
SaplingOperation operation2(consensusParams, nextBlockHeight, pwalletMain.get());
445468
BOOST_CHECK(operation2.setSelectTransparentCoins(true)
446469
->setRecipients(recipients2)
447470
->setMinDepth(0)
@@ -472,6 +495,7 @@ BOOST_AUTO_TEST_CASE(rpc_shieldsendmany_taddr_to_sapling)
472495
// Tear down
473496
chainActive.SetTip(nullptr);
474497
mapBlockIndex.erase(blockHash);
498+
vpwallets.erase(vpwallets.begin());
475499
}
476500

477501
BOOST_AUTO_TEST_CASE(rpc_wallet_encrypted_wallet_sapzkeys)
@@ -484,6 +508,7 @@ BOOST_AUTO_TEST_CASE(rpc_wallet_encrypted_wallet_sapzkeys)
484508
pwalletMain->SetMinVersion(FEATURE_SAPLING);
485509
pwalletMain->SetupSPKM(false);
486510
}
511+
vpwallets.insert(vpwallets.begin(), pwalletMain.get());
487512

488513
// wallet should currently be empty
489514
std::set<libzcash::SaplingPaymentAddress> addrs;
@@ -532,8 +557,7 @@ BOOST_AUTO_TEST_CASE(rpc_wallet_encrypted_wallet_sapzkeys)
532557
arr = retValue.get_array();
533558
BOOST_CHECK((int) arr.size() == n+1);
534559

535-
// We can't simulate over RPC the wallet closing and being reloaded
536-
// but there are tests for this in gtest.
560+
vpwallets.erase(vpwallets.begin());
537561
}
538562

539563
BOOST_AUTO_TEST_CASE(rpc_listshieldunspent_parameters)
@@ -542,6 +566,7 @@ BOOST_AUTO_TEST_CASE(rpc_listshieldunspent_parameters)
542566
LOCK(pwalletMain->cs_wallet);
543567
pwalletMain->SetupSPKM(false);
544568
}
569+
vpwallets.insert(vpwallets.begin(), pwalletMain.get());
545570

546571
UniValue retValue;
547572

@@ -583,6 +608,8 @@ BOOST_AUTO_TEST_CASE(rpc_listshieldunspent_parameters)
583608

584609
// duplicate address error
585610
BOOST_CHECK_THROW(CallRPC("listshieldunspent 1 999 false [\"" + myzaddr + "\", \"" + myzaddr + "\"]"), std::runtime_error);
611+
612+
vpwallets.erase(vpwallets.begin());
586613
}
587614

588615
BOOST_AUTO_TEST_SUITE_END()

src/test/librust/sapling_wallet_tests.cpp

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -25,8 +25,6 @@
2525

2626
#include <boost/test/unit_test.hpp>
2727

28-
extern CWallet* pwalletMain;
29-
3028
void setupWallet(CWallet& wallet)
3129
{
3230
wallet.SetMinVersion(FEATURE_SAPLING);

src/test/librust/wallet_zkeys_tests.cpp

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -12,8 +12,6 @@
1212
#include "util/system.h"
1313
#include <boost/test/unit_test.hpp>
1414

15-
extern CWallet* pwalletMain;
16-
1715
/**
1816
* This test covers methods on CWallet
1917
* GenerateNewZKey()
@@ -172,7 +170,7 @@ BOOST_AUTO_TEST_CASE(WriteCryptedSaplingZkeyDirectToDb) {
172170
BOOST_CHECK_EQUAL(DB_LOAD_OK, wallet2.LoadWallet(fFirstRun));
173171

174172
// Confirm it's not the same as the other wallet
175-
BOOST_CHECK(pwalletMain != &wallet2);
173+
BOOST_CHECK(pwalletMain.get() != &wallet2);
176174
BOOST_CHECK(wallet2.HasSaplingSPKM());
177175

178176
// wallet should have two keys

src/test/miner_tests.cpp

Lines changed: 12 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -17,7 +17,6 @@
1717

1818
#include <boost/test/unit_test.hpp>
1919

20-
extern CWallet* pwalletMain;
2120

2221
// future: this should be MAINNET.
2322
BOOST_FIXTURE_TEST_SUITE(miner_tests, WalletRegTestingSetup)
@@ -91,7 +90,7 @@ BOOST_AUTO_TEST_CASE(CreateNewBlock_validity)
9190
Checkpoints::fEnabled = false;
9291

9392
// Simple block creation, nothing special yet:
94-
BOOST_CHECK(pblocktemplate = BlockAssembler(Params(), DEFAULT_PRINTPRIORITY).CreateNewBlock(scriptPubKey, pwalletMain, false));
93+
BOOST_CHECK(pblocktemplate = BlockAssembler(Params(), DEFAULT_PRINTPRIORITY).CreateNewBlock(scriptPubKey, pwalletMain.get(), false));
9594
// Set genesis block
9695
pblocktemplate->block.hashPrevBlock = chainparams.GetConsensus().hashGenesisBlock;
9796

@@ -117,7 +116,7 @@ BOOST_AUTO_TEST_CASE(CreateNewBlock_validity)
117116
}
118117

119118
// Just to make sure we can still make simple blocks
120-
BOOST_CHECK(pblocktemplate = BlockAssembler(Params(), DEFAULT_PRINTPRIORITY).CreateNewBlock(scriptPubKey, pwalletMain, false));
119+
BOOST_CHECK(pblocktemplate = BlockAssembler(Params(), DEFAULT_PRINTPRIORITY).CreateNewBlock(scriptPubKey, pwalletMain.get(), false));
121120

122121
// block sigops > limit: 2000 CHECKMULTISIG + 1
123122
tx.vin.resize(1);
@@ -135,7 +134,7 @@ BOOST_AUTO_TEST_CASE(CreateNewBlock_validity)
135134
mempool.addUnchecked(hash, entry.Fee(1000000).Time(GetTime()).SpendsCoinbaseOrCoinstake(spendsCoinbase).FromTx(tx));
136135
tx.vin[0].prevout.hash = hash;
137136
}
138-
BOOST_CHECK_EXCEPTION(pblocktemplate = BlockAssembler(Params(), DEFAULT_PRINTPRIORITY).CreateNewBlock(scriptPubKey, pwalletMain, false), std::runtime_error, HasReason("bad-blk-sigops"));
137+
BOOST_CHECK_EXCEPTION(pblocktemplate = BlockAssembler(Params(), DEFAULT_PRINTPRIORITY).CreateNewBlock(scriptPubKey, pwalletMain.get(), false), std::runtime_error, HasReason("bad-blk-sigops"));
139138
mempool.clear();
140139

141140
tx.vin[0].prevout.hash = txFirst[0]->GetHash();
@@ -148,7 +147,7 @@ BOOST_AUTO_TEST_CASE(CreateNewBlock_validity)
148147
mempool.addUnchecked(hash, entry.Fee(1000000).Time(GetTime()).SpendsCoinbaseOrCoinstake(spendsCoinbase).SigOps(20).FromTx(tx));
149148
tx.vin[0].prevout.hash = hash;
150149
}
151-
BOOST_CHECK(pblocktemplate = BlockAssembler(Params(), DEFAULT_PRINTPRIORITY).CreateNewBlock(scriptPubKey, pwalletMain, false));
150+
BOOST_CHECK(pblocktemplate = BlockAssembler(Params(), DEFAULT_PRINTPRIORITY).CreateNewBlock(scriptPubKey, pwalletMain.get(), false));
152151
mempool.clear();
153152

154153
// block size > limit
@@ -168,13 +167,13 @@ BOOST_AUTO_TEST_CASE(CreateNewBlock_validity)
168167
mempool.addUnchecked(hash, entry.Fee(1000000).Time(GetTime()).SpendsCoinbaseOrCoinstake(spendsCoinbase).FromTx(tx));
169168
tx.vin[0].prevout.hash = hash;
170169
}
171-
BOOST_CHECK(pblocktemplate = BlockAssembler(Params(), DEFAULT_PRINTPRIORITY).CreateNewBlock(scriptPubKey, pwalletMain, false));
170+
BOOST_CHECK(pblocktemplate = BlockAssembler(Params(), DEFAULT_PRINTPRIORITY).CreateNewBlock(scriptPubKey, pwalletMain.get(), false));
172171
mempool.clear();
173172

174173
// orphan in mempool, template creation fails
175174
hash = tx.GetHash();
176175
mempool.addUnchecked(hash, entry.Fee(1000000).Time(GetTime()).FromTx(tx));
177-
BOOST_CHECK_EXCEPTION(pblocktemplate = BlockAssembler(Params(), DEFAULT_PRINTPRIORITY).CreateNewBlock(scriptPubKey, pwalletMain, false), std::runtime_error, HasReason("bad-txns-inputs-missingorspent"));
176+
BOOST_CHECK_EXCEPTION(pblocktemplate = BlockAssembler(Params(), DEFAULT_PRINTPRIORITY).CreateNewBlock(scriptPubKey, pwalletMain.get(), false), std::runtime_error, HasReason("bad-txns-inputs-missingorspent"));
178177
mempool.clear();
179178

180179
// child with higher priority than parent
@@ -191,7 +190,7 @@ BOOST_AUTO_TEST_CASE(CreateNewBlock_validity)
191190
tx.vout[0].nValue = 5900000000LL;
192191
hash = tx.GetHash();
193192
mempool.addUnchecked(hash, entry.Fee(400000000LL).Time(GetTime()).SpendsCoinbaseOrCoinstake(true).FromTx(tx));
194-
BOOST_CHECK(pblocktemplate = BlockAssembler(Params(), DEFAULT_PRINTPRIORITY).CreateNewBlock(scriptPubKey, pwalletMain, false));
193+
BOOST_CHECK(pblocktemplate = BlockAssembler(Params(), DEFAULT_PRINTPRIORITY).CreateNewBlock(scriptPubKey, pwalletMain.get(), false));
195194
mempool.clear();
196195

197196
// coinbase in mempool, template creation fails
@@ -202,7 +201,7 @@ BOOST_AUTO_TEST_CASE(CreateNewBlock_validity)
202201
hash = tx.GetHash();
203202
// give it a fee so it'll get mined
204203
mempool.addUnchecked(hash, entry.Fee(100000).Time(GetTime()).SpendsCoinbaseOrCoinstake(false).FromTx(tx));
205-
BOOST_CHECK_EXCEPTION(pblocktemplate = BlockAssembler(Params(), DEFAULT_PRINTPRIORITY).CreateNewBlock(scriptPubKey, pwalletMain, false), std::runtime_error, HasReason("bad-cb-multiple"));
204+
BOOST_CHECK_EXCEPTION(pblocktemplate = BlockAssembler(Params(), DEFAULT_PRINTPRIORITY).CreateNewBlock(scriptPubKey, pwalletMain.get(), false), std::runtime_error, HasReason("bad-cb-multiple"));
206205
mempool.clear();
207206

208207
// invalid (pre-p2sh) txn in mempool, template creation fails
@@ -220,7 +219,7 @@ BOOST_AUTO_TEST_CASE(CreateNewBlock_validity)
220219
hash = tx.GetHash();
221220
mempool.addUnchecked(hash, entry.Fee(1000000).Time(GetTime()).SpendsCoinbaseOrCoinstake(false).FromTx(tx));
222221
// Should throw block-validation-failed
223-
BOOST_CHECK_EXCEPTION(pblocktemplate = BlockAssembler(Params(), DEFAULT_PRINTPRIORITY).CreateNewBlock(scriptPubKey, pwalletMain, false), std::runtime_error, HasReason("block-validation-failed"));
222+
BOOST_CHECK_EXCEPTION(pblocktemplate = BlockAssembler(Params(), DEFAULT_PRINTPRIORITY).CreateNewBlock(scriptPubKey, pwalletMain.get(), false), std::runtime_error, HasReason("block-validation-failed"));
224223
mempool.clear();
225224

226225
// double spend txn pair in mempool, template creation fails
@@ -233,7 +232,7 @@ BOOST_AUTO_TEST_CASE(CreateNewBlock_validity)
233232
tx.vout[0].scriptPubKey = CScript() << OP_2;
234233
hash = tx.GetHash();
235234
mempool.addUnchecked(hash, entry.Fee(100000000L).Time(GetTime()).SpendsCoinbaseOrCoinstake(true).FromTx(tx));
236-
BOOST_CHECK_EXCEPTION(pblocktemplate = BlockAssembler(Params(), DEFAULT_PRINTPRIORITY).CreateNewBlock(scriptPubKey, pwalletMain, false), std::runtime_error, HasReason("bad-txns-inputs-missingorspent"));
235+
BOOST_CHECK_EXCEPTION(pblocktemplate = BlockAssembler(Params(), DEFAULT_PRINTPRIORITY).CreateNewBlock(scriptPubKey, pwalletMain.get(), false), std::runtime_error, HasReason("bad-txns-inputs-missingorspent"));
237236
mempool.clear();
238237

239238
// non-final txs in mempool
@@ -264,7 +263,7 @@ BOOST_AUTO_TEST_CASE(CreateNewBlock_validity)
264263
mempool.addUnchecked(hash, entry.Fee(100000000L).Time(GetTime()).SpendsCoinbaseOrCoinstake(true).FromTx(tx2));
265264
{ LOCK(cs_main); BOOST_CHECK(!CheckFinalTx(MakeTransactionRef(tx2), LOCKTIME_MEDIAN_TIME_PAST)); }
266265

267-
BOOST_CHECK(pblocktemplate = BlockAssembler(Params(), DEFAULT_PRINTPRIORITY).CreateNewBlock(scriptPubKey, pwalletMain, false));
266+
BOOST_CHECK(pblocktemplate = BlockAssembler(Params(), DEFAULT_PRINTPRIORITY).CreateNewBlock(scriptPubKey, pwalletMain.get(), false));
268267

269268
// Neither tx should have make it into the template.
270269
BOOST_CHECK_EQUAL(pblocktemplate->block.vtx.size(), 1);
@@ -281,7 +280,7 @@ BOOST_AUTO_TEST_CASE(CreateNewBlock_validity)
281280
//BOOST_CHECK(CheckFinalTx(tx));
282281
//BOOST_CHECK(CheckFinalTx(tx2));
283282

284-
BOOST_CHECK(pblocktemplate = BlockAssembler(Params(), DEFAULT_PRINTPRIORITY).CreateNewBlock(scriptPubKey, pwalletMain, false));
283+
BOOST_CHECK(pblocktemplate = BlockAssembler(Params(), DEFAULT_PRINTPRIORITY).CreateNewBlock(scriptPubKey, pwalletMain.get(), false));
285284
BOOST_CHECK_EQUAL(pblocktemplate->block.vtx.size(), 3);
286285

287286
WITH_LOCK(cs_main, chainActive.Tip()->nHeight--);

src/test/script_P2CS_tests.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -307,7 +307,7 @@ BOOST_AUTO_TEST_CASE(fake_script_test)
307307
{
308308
BOOST_ASSERT(!g_IsV6Active);
309309

310-
CWallet& wallet = *vpwallets[0];
310+
CWallet& wallet = *pwalletMain;
311311
LOCK(wallet.cs_wallet);
312312
setupWallet(wallet);
313313
CKey stakerKey; // dummy staker key (not in the wallet)

0 commit comments

Comments
 (0)