25
25
26
26
#include < univalue.h>
27
27
28
- extern CWallet* pwalletMain;
29
28
30
29
extern UniValue CallRPC (std::string args); // Implemented in rpc_tests.cpp
31
30
@@ -57,6 +56,8 @@ BOOST_FIXTURE_TEST_SUITE(sapling_rpc_wallet_tests, WalletTestingSetup)
57
56
BOOST_AUTO_TEST_CASE(rpc_wallet_sapling_validateaddress)
58
57
{
59
58
SelectParams (CBaseChainParams::MAIN);
59
+ vpwallets.insert (vpwallets.begin (), pwalletMain.get ());
60
+
60
61
UniValue retValue;
61
62
62
63
// Check number of args
@@ -83,6 +84,8 @@ BOOST_AUTO_TEST_CASE(rpc_wallet_sapling_validateaddress)
83
84
BOOST_CHECK_EQUAL (b, false );
84
85
BOOST_CHECK_EQUAL (find_value (resultObj, " diversifier" ).get_str (), " e1fd627f1b9a8e4c7e6657" );
85
86
BOOST_CHECK_EQUAL (find_value (resultObj, " diversifiedtransmissionkey" ).get_str (), " d35e0d0897edbd3cf02b3d2327622a14c685534dbd2d3f4f4fa3e0e56cc2f008" );
87
+
88
+ vpwallets.erase (vpwallets.begin ());
86
89
}
87
90
88
91
BOOST_AUTO_TEST_CASE (rpc_wallet_getbalance)
@@ -92,6 +95,7 @@ BOOST_AUTO_TEST_CASE(rpc_wallet_getbalance)
92
95
pwalletMain->SetMinVersion (FEATURE_SAPLING);
93
96
pwalletMain->SetupSPKM (false );
94
97
}
98
+ vpwallets.insert (vpwallets.begin (), pwalletMain.get ());
95
99
96
100
BOOST_CHECK_THROW (CallRPC (" getshieldbalance too many args" ), std::runtime_error);
97
101
BOOST_CHECK_THROW (CallRPC (" getshieldbalance invalidaddress" ), std::runtime_error);
@@ -111,6 +115,8 @@ BOOST_AUTO_TEST_CASE(rpc_wallet_getbalance)
111
115
BOOST_CHECK_THROW (CallRPC (" listreceivedbyshieldaddress DMKU6mc52un1MThGCsnNwAtEvncaTdAuaZ 0" ), std::runtime_error);
112
116
// don't have the spending key
113
117
BOOST_CHECK_THROW (CallRPC (" listreceivedbyshieldaddress ps1u87kylcmn28yclnx2uy0psnvuhs2xn608ukm6n2nshrpg2nzyu3n62ls8j77m9cgp40dx40evej 1" ), std::runtime_error);
118
+
119
+ vpwallets.erase (vpwallets.begin ());
114
120
}
115
121
116
122
BOOST_AUTO_TEST_CASE (rpc_wallet_sapling_importkey_paymentaddress)
@@ -120,6 +126,7 @@ BOOST_AUTO_TEST_CASE(rpc_wallet_sapling_importkey_paymentaddress)
120
126
pwalletMain->SetMinVersion (FEATURE_SAPLING);
121
127
pwalletMain->SetupSPKM (false );
122
128
}
129
+ vpwallets.insert (vpwallets.begin (), pwalletMain.get ());
123
130
124
131
auto testAddress = [](const std::string& key) {
125
132
UniValue ret;
@@ -137,6 +144,7 @@ BOOST_AUTO_TEST_CASE(rpc_wallet_sapling_importkey_paymentaddress)
137
144
" 8uqmqlx8ccxpsw7ae243quhwr0zyekrrc520gs9z0j8pm954c3cev2yvp29vrc"
138
145
" 0zweu7stxkwhp593p6drheps9uhz9pvkrfgvpxzte8d60uzw0qxadnsc77tcd" );
139
146
147
+ vpwallets.erase (vpwallets.begin ());
140
148
}
141
149
142
150
/*
@@ -149,6 +157,8 @@ BOOST_AUTO_TEST_CASE(rpc_wallet_sapling_importexport)
149
157
pwalletMain->SetMinVersion (FEATURE_SAPLING);
150
158
pwalletMain->SetupSPKM (false );
151
159
}
160
+ vpwallets.insert (vpwallets.begin (), pwalletMain.get ());
161
+
152
162
UniValue retValue;
153
163
int n1 = 1000 ; // number of times to import/export
154
164
int n2 = 1000 ; // number of addresses to create and list
@@ -223,15 +233,17 @@ BOOST_AUTO_TEST_CASE(rpc_wallet_sapling_importexport)
223
233
BOOST_CHECK ((int ) listaddrs.size () == numAddrs);
224
234
BOOST_CHECK (myaddrs == listaddrs);
225
235
236
+ vpwallets.erase (vpwallets.begin ());
226
237
}
227
238
228
239
// 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
+ {
230
242
231
243
BOOST_CHECK (IsValidPaymentAddress (addr));
232
244
auto addr_of_type = boost::get<libzcash::SaplingPaymentAddress>(&addr);
233
245
BOOST_ASSERT (addr_of_type != nullptr );
234
- BOOST_CHECK (pwalletMain ->HaveSpendingKeyForPaymentAddress (*addr_of_type));
246
+ BOOST_CHECK (pwallet ->HaveSpendingKeyForPaymentAddress (*addr_of_type));
235
247
}
236
248
237
249
BOOST_AUTO_TEST_CASE (rpc_wallet_getnewshieldaddress)
@@ -241,12 +253,15 @@ BOOST_AUTO_TEST_CASE(rpc_wallet_getnewshieldaddress)
241
253
pwalletMain->SetMinVersion (FEATURE_SAPLING);
242
254
pwalletMain->SetupSPKM (false );
243
255
}
256
+ vpwallets.insert (vpwallets.begin (), pwalletMain.get ());
244
257
245
258
// No parameter defaults to sapling address
246
259
UniValue addr = CallRPC (" getnewshieldaddress" );
247
- CheckHaveAddr (KeyIO::DecodePaymentAddress (addr.get_str ()));
260
+ CheckHaveAddr (pwalletMain, KeyIO::DecodePaymentAddress (addr.get_str ()));
248
261
// Too many arguments will throw with the help
249
262
BOOST_CHECK_THROW (CallRPC (" getnewshieldaddress many args" ), std::runtime_error);
263
+
264
+ vpwallets.erase (vpwallets.begin ());
250
265
}
251
266
252
267
BOOST_AUTO_TEST_CASE (rpc_shieldsendmany_parameters)
@@ -256,6 +271,7 @@ BOOST_AUTO_TEST_CASE(rpc_shieldsendmany_parameters)
256
271
pwalletMain->SetMinVersion (FEATURE_SAPLING);
257
272
pwalletMain->SetupSPKM (false );
258
273
}
274
+ vpwallets.insert (vpwallets.begin (), pwalletMain.get ());
259
275
260
276
BOOST_CHECK_THROW (CallRPC (" shieldsendmany" ), std::runtime_error);
261
277
BOOST_CHECK_THROW (CallRPC (" shieldsendmany toofewargs" ), std::runtime_error);
@@ -308,16 +324,20 @@ BOOST_AUTO_TEST_CASE(rpc_shieldsendmany_parameters)
308
324
std::string zaddr1 = KeyIO::EncodePaymentAddress (pa);
309
325
BOOST_CHECK_THROW (CallRPC (std::string (" shieldsendmany DMKU6mc52un1MThGCsnNwAtEvncaTdAuaZ " )
310
326
+ " [{\" address\" :\" " + zaddr1 + " \" , \" amount\" :123.456}]" ), std::runtime_error);
327
+
328
+ vpwallets.erase (vpwallets.begin ());
311
329
}
312
330
331
+ // TODO: test private methods
313
332
BOOST_AUTO_TEST_CASE (saplingOperationTests)
314
333
{
315
334
{
316
335
LOCK2 (cs_main, pwalletMain->cs_wallet );
317
336
pwalletMain->SetupSPKM (false );
318
337
}
319
-
320
338
auto consensusParams = Params ().GetConsensus ();
339
+ vpwallets.insert (vpwallets.begin (), pwalletMain.get ());
340
+
321
341
UniValue retValue;
322
342
323
343
// add keys manually
@@ -330,7 +350,7 @@ BOOST_AUTO_TEST_CASE(saplingOperationTests)
330
350
// there are no utxos to spend
331
351
{
332
352
std::vector<SendManyRecipient> recipients = { SendManyRecipient (zaddr1, COIN, " DEADBEEF" ) };
333
- SaplingOperation operation (consensusParams, 1 , pwalletMain);
353
+ SaplingOperation operation (consensusParams, 1 , pwalletMain. get () );
334
354
operation.setFromAddress (taddr1);
335
355
auto res = operation.setRecipients (recipients)->buildAndSend (ret);
336
356
BOOST_CHECK (!res);
@@ -340,7 +360,7 @@ BOOST_AUTO_TEST_CASE(saplingOperationTests)
340
360
// minconf cannot be zero when sending from zaddr
341
361
{
342
362
std::vector<SendManyRecipient> recipients = { SendManyRecipient (zaddr1, COIN, " DEADBEEF" ) };
343
- SaplingOperation operation (consensusParams, 1 , pwalletMain);
363
+ SaplingOperation operation (consensusParams, 1 , pwalletMain. get () );
344
364
operation.setFromAddress (zaddr1);
345
365
auto res = operation.setRecipients (recipients)->setMinDepth (0 )->buildAndSend (ret);
346
366
BOOST_CHECK (!res);
@@ -350,7 +370,7 @@ BOOST_AUTO_TEST_CASE(saplingOperationTests)
350
370
// there are no unspent notes to spend
351
371
{
352
372
std::vector<SendManyRecipient> recipients = { SendManyRecipient (taddr1, COIN) };
353
- SaplingOperation operation (consensusParams, 1 , pwalletMain);
373
+ SaplingOperation operation (consensusParams, 1 , pwalletMain. get () );
354
374
operation.setFromAddress (zaddr1);
355
375
auto res = operation.setRecipients (recipients)->buildAndSend (ret);
356
376
BOOST_CHECK (!res);
@@ -385,6 +405,8 @@ BOOST_AUTO_TEST_CASE(saplingOperationTests)
385
405
const std::string& errStr = res.getError ();
386
406
BOOST_CHECK (errStr.find (" too big" ) != std::string::npos);
387
407
}
408
+
409
+ vpwallets.erase (vpwallets.begin ());
388
410
}
389
411
390
412
@@ -394,6 +416,7 @@ BOOST_AUTO_TEST_CASE(rpc_shieldsendmany_taddr_to_sapling)
394
416
LOCK2 (cs_main, pwalletMain->cs_wallet );
395
417
pwalletMain->SetupSPKM (false );
396
418
}
419
+ vpwallets.insert (vpwallets.begin (), pwalletMain.get ());
397
420
398
421
UniValue retValue;
399
422
@@ -411,7 +434,7 @@ BOOST_AUTO_TEST_CASE(rpc_shieldsendmany_taddr_to_sapling)
411
434
CMutableTransaction mtx;
412
435
mtx.vout .emplace_back (5 * COIN, GetScriptForDestination (taddr));
413
436
// Add to wallet and get the updated wtx
414
- CWalletTx wtxIn (pwalletMain, MakeTransactionRef (mtx));
437
+ CWalletTx wtxIn (pwalletMain. get () , MakeTransactionRef (mtx));
415
438
pwalletMain->LoadToWallet (wtxIn);
416
439
CWalletTx& wtx = pwalletMain->mapWallet .at (mtx.GetHash ());
417
440
@@ -433,15 +456,15 @@ BOOST_AUTO_TEST_CASE(rpc_shieldsendmany_taddr_to_sapling)
433
456
BOOST_CHECK_MESSAGE (pwalletMain->GetAvailableBalance () > 0 , " tx not confirmed" );
434
457
435
458
std::vector<SendManyRecipient> recipients = { SendManyRecipient (zaddr1, 1 * COIN, " ABCD" ) };
436
- SaplingOperation operation (consensusParams, nextBlockHeight, pwalletMain);
459
+ SaplingOperation operation (consensusParams, nextBlockHeight, pwalletMain. get () );
437
460
operation.setFromAddress (taddr);
438
461
BOOST_CHECK (operation.setRecipients (recipients)
439
462
->setMinDepth (0 )
440
463
->build ());
441
464
442
465
// try from auto-selected transparent address
443
466
std::vector<SendManyRecipient> recipients2 = { SendManyRecipient (zaddr1, 1 * COIN, " ABCD" ) };
444
- SaplingOperation operation2 (consensusParams, nextBlockHeight, pwalletMain);
467
+ SaplingOperation operation2 (consensusParams, nextBlockHeight, pwalletMain. get () );
445
468
BOOST_CHECK (operation2.setSelectTransparentCoins (true )
446
469
->setRecipients (recipients2)
447
470
->setMinDepth (0 )
@@ -472,6 +495,7 @@ BOOST_AUTO_TEST_CASE(rpc_shieldsendmany_taddr_to_sapling)
472
495
// Tear down
473
496
chainActive.SetTip (nullptr );
474
497
mapBlockIndex.erase (blockHash);
498
+ vpwallets.erase (vpwallets.begin ());
475
499
}
476
500
477
501
BOOST_AUTO_TEST_CASE (rpc_wallet_encrypted_wallet_sapzkeys)
@@ -484,6 +508,7 @@ BOOST_AUTO_TEST_CASE(rpc_wallet_encrypted_wallet_sapzkeys)
484
508
pwalletMain->SetMinVersion (FEATURE_SAPLING);
485
509
pwalletMain->SetupSPKM (false );
486
510
}
511
+ vpwallets.insert (vpwallets.begin (), pwalletMain.get ());
487
512
488
513
// wallet should currently be empty
489
514
std::set<libzcash::SaplingPaymentAddress> addrs;
@@ -532,8 +557,7 @@ BOOST_AUTO_TEST_CASE(rpc_wallet_encrypted_wallet_sapzkeys)
532
557
arr = retValue.get_array ();
533
558
BOOST_CHECK ((int ) arr.size () == n+1 );
534
559
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 ());
537
561
}
538
562
539
563
BOOST_AUTO_TEST_CASE (rpc_listshieldunspent_parameters)
@@ -542,6 +566,7 @@ BOOST_AUTO_TEST_CASE(rpc_listshieldunspent_parameters)
542
566
LOCK (pwalletMain->cs_wallet );
543
567
pwalletMain->SetupSPKM (false );
544
568
}
569
+ vpwallets.insert (vpwallets.begin (), pwalletMain.get ());
545
570
546
571
UniValue retValue;
547
572
@@ -583,6 +608,8 @@ BOOST_AUTO_TEST_CASE(rpc_listshieldunspent_parameters)
583
608
584
609
// duplicate address error
585
610
BOOST_CHECK_THROW (CallRPC (" listshieldunspent 1 999 false [\" " + myzaddr + " \" , \" " + myzaddr + " \" ]" ), std::runtime_error);
611
+
612
+ vpwallets.erase (vpwallets.begin ());
586
613
}
587
614
588
615
BOOST_AUTO_TEST_SUITE_END ()
0 commit comments