Adding in rpc wallet sap for test_bitcoin

This commit is contained in:
mdr0id
2018-09-27 13:06:33 -07:00
committed by Jack Grigg
parent 48a93fd2e0
commit fe92bc700a

View File

@@ -1412,6 +1412,67 @@ BOOST_AUTO_TEST_CASE(rpc_wallet_encrypted_wallet_zkeys)
// but there are tests for this in gtest.
}
BOOST_AUTO_TEST_CASE(rpc_wallet_encrypted_wallet_sapzkeys)
{
LOCK2(cs_main, pwalletMain->cs_wallet);
UniValue retValue;
int n = 100;
if(!pwalletMain->HaveHDSeed())
{
pwalletMain->GenerateNewSeed();
}
// wallet should currently be empty
std::set<libzcash::SaplingPaymentAddress> addrs;
pwalletMain->GetSaplingPaymentAddresses(addrs);
BOOST_CHECK(addrs.size()==0);
// create keys
for (int i = 0; i < n; i++) {
CallRPC("z_getnewaddress sapling");
}
// Verify we can list the keys imported
BOOST_CHECK_NO_THROW(retValue = CallRPC("z_listaddresses"));
UniValue arr = retValue.get_array();
BOOST_CHECK(arr.size() == n);
// Verify that the wallet encryption RPC is disabled
BOOST_CHECK_THROW(CallRPC("encryptwallet passphrase"), runtime_error);
// Encrypt the wallet (we can't call RPC encryptwallet as that shuts down node)
SecureString strWalletPass;
strWalletPass.reserve(100);
strWalletPass = "hello";
boost::filesystem::current_path(GetArg("-datadir","/tmp/thisshouldnothappen"));
BOOST_CHECK(pwalletMain->EncryptWallet(strWalletPass));
// Verify we can still list the keys imported
BOOST_CHECK_NO_THROW(retValue = CallRPC("z_listaddresses"));
arr = retValue.get_array();
BOOST_CHECK(arr.size() == n);
// Try to add a new key, but we can't as the wallet is locked
BOOST_CHECK_THROW(CallRPC("z_getnewaddress sapling"), runtime_error);
// We can't call RPC walletpassphrase as that invokes RPCRunLater which breaks tests.
// So we manually unlock.
BOOST_CHECK(pwalletMain->Unlock(strWalletPass));
// Now add a key
BOOST_CHECK_NO_THROW(CallRPC("z_getnewaddress sapling"));
// Verify the key has been added
BOOST_CHECK_NO_THROW(retValue = CallRPC("z_listaddresses"));
arr = retValue.get_array();
BOOST_CHECK(arr.size() == n+1);
// We can't simulate over RPC the wallet closing and being reloaded
// but there are tests for this in gtest.
}
BOOST_AUTO_TEST_CASE(rpc_z_listunspent_parameters)
{