Skip to content

Commit

Permalink
test: bugfix, use a real wallet db to test encryption and not the moc…
Browse files Browse the repository at this point in the history
…ked m_wallet.
  • Loading branch information
furszy committed Nov 26, 2021
1 parent 28d17a1 commit 3d8f54f
Showing 1 changed file with 13 additions and 7 deletions.
20 changes: 13 additions & 7 deletions src/test/librust/sapling_rpc_wallet_tests.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@
#include "key_io.h"
#include "consensus/merkle.h"
#include "wallet/wallet.h"
#include "wallet/walletutil.h"

#include "sapling/key_io_sapling.h"
#include "sapling/address.h"
Expand Down Expand Up @@ -502,16 +503,21 @@ BOOST_AUTO_TEST_CASE(rpc_wallet_encrypted_wallet_sapzkeys)
UniValue retValue;
int n = 100;

fs::path path = fs::absolute("testWallet1", GetWalletDir());
path.make_preferred();
std::unique_ptr<CWallet> test_wallet = std::make_unique<CWallet>("testWallet1", WalletDatabase::Create(path));
bool fFirstRun;
BOOST_CHECK_EQUAL(test_wallet->LoadWallet(fFirstRun), DB_LOAD_OK);
{
LOCK(m_wallet.cs_wallet);
m_wallet.SetMinVersion(FEATURE_SAPLING);
m_wallet.SetupSPKM(false);
LOCK(test_wallet->cs_wallet);
test_wallet->SetMinVersion(FEATURE_SAPLING);
test_wallet->SetupSPKM(false);
}
vpwallets.insert(vpwallets.begin(), &m_wallet);
vpwallets.insert(vpwallets.begin(), test_wallet.get());

// wallet should currently be empty
std::set<libzcash::SaplingPaymentAddress> addrs;
m_wallet.GetSaplingPaymentAddresses(addrs);
test_wallet->GetSaplingPaymentAddresses(addrs);
BOOST_CHECK(addrs.empty());

// create keys
Expand All @@ -534,7 +540,7 @@ BOOST_AUTO_TEST_CASE(rpc_wallet_encrypted_wallet_sapzkeys)
strWalletPass = "hello";

PushCurrentDirectory push_dir(gArgs.GetArg("-datadir","/tmp/thisshouldnothappen"));
BOOST_CHECK(m_wallet.EncryptWallet(strWalletPass));
BOOST_CHECK(test_wallet->EncryptWallet(strWalletPass));

// Verify we can still list the keys imported
BOOST_CHECK_NO_THROW(retValue = CallRPC("listshieldaddresses"));
Expand All @@ -546,7 +552,7 @@ BOOST_AUTO_TEST_CASE(rpc_wallet_encrypted_wallet_sapzkeys)

// We can't call RPC walletpassphrase as that invokes RPCRunLater which breaks tests.
// So we manually unlock.
BOOST_CHECK(m_wallet.Unlock(strWalletPass));
BOOST_CHECK(test_wallet->Unlock(strWalletPass));

// Now add a key
BOOST_CHECK_NO_THROW(CallRPC("getnewshieldaddress"));
Expand Down

0 comments on commit 3d8f54f

Please sign in to comment.