Skip to content

Commit 4734a84

Browse files
committed
[Cleanup][Tests] Fix chainparams-change in librust tests
1 parent ff4cee0 commit 4734a84

File tree

7 files changed

+72
-121
lines changed

7 files changed

+72
-121
lines changed

src/test/librust/sapling_test_fixture.cpp

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -13,3 +13,8 @@ SaplingTestingSetup::SaplingTestingSetup(const std::string& chainName) : Testing
1313
SaplingTestingSetup::~SaplingTestingSetup()
1414
{
1515
}
16+
17+
SaplingRegTestingSetup::SaplingRegTestingSetup() : SaplingTestingSetup(CBaseChainParams::REGTEST)
18+
{
19+
UpdateNetworkUpgradeParameters(Consensus::UPGRADE_V5_0, Consensus::NetworkUpgrade::ALWAYS_ACTIVE);
20+
}

src/test/librust/sapling_test_fixture.h

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -16,5 +16,13 @@ struct SaplingTestingSetup : public TestingSetup
1616
~SaplingTestingSetup();
1717
};
1818

19+
/**
20+
* Regtest setup with sapling always active
21+
*/
22+
struct SaplingRegTestingSetup : public SaplingTestingSetup
23+
{
24+
SaplingRegTestingSetup();
25+
};
26+
1927

2028
#endif //PIVX_SAPLING_TEST_FIXTURE_H

src/test/librust/sapling_wallet_tests.cpp

Lines changed: 45 additions & 64 deletions
Original file line numberDiff line numberDiff line change
@@ -70,10 +70,10 @@ uint256 GetWitnessesAndAnchors(CWallet& wallet,
7070
return saplingAnchor;
7171
}
7272

73-
BOOST_FIXTURE_TEST_SUITE(sapling_wallet_tests, WalletTestingSetup)
73+
BOOST_FIXTURE_TEST_SUITE(sapling_wallet_tests, WalletRegTestingSetup)
7474

7575
BOOST_AUTO_TEST_CASE(SetSaplingNoteAddrsInCWalletTx) {
76-
auto consensusParams = RegtestActivateSapling();
76+
auto consensusParams = Params().GetConsensus();
7777

7878
CWallet& wallet = *pwalletMain;
7979
LOCK(wallet.cs_wallet);
@@ -124,9 +124,6 @@ BOOST_AUTO_TEST_CASE(SetSaplingNoteAddrsInCWalletTx) {
124124
BOOST_CHECK(nullifier == wtx.mapSaplingNoteData[op].nullifier);
125125
BOOST_CHECK(nd.witnessHeight == wtx.mapSaplingNoteData[op].witnessHeight);
126126
BOOST_CHECK(witness == wtx.mapSaplingNoteData[op].witnesses.front());
127-
128-
// Revert to default
129-
RegtestDeactivateSapling();
130127
}
131128

132129
// Cannot add note data for an index which does not exist in tx.vShieldedOutput
@@ -142,8 +139,9 @@ BOOST_AUTO_TEST_CASE(SetInvalidSaplingNoteDataInCWalletTx) {
142139
BOOST_CHECK_THROW(wtx.SetSaplingNoteData(noteData), std::logic_error);
143140
}
144141

145-
BOOST_AUTO_TEST_CASE(FindMySaplingNotes) {
146-
auto consensusParams = RegtestActivateSapling();
142+
BOOST_AUTO_TEST_CASE(FindMySaplingNotes)
143+
{
144+
auto consensusParams = Params().GetConsensus();
147145

148146
CWallet& wallet = *pwalletMain;
149147
LOCK(wallet.cs_wallet);
@@ -175,14 +173,12 @@ BOOST_AUTO_TEST_CASE(FindMySaplingNotes) {
175173
BOOST_CHECK(wallet.HaveSaplingSpendingKey(extfvk));
176174
noteMap = wallet.GetSaplingScriptPubKeyMan()->FindMySaplingNotes(*wtx.tx).first;
177175
BOOST_CHECK_EQUAL(2, noteMap.size());
178-
179-
// Revert to default
180-
RegtestDeactivateSapling();
181176
}
182177

183178
// Generate note A and spend to create note B, from which we spend to create two conflicting transactions
184-
BOOST_AUTO_TEST_CASE(GetConflictedSaplingNotes) {
185-
auto consensusParams = RegtestActivateSapling();
179+
BOOST_AUTO_TEST_CASE(GetConflictedSaplingNotes)
180+
{
181+
auto consensusParams = Params().GetConsensus();
186182

187183
CWallet& wallet = *pwalletMain;
188184
LOCK2(cs_main, wallet.cs_wallet);
@@ -296,15 +292,13 @@ BOOST_AUTO_TEST_CASE(GetConflictedSaplingNotes) {
296292
BOOST_CHECK(std::set<uint256>({hash2, hash3}) == c3);
297293

298294
// Tear down
299-
chainActive.SetTip(NULL);
295+
chainActive.SetTip(nullptr);
300296
mapBlockIndex.erase(blockHash);
301-
302-
// Revert to default
303-
RegtestDeactivateSapling();
304297
}
305298

306-
BOOST_AUTO_TEST_CASE(SaplingNullifierIsSpent) {
307-
auto consensusParams = RegtestActivateSapling();
299+
BOOST_AUTO_TEST_CASE(SaplingNullifierIsSpent)
300+
{
301+
auto consensusParams = Params().GetConsensus();
308302

309303
CWallet& wallet = *pwalletMain;
310304
LOCK2(cs_main, wallet.cs_wallet);
@@ -357,15 +351,13 @@ BOOST_AUTO_TEST_CASE(SaplingNullifierIsSpent) {
357351
BOOST_CHECK(wallet.GetSaplingScriptPubKeyMan()->IsSaplingSpent(nullifier));
358352

359353
// Tear down
360-
chainActive.SetTip(NULL);
354+
chainActive.SetTip(nullptr);
361355
mapBlockIndex.erase(blockHash);
362-
363-
// Revert to default
364-
RegtestDeactivateSapling();
365356
}
366357

367-
BOOST_AUTO_TEST_CASE(NavigateFromSaplingNullifierToNote) {
368-
auto consensusParams = RegtestActivateSapling();
358+
BOOST_AUTO_TEST_CASE(NavigateFromSaplingNullifierToNote)
359+
{
360+
auto consensusParams = Params().GetConsensus();
369361

370362
CWallet& wallet = *pwalletMain;
371363
LOCK2(cs_main, wallet.cs_wallet);
@@ -454,16 +446,14 @@ BOOST_AUTO_TEST_CASE(NavigateFromSaplingNullifierToNote) {
454446
}
455447

456448
// Tear down
457-
chainActive.SetTip(NULL);
449+
chainActive.SetTip(nullptr);
458450
mapBlockIndex.erase(blockHash);
459-
460-
// Revert to default
461-
RegtestDeactivateSapling();
462451
}
463452

464453
// Create note A, spend A to create note B, spend and verify note B is from me.
465-
BOOST_AUTO_TEST_CASE(SpentSaplingNoteIsFromMe) {
466-
auto consensusParams = RegtestActivateSapling();
454+
BOOST_AUTO_TEST_CASE(SpentSaplingNoteIsFromMe)
455+
{
456+
auto consensusParams = Params().GetConsensus();
467457

468458
CWallet& wallet = *pwalletMain;
469459
LOCK2(cs_main, wallet.cs_wallet);
@@ -601,16 +591,14 @@ BOOST_AUTO_TEST_CASE(SpentSaplingNoteIsFromMe) {
601591
BOOST_CHECK(wallet.GetSaplingScriptPubKeyMan()->mapSaplingNullifiersToNotes.count(nullifier2));
602592

603593
// Tear down
604-
chainActive.SetTip(NULL);
594+
chainActive.SetTip(nullptr);
605595
mapBlockIndex.erase(blockHash);
606596
mapBlockIndex.erase(blockHash2);
607-
608-
// Revert to default
609-
RegtestDeactivateSapling();
610597
}
611598

612-
BOOST_AUTO_TEST_CASE(CachedWitnessesEmptyChain) {
613-
auto consensusParams = RegtestActivateSapling();
599+
BOOST_AUTO_TEST_CASE(CachedWitnessesEmptyChain)
600+
{
601+
auto consensusParams = Params().GetConsensus();
614602

615603
CWallet& wallet = *pwalletMain;
616604
{
@@ -646,13 +634,11 @@ BOOST_AUTO_TEST_CASE(CachedWitnessesEmptyChain) {
646634

647635
// Until zcash#1302 is implemented, this should triggger an assertion
648636
BOOST_CHECK_THROW(wallet.DecrementNoteWitnesses(&index), std::runtime_error);
649-
650-
// Revert to default
651-
RegtestDeactivateSapling();
652637
}
653638

654-
BOOST_AUTO_TEST_CASE(CachedWitnessesChainTip) {
655-
auto consensusParams = RegtestActivateSapling();
639+
BOOST_AUTO_TEST_CASE(CachedWitnessesChainTip)
640+
{
641+
auto consensusParams = Params().GetConsensus();
656642

657643
libzcash::SaplingExtendedSpendingKey sk = GetTestMasterSaplingSpendingKey();
658644
CWallet& wallet = *pwalletMain;
@@ -730,9 +716,9 @@ BOOST_AUTO_TEST_CASE(CachedWitnessesChainTip) {
730716
}
731717
}
732718

733-
BOOST_AUTO_TEST_CASE(CachedWitnessesDecrementFirst) {
734-
auto consensusParams = RegtestActivateSapling();
735-
719+
BOOST_AUTO_TEST_CASE(CachedWitnessesDecrementFirst)
720+
{
721+
auto consensusParams = Params().GetConsensus();
736722
libzcash::SaplingExtendedSpendingKey sk = GetTestMasterSaplingSpendingKey();
737723
CWallet& wallet = *pwalletMain;
738724
{
@@ -798,8 +784,9 @@ BOOST_AUTO_TEST_CASE(CachedWitnessesDecrementFirst) {
798784
}
799785
}
800786

801-
BOOST_AUTO_TEST_CASE(CachedWitnessesCleanIndex) {
802-
auto consensusParams = RegtestActivateSapling();
787+
BOOST_AUTO_TEST_CASE(CachedWitnessesCleanIndex)
788+
{
789+
auto consensusParams = Params().GetConsensus();
803790

804791
libzcash::SaplingExtendedSpendingKey sk = GetTestMasterSaplingSpendingKey();
805792
CWallet& wallet = *pwalletMain;
@@ -874,8 +861,9 @@ BOOST_AUTO_TEST_CASE(CachedWitnessesCleanIndex) {
874861
}
875862
}
876863

877-
BOOST_AUTO_TEST_CASE(ClearNoteWitnessCache) {
878-
auto consensusParams = RegtestActivateSapling();
864+
BOOST_AUTO_TEST_CASE(ClearNoteWitnessCache)
865+
{
866+
auto consensusParams = Params().GetConsensus();
879867

880868
libzcash::SaplingExtendedSpendingKey sk = GetTestMasterSaplingSpendingKey();
881869
CWallet& wallet = *pwalletMain;
@@ -922,8 +910,9 @@ BOOST_AUTO_TEST_CASE(ClearNoteWitnessCache) {
922910
BOOST_CHECK_EQUAL(0, wallet.GetSaplingScriptPubKeyMan()->nWitnessCacheSize);
923911
}
924912

925-
BOOST_AUTO_TEST_CASE(UpdatedSaplingNoteData) {
926-
auto consensusParams = RegtestActivateSapling();
913+
BOOST_AUTO_TEST_CASE(UpdatedSaplingNoteData)
914+
{
915+
auto consensusParams = Params().GetConsensus();
927916

928917
CWallet& wallet = *pwalletMain;
929918
// Need to lock cs_main for now due the lock ordering. future: revamp all of this function to only lock where is needed.
@@ -1028,15 +1017,13 @@ BOOST_AUTO_TEST_CASE(UpdatedSaplingNoteData) {
10281017
BOOST_CHECK(wtx.mapSaplingNoteData[sop1].witnesses.front() == testNote.tree.witness());
10291018

10301019
// Tear down
1031-
chainActive.SetTip(NULL);
1020+
chainActive.SetTip(nullptr);
10321021
mapBlockIndex.erase(blockHash);
1033-
1034-
// Revert to default
1035-
RegtestDeactivateSapling();
10361022
}
10371023

1038-
BOOST_AUTO_TEST_CASE(MarkAffectedSaplingTransactionsDirty) {
1039-
auto consensusParams = RegtestActivateSapling();
1024+
BOOST_AUTO_TEST_CASE(MarkAffectedSaplingTransactionsDirty)
1025+
{
1026+
auto consensusParams = Params().GetConsensus();
10401027

10411028
CWallet& wallet = *pwalletMain;
10421029
LOCK2(cs_main, wallet.cs_wallet);
@@ -1140,16 +1127,13 @@ BOOST_AUTO_TEST_CASE(MarkAffectedSaplingTransactionsDirty) {
11401127
BOOST_CHECK(!wallet.mapWallet.at(hash).IsAmountCached(CWalletTx::AmountType::DEBIT, ISMINE_SPENDABLE));
11411128

11421129
// Tear down
1143-
chainActive.SetTip(NULL);
1130+
chainActive.SetTip(nullptr);
11441131
mapBlockIndex.erase(blockHash);
1145-
1146-
// Revert to default
1147-
RegtestDeactivateSapling();
11481132
}
11491133

11501134
BOOST_AUTO_TEST_CASE(GetNotes)
11511135
{
1152-
auto consensusParams = RegtestActivateSapling();
1136+
auto consensusParams = Params().GetConsensus();
11531137

11541138
CWallet& wallet = *pwalletMain;
11551139
libzcash::SaplingPaymentAddress pk;
@@ -1238,9 +1222,6 @@ BOOST_AUTO_TEST_CASE(GetNotes)
12381222
LOCK(cs_main);
12391223
chainActive.SetTip(nullptr);
12401224
mapBlockIndex.erase(blockHash);
1241-
1242-
// Revert to default
1243-
RegtestDeactivateSapling();
12441225
}
12451226

12461227
// TODO: Back port WriteWitnessCache & SetBestChainIgnoresTxsWithoutShieldedData test cases.

0 commit comments

Comments
 (0)