Merge remote-tracking branch 'zcash/master' into rebase2
# Conflicts: # .travis.yml # Makefile.am # README.md # configure.ac # depends/Makefile # depends/builders/darwin.mk # depends/funcs.mk # depends/hosts/darwin.mk # depends/packages/googlemock.mk # depends/packages/googletest.mk # depends/packages/libsnark.mk # depends/packages/libsodium.mk # depends/packages/packages.mk # depends/packages/rust.mk # src/Makefile.am # src/Makefile.gtest.include # src/chainparams.cpp # src/chainparams.h # src/checkpoints.h # src/clientversion.h # src/coins.cpp # src/consensus/consensus.h # src/gtest/test_mempool.cpp # src/httprpc.cpp # src/init.cpp # src/komodo-tx.cpp # src/main.cpp # src/miner.cpp # src/policy/fees.cpp # src/policy/fees.h # src/rpcmining.cpp # src/rpcrawtransaction.cpp # src/rpcserver.cpp # src/test/policyestimator_tests.cpp # src/test/rpc_wallet_tests.cpp # src/test/transaction_tests.cpp # src/txdb.cpp # src/txmempool.cpp # src/wallet/asyncrpcoperation_sendmany.cpp # src/wallet/rpcwallet.cpp # src/wallet/wallet.cpp # src/wallet/wallet.h # src/zcash/CreateJoinSplit.cpp # zcutil/build.sh
This commit is contained in:
@@ -281,7 +281,7 @@ TEST(wallet_tests, find_unspent_notes) {
|
||||
wallet.GetFilteredNotes(entries, "", 2, false);
|
||||
EXPECT_EQ(1, entries.size());
|
||||
entries.clear();
|
||||
// If we also ignore spent notes at thie depth, we won't find any notes.
|
||||
// If we also ignore spent notes at this depth, we won't find any notes.
|
||||
wallet.GetFilteredNotes(entries, "", 2, true);
|
||||
EXPECT_EQ(0, entries.size());
|
||||
entries.clear();
|
||||
@@ -328,7 +328,7 @@ TEST(wallet_tests, GetNoteNullifier) {
|
||||
|
||||
auto sk = libzcash::SpendingKey::random();
|
||||
auto address = sk.address();
|
||||
auto dec = ZCNoteDecryption(sk.viewing_key());
|
||||
auto dec = ZCNoteDecryption(sk.receiving_key());
|
||||
|
||||
auto wtx = GetValidReceive(sk, 10, true);
|
||||
auto note = GetNote(sk, wtx, 0, 1);
|
||||
|
||||
@@ -66,6 +66,53 @@ TEST(wallet_zkeys_tests, store_and_load_zkeys) {
|
||||
ASSERT_EQ(m.nCreateTime, now);
|
||||
}
|
||||
|
||||
/**
|
||||
* This test covers methods on CWallet
|
||||
* AddViewingKey()
|
||||
* RemoveViewingKey()
|
||||
* LoadViewingKey()
|
||||
*/
|
||||
TEST(wallet_zkeys_tests, StoreAndLoadViewingKeys) {
|
||||
SelectParams(CBaseChainParams::MAIN);
|
||||
|
||||
CWallet wallet;
|
||||
|
||||
// wallet should be empty
|
||||
std::set<libzcash::PaymentAddress> addrs;
|
||||
wallet.GetPaymentAddresses(addrs);
|
||||
ASSERT_EQ(0, addrs.size());
|
||||
|
||||
// manually add new viewing key to wallet
|
||||
auto sk = libzcash::SpendingKey::random();
|
||||
auto vk = sk.viewing_key();
|
||||
ASSERT_TRUE(wallet.AddViewingKey(vk));
|
||||
|
||||
// verify wallet did add it
|
||||
auto addr = sk.address();
|
||||
ASSERT_TRUE(wallet.HaveViewingKey(addr));
|
||||
// and that we don't have the corresponding spending key
|
||||
ASSERT_FALSE(wallet.HaveSpendingKey(addr));
|
||||
|
||||
// verify viewing key stored correctly
|
||||
libzcash::ViewingKey vkOut;
|
||||
wallet.GetViewingKey(addr, vkOut);
|
||||
ASSERT_EQ(vk, vkOut);
|
||||
|
||||
// Load a second viewing key into the wallet
|
||||
auto sk2 = libzcash::SpendingKey::random();
|
||||
ASSERT_TRUE(wallet.LoadViewingKey(sk2.viewing_key()));
|
||||
|
||||
// verify wallet did add it
|
||||
auto addr2 = sk2.address();
|
||||
ASSERT_TRUE(wallet.HaveViewingKey(addr2));
|
||||
ASSERT_FALSE(wallet.HaveSpendingKey(addr2));
|
||||
|
||||
// Remove the first viewing key
|
||||
ASSERT_TRUE(wallet.RemoveViewingKey(vk));
|
||||
ASSERT_FALSE(wallet.HaveViewingKey(addr));
|
||||
ASSERT_TRUE(wallet.HaveViewingKey(addr2));
|
||||
}
|
||||
|
||||
/**
|
||||
* This test covers methods on CWalletDB
|
||||
* WriteZKey()
|
||||
@@ -138,6 +185,50 @@ TEST(wallet_zkeys_tests, write_zkey_direct_to_db) {
|
||||
ASSERT_EQ(m.nCreateTime, now);
|
||||
}
|
||||
|
||||
/**
|
||||
* This test covers methods on CWalletDB
|
||||
* WriteViewingKey()
|
||||
*/
|
||||
TEST(wallet_zkeys_tests, WriteViewingKeyDirectToDB) {
|
||||
SelectParams(CBaseChainParams::TESTNET);
|
||||
|
||||
// Get temporary and unique path for file.
|
||||
// Note: / operator to append paths
|
||||
boost::filesystem::path pathTemp = boost::filesystem::temp_directory_path() / boost::filesystem::unique_path();
|
||||
boost::filesystem::create_directories(pathTemp);
|
||||
mapArgs["-datadir"] = pathTemp.string();
|
||||
|
||||
bool fFirstRun;
|
||||
CWallet wallet("wallet-vkey.dat");
|
||||
ASSERT_EQ(DB_LOAD_OK, wallet.LoadWallet(fFirstRun));
|
||||
|
||||
// No default CPubKey set
|
||||
ASSERT_TRUE(fFirstRun);
|
||||
|
||||
// create random viewing key and add it to database directly, bypassing wallet
|
||||
auto sk = libzcash::SpendingKey::random();
|
||||
auto vk = sk.viewing_key();
|
||||
auto addr = sk.address();
|
||||
int64_t now = GetTime();
|
||||
CKeyMetadata meta(now);
|
||||
CWalletDB db("wallet-vkey.dat");
|
||||
db.WriteViewingKey(vk);
|
||||
|
||||
// wallet should not be aware of viewing key
|
||||
ASSERT_FALSE(wallet.HaveViewingKey(addr));
|
||||
|
||||
// load the wallet again
|
||||
ASSERT_EQ(DB_LOAD_OK, wallet.LoadWallet(fFirstRun));
|
||||
|
||||
// wallet can now see the viewing key
|
||||
ASSERT_TRUE(wallet.HaveViewingKey(addr));
|
||||
|
||||
// check key is the same
|
||||
libzcash::ViewingKey vkOut;
|
||||
wallet.GetViewingKey(addr, vkOut);
|
||||
ASSERT_EQ(vk, vkOut);
|
||||
}
|
||||
|
||||
|
||||
|
||||
/**
|
||||
@@ -214,5 +305,7 @@ TEST(wallet_zkeys_tests, write_cryptedzkey_direct_to_db) {
|
||||
|
||||
wallet2.GetSpendingKey(paymentAddress2.Get(), keyOut);
|
||||
ASSERT_EQ(paymentAddress2.Get(), keyOut.address());
|
||||
|
||||
ECC_Stop();
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user