@@ -614,8 +614,10 @@ BOOST_AUTO_TEST_CASE(CachedWitnessesEmptyChain) {
614614 auto consensusParams = RegtestActivateSapling ();
615615
616616 CWallet& wallet = *pwalletMain;
617- LOCK (wallet.cs_wallet );
618- setupWallet (wallet);
617+ {
618+ LOCK (wallet.cs_wallet );
619+ setupWallet (wallet);
620+ }
619621
620622 auto sk = GetTestMasterSaplingSpendingKey ();
621623 CWalletTx wtx = GetValidSaplingReceive (Params ().GetConsensus (), wallet, sk, 10 , true );
@@ -653,18 +655,19 @@ BOOST_AUTO_TEST_CASE(CachedWitnessesEmptyChain) {
653655BOOST_AUTO_TEST_CASE (CachedWitnessesChainTip) {
654656 auto consensusParams = RegtestActivateSapling ();
655657
658+ libzcash::SaplingExtendedSpendingKey sk = GetTestMasterSaplingSpendingKey ();
656659 CWallet& wallet = *pwalletMain;
657- LOCK (wallet.cs_wallet );
658- setupWallet (wallet);
660+ {
661+ LOCK (wallet.cs_wallet );
662+ setupWallet (wallet);
663+ BOOST_CHECK (wallet.AddSaplingZKey (sk));
664+ BOOST_CHECK (wallet.HaveSaplingSpendingKey (sk.ToXFVK ()));
665+ }
659666
660667 uint256 anchors1;
661668 CBlock block1;
662669 SaplingMerkleTree saplingTree;
663670
664- libzcash::SaplingExtendedSpendingKey sk = GetTestMasterSaplingSpendingKey ();
665- BOOST_CHECK (wallet.AddSaplingZKey (sk));
666- BOOST_CHECK (wallet.HaveSaplingSpendingKey (sk.ToXFVK ()));
667-
668671 {
669672 // First block (case tested in _empty_chain)
670673 CBlockIndex index1 (block1);
@@ -731,15 +734,15 @@ BOOST_AUTO_TEST_CASE(CachedWitnessesChainTip) {
731734BOOST_AUTO_TEST_CASE (CachedWitnessesDecrementFirst) {
732735 auto consensusParams = RegtestActivateSapling ();
733736
737+ libzcash::SaplingExtendedSpendingKey sk = GetTestMasterSaplingSpendingKey ();
734738 CWallet& wallet = *pwalletMain;
735- LOCK (wallet.cs_wallet );
736- setupWallet (wallet);
739+ {
740+ LOCK (wallet.cs_wallet );
741+ setupWallet (wallet);
742+ BOOST_CHECK (wallet.AddSaplingZKey (sk));
743+ }
737744
738745 SaplingMerkleTree saplingTree;
739-
740- libzcash::SaplingExtendedSpendingKey sk = GetTestMasterSaplingSpendingKey ();
741- BOOST_CHECK (wallet.AddSaplingZKey (sk));
742-
743746 {
744747 // First block (case tested in _empty_chain)
745748 CBlock block1;
@@ -799,9 +802,13 @@ BOOST_AUTO_TEST_CASE(CachedWitnessesDecrementFirst) {
799802BOOST_AUTO_TEST_CASE (CachedWitnessesCleanIndex) {
800803 auto consensusParams = RegtestActivateSapling ();
801804
805+ libzcash::SaplingExtendedSpendingKey sk = GetTestMasterSaplingSpendingKey ();
802806 CWallet& wallet = *pwalletMain;
803- LOCK (wallet.cs_wallet );
804- setupWallet (wallet);
807+ {
808+ LOCK (wallet.cs_wallet );
809+ setupWallet (wallet);
810+ BOOST_CHECK (wallet.AddSaplingZKey (sk));
811+ }
805812
806813 std::vector<CBlock> blocks;
807814 std::vector<CBlockIndex> indices;
@@ -811,9 +818,6 @@ BOOST_AUTO_TEST_CASE(CachedWitnessesCleanIndex) {
811818 SaplingMerkleTree saplingRiTree = saplingTree;
812819 std::vector<Optional<SaplingWitness>> saplingWitnesses;
813820
814- libzcash::SaplingExtendedSpendingKey sk = GetTestMasterSaplingSpendingKey ();
815- BOOST_CHECK (wallet.AddSaplingZKey (sk));
816-
817821 // Generate a chain
818822 size_t numBlocks = WITNESS_CACHE_SIZE + 10 ;
819823 blocks.resize (numBlocks);
@@ -874,12 +878,13 @@ BOOST_AUTO_TEST_CASE(CachedWitnessesCleanIndex) {
874878BOOST_AUTO_TEST_CASE (ClearNoteWitnessCache) {
875879 auto consensusParams = RegtestActivateSapling ();
876880
877- CWallet& wallet = *pwalletMain;
878- LOCK (wallet.cs_wallet );
879- setupWallet (wallet);
880-
881881 libzcash::SaplingExtendedSpendingKey sk = GetTestMasterSaplingSpendingKey ();
882- BOOST_CHECK (wallet.AddSaplingZKey (sk));
882+ CWallet& wallet = *pwalletMain;
883+ {
884+ LOCK (wallet.cs_wallet );
885+ setupWallet (wallet);
886+ BOOST_CHECK (wallet.AddSaplingZKey (sk));
887+ }
883888
884889 CWalletTx wtx = GetValidSaplingReceive (Params ().GetConsensus (),
885890 wallet, sk, 10 , true );
@@ -922,7 +927,8 @@ BOOST_AUTO_TEST_CASE(UpdatedSaplingNoteData) {
922927 auto consensusParams = RegtestActivateSapling ();
923928
924929 CWallet& wallet = *pwalletMain;
925- LOCK (wallet.cs_wallet );
930+ // Need to lock cs_main for now due the lock ordering. future: revamp all of this function to only lock where is needed.
931+ LOCK2 (cs_main, wallet.cs_wallet );
926932 setupWallet (wallet);
927933
928934 auto m = GetTestMasterSaplingSpendingKey ();
0 commit comments