|
|
@ -43,7 +43,64 @@ TEST(keystore_tests, store_and_retrieve_note_decryptor) { |
|
|
|
|
|
|
|
keyStore.AddSpendingKey(sk); |
|
|
|
EXPECT_TRUE(keyStore.GetNoteDecryptor(addr, decOut)); |
|
|
|
EXPECT_EQ(ZCNoteDecryption(sk.viewing_key()), decOut); |
|
|
|
EXPECT_EQ(ZCNoteDecryption(sk.receiving_key()), decOut); |
|
|
|
} |
|
|
|
|
|
|
|
TEST(keystore_tests, StoreAndRetrieveViewingKey) { |
|
|
|
CBasicKeyStore keyStore; |
|
|
|
libzcash::ViewingKey vkOut; |
|
|
|
libzcash::SpendingKey skOut; |
|
|
|
ZCNoteDecryption decOut; |
|
|
|
|
|
|
|
auto sk = libzcash::SpendingKey::random(); |
|
|
|
auto vk = sk.viewing_key(); |
|
|
|
auto addr = sk.address(); |
|
|
|
|
|
|
|
// Sanity-check: we can't get a viewing key we haven't added
|
|
|
|
EXPECT_FALSE(keyStore.HaveViewingKey(addr)); |
|
|
|
EXPECT_FALSE(keyStore.GetViewingKey(addr, vkOut)); |
|
|
|
|
|
|
|
// and we shouldn't have a spending key or decryptor either
|
|
|
|
EXPECT_FALSE(keyStore.HaveSpendingKey(addr)); |
|
|
|
EXPECT_FALSE(keyStore.GetSpendingKey(addr, skOut)); |
|
|
|
EXPECT_FALSE(keyStore.GetNoteDecryptor(addr, decOut)); |
|
|
|
|
|
|
|
// and we can't find it in our list of addresses
|
|
|
|
std::set<libzcash::PaymentAddress> addresses; |
|
|
|
keyStore.GetPaymentAddresses(addresses); |
|
|
|
EXPECT_FALSE(addresses.count(addr)); |
|
|
|
|
|
|
|
keyStore.AddViewingKey(vk); |
|
|
|
EXPECT_TRUE(keyStore.HaveViewingKey(addr)); |
|
|
|
EXPECT_TRUE(keyStore.GetViewingKey(addr, vkOut)); |
|
|
|
EXPECT_EQ(vk, vkOut); |
|
|
|
|
|
|
|
// We should still not have the spending key...
|
|
|
|
EXPECT_FALSE(keyStore.HaveSpendingKey(addr)); |
|
|
|
EXPECT_FALSE(keyStore.GetSpendingKey(addr, skOut)); |
|
|
|
|
|
|
|
// ... but we should have a decryptor
|
|
|
|
EXPECT_TRUE(keyStore.GetNoteDecryptor(addr, decOut)); |
|
|
|
EXPECT_EQ(ZCNoteDecryption(sk.receiving_key()), decOut); |
|
|
|
|
|
|
|
// ... and we should find it in our list of addresses
|
|
|
|
addresses.clear(); |
|
|
|
keyStore.GetPaymentAddresses(addresses); |
|
|
|
EXPECT_TRUE(addresses.count(addr)); |
|
|
|
|
|
|
|
keyStore.RemoveViewingKey(vk); |
|
|
|
EXPECT_FALSE(keyStore.HaveViewingKey(addr)); |
|
|
|
EXPECT_FALSE(keyStore.GetViewingKey(addr, vkOut)); |
|
|
|
EXPECT_FALSE(keyStore.HaveSpendingKey(addr)); |
|
|
|
EXPECT_FALSE(keyStore.GetSpendingKey(addr, skOut)); |
|
|
|
addresses.clear(); |
|
|
|
keyStore.GetPaymentAddresses(addresses); |
|
|
|
EXPECT_FALSE(addresses.count(addr)); |
|
|
|
|
|
|
|
// We still have a decryptor because those are cached in memory
|
|
|
|
// (and also we only remove viewing keys when adding a spending key)
|
|
|
|
EXPECT_TRUE(keyStore.GetNoteDecryptor(addr, decOut)); |
|
|
|
EXPECT_EQ(ZCNoteDecryption(sk.receiving_key()), decOut); |
|
|
|
} |
|
|
|
|
|
|
|
#ifdef ENABLE_WALLET |
|
|
@ -72,13 +129,13 @@ TEST(keystore_tests, store_and_retrieve_spending_key_in_encrypted_store) { |
|
|
|
ASSERT_TRUE(keyStore.GetSpendingKey(addr, keyOut)); |
|
|
|
ASSERT_EQ(sk, keyOut); |
|
|
|
EXPECT_TRUE(keyStore.GetNoteDecryptor(addr, decOut)); |
|
|
|
EXPECT_EQ(ZCNoteDecryption(sk.viewing_key()), decOut); |
|
|
|
EXPECT_EQ(ZCNoteDecryption(sk.receiving_key()), decOut); |
|
|
|
|
|
|
|
ASSERT_TRUE(keyStore.EncryptKeys(vMasterKey)); |
|
|
|
ASSERT_TRUE(keyStore.HaveSpendingKey(addr)); |
|
|
|
ASSERT_FALSE(keyStore.GetSpendingKey(addr, keyOut)); |
|
|
|
EXPECT_TRUE(keyStore.GetNoteDecryptor(addr, decOut)); |
|
|
|
EXPECT_EQ(ZCNoteDecryption(sk.viewing_key()), decOut); |
|
|
|
EXPECT_EQ(ZCNoteDecryption(sk.receiving_key()), decOut); |
|
|
|
|
|
|
|
// Unlocking with a random key should fail
|
|
|
|
uint256 r2 {GetRandHash()}; |
|
|
@ -109,19 +166,19 @@ TEST(keystore_tests, store_and_retrieve_spending_key_in_encrypted_store) { |
|
|
|
ASSERT_TRUE(keyStore.GetSpendingKey(addr2, keyOut)); |
|
|
|
ASSERT_EQ(sk2, keyOut); |
|
|
|
EXPECT_TRUE(keyStore.GetNoteDecryptor(addr2, decOut)); |
|
|
|
EXPECT_EQ(ZCNoteDecryption(sk2.viewing_key()), decOut); |
|
|
|
EXPECT_EQ(ZCNoteDecryption(sk2.receiving_key()), decOut); |
|
|
|
|
|
|
|
ASSERT_TRUE(keyStore.Lock()); |
|
|
|
ASSERT_TRUE(keyStore.HaveSpendingKey(addr2)); |
|
|
|
ASSERT_FALSE(keyStore.GetSpendingKey(addr2, keyOut)); |
|
|
|
EXPECT_TRUE(keyStore.GetNoteDecryptor(addr2, decOut)); |
|
|
|
EXPECT_EQ(ZCNoteDecryption(sk2.viewing_key()), decOut); |
|
|
|
EXPECT_EQ(ZCNoteDecryption(sk2.receiving_key()), decOut); |
|
|
|
|
|
|
|
ASSERT_TRUE(keyStore.Unlock(vMasterKey)); |
|
|
|
ASSERT_TRUE(keyStore.GetSpendingKey(addr2, keyOut)); |
|
|
|
ASSERT_EQ(sk2, keyOut); |
|
|
|
EXPECT_TRUE(keyStore.GetNoteDecryptor(addr2, decOut)); |
|
|
|
EXPECT_EQ(ZCNoteDecryption(sk2.viewing_key()), decOut); |
|
|
|
EXPECT_EQ(ZCNoteDecryption(sk2.receiving_key()), decOut); |
|
|
|
|
|
|
|
keyStore.GetPaymentAddresses(addrs); |
|
|
|
ASSERT_EQ(2, addrs.size()); |
|
|
|