1 #include <gtest/gtest.h>
4 #include "zcash/Address.hpp"
6 TEST(keystore_tests, store_and_retrieve_spending_key) {
7 CBasicKeyStore keyStore;
8 libzcash::SpendingKey skOut;
10 std::set<libzcash::PaymentAddress> addrs;
11 keyStore.GetPaymentAddresses(addrs);
12 EXPECT_EQ(0, addrs.size());
14 auto sk = libzcash::SpendingKey::random();
15 auto addr = sk.address();
17 // Sanity-check: we can't get a key we haven't added
18 EXPECT_FALSE(keyStore.HaveSpendingKey(addr));
19 EXPECT_FALSE(keyStore.GetSpendingKey(addr, skOut));
21 keyStore.AddSpendingKey(sk);
22 EXPECT_TRUE(keyStore.HaveSpendingKey(addr));
23 EXPECT_TRUE(keyStore.GetSpendingKey(addr, skOut));
26 keyStore.GetPaymentAddresses(addrs);
27 EXPECT_EQ(1, addrs.size());
28 EXPECT_EQ(1, addrs.count(addr));
31 TEST(keystore_tests, store_and_retrieve_note_decryptor) {
32 CBasicKeyStore keyStore;
33 ZCNoteDecryption decOut;
35 auto sk = libzcash::SpendingKey::random();
36 auto addr = sk.address();
38 EXPECT_FALSE(keyStore.GetNoteDecryptor(addr, decOut));
40 keyStore.AddSpendingKey(sk);
41 EXPECT_TRUE(keyStore.GetNoteDecryptor(addr, decOut));
42 EXPECT_EQ(ZCNoteDecryption(sk.viewing_key()), decOut);