Add test method for generating master Sapling extended spending keys
This commit is contained in:
parent
9eadcb3eca
commit
1534671fb0
|
@ -3,15 +3,15 @@
|
|||
#include <zcash/Address.hpp>
|
||||
#include <zcash/zip32.h>
|
||||
|
||||
#include "utiltest.h"
|
||||
|
||||
#include <gtest/gtest.h>
|
||||
|
||||
TEST(Keys, EncodeAndDecodeSapling)
|
||||
{
|
||||
SelectParams(CBaseChainParams::MAIN);
|
||||
|
||||
std::vector<unsigned char, secure_allocator<unsigned char>> rawSeed(32);
|
||||
HDSeed seed(rawSeed);
|
||||
auto m = libzcash::SaplingExtendedSpendingKey::Master(seed);
|
||||
auto m = GetMasterSaplingSpendingKey();
|
||||
|
||||
for (uint32_t i = 0; i < 1000; i++) {
|
||||
auto sk = m.Derive(i);
|
||||
|
|
|
@ -7,6 +7,7 @@
|
|||
#ifdef ENABLE_WALLET
|
||||
#include "wallet/crypter.h"
|
||||
#endif
|
||||
#include "utiltest.h"
|
||||
#include "zcash/Address.hpp"
|
||||
#include "zcash/zip32.h"
|
||||
|
||||
|
@ -198,9 +199,7 @@ TEST(keystore_tests, StoreAndRetrieveSaplingSpendingKey) {
|
|||
libzcash::SaplingFullViewingKey fvkOut;
|
||||
libzcash::SaplingIncomingViewingKey ivkOut;
|
||||
|
||||
std::vector<unsigned char, secure_allocator<unsigned char>> rawSeed(32);
|
||||
HDSeed seed(rawSeed);
|
||||
auto sk = libzcash::SaplingExtendedSpendingKey::Master(seed);
|
||||
auto sk = GetMasterSaplingSpendingKey();
|
||||
auto fvk = sk.expsk.full_viewing_key();
|
||||
auto ivk = fvk.in_viewing_key();
|
||||
auto addr = sk.DefaultAddress();
|
||||
|
|
|
@ -10,6 +10,7 @@
|
|||
#include "uint256.h"
|
||||
#include "util.h"
|
||||
#include "utilstrencodings.h"
|
||||
#include "utiltest.h"
|
||||
#include "test/test_bitcoin.h"
|
||||
|
||||
#include "zcash/Address.hpp"
|
||||
|
@ -225,9 +226,7 @@ BOOST_AUTO_TEST_CASE(zs_address_test)
|
|||
{
|
||||
SelectParams(CBaseChainParams::REGTEST);
|
||||
|
||||
std::vector<unsigned char, secure_allocator<unsigned char>> rawSeed(32);
|
||||
HDSeed seed(rawSeed);
|
||||
auto m = libzcash::SaplingExtendedSpendingKey::Master(seed);
|
||||
auto m = GetMasterSaplingSpendingKey();
|
||||
|
||||
for (uint32_t i = 0; i < 1000; i++) {
|
||||
auto sk = m.Derive(i);
|
||||
|
|
|
@ -563,9 +563,7 @@ BOOST_AUTO_TEST_CASE(rpc_wallet_z_importexport)
|
|||
pwalletMain->GetSaplingPaymentAddresses(saplingAddrs);
|
||||
BOOST_CHECK(saplingAddrs.empty());
|
||||
|
||||
std::vector<unsigned char, secure_allocator<unsigned char>> rawSeed(32);
|
||||
HDSeed seed(rawSeed);
|
||||
auto m = libzcash::SaplingExtendedSpendingKey::Master(seed);
|
||||
auto m = GetMasterSaplingSpendingKey();
|
||||
|
||||
// verify import and export key
|
||||
for (int i = 0; i < n1; i++) {
|
||||
|
|
|
@ -171,6 +171,12 @@ void DeactivateSapling() {
|
|||
// SelectParams(CBaseChainParams::MAIN);
|
||||
}
|
||||
|
||||
libzcash::SaplingExtendedSpendingKey GetMasterSaplingSpendingKey() {
|
||||
std::vector<unsigned char, secure_allocator<unsigned char>> rawSeed(32);
|
||||
HDSeed seed(rawSeed);
|
||||
return libzcash::SaplingExtendedSpendingKey::Master(seed);
|
||||
}
|
||||
|
||||
TestSaplingNote GetTestSaplingNote(const libzcash::SaplingPaymentAddress& pa, CAmount value) {
|
||||
// Generate dummy Sapling note
|
||||
libzcash::SaplingNote note(pa, value);
|
||||
|
@ -188,7 +194,7 @@ CWalletTx GetValidSaplingTx(const Consensus::Params& consensusParams,
|
|||
auto pa = sk.DefaultAddress();
|
||||
|
||||
auto testNote = GetTestSaplingNote(pa, value);
|
||||
|
||||
|
||||
auto builder = TransactionBuilder(consensusParams, 1);
|
||||
builder.SetFee(0);
|
||||
builder.AddSaplingSpend(expsk, testNote.note, testNote.tree.root(), testNote.tree.witness());
|
||||
|
|
|
@ -32,6 +32,8 @@ const Consensus::Params& ActivateSapling();
|
|||
|
||||
void DeactivateSapling();
|
||||
|
||||
libzcash::SaplingExtendedSpendingKey GetMasterSaplingSpendingKey();
|
||||
|
||||
/**
|
||||
* Generate a dummy SaplingNote and a SaplingMerkleTree with that note's commitment.
|
||||
*/
|
||||
|
|
|
@ -360,9 +360,7 @@ TEST(WalletTests, SetSaplingNoteAddrsInCWalletTx) {
|
|||
|
||||
TestWallet wallet;
|
||||
|
||||
std::vector<unsigned char, secure_allocator<unsigned char>> rawSeed(32);
|
||||
HDSeed seed(rawSeed);
|
||||
auto sk = libzcash::SaplingExtendedSpendingKey::Master(seed);
|
||||
auto sk = GetMasterSaplingSpendingKey();
|
||||
auto expsk = sk.expsk;
|
||||
auto fvk = expsk.full_viewing_key();
|
||||
auto ivk = fvk.in_viewing_key();
|
||||
|
@ -477,9 +475,7 @@ TEST(WalletTests, FindMySaplingNotes) {
|
|||
TestWallet wallet;
|
||||
|
||||
// Generate dummy Sapling address
|
||||
std::vector<unsigned char, secure_allocator<unsigned char>> rawSeed(32);
|
||||
HDSeed seed(rawSeed);
|
||||
auto sk = libzcash::SaplingExtendedSpendingKey::Master(seed);
|
||||
auto sk = GetMasterSaplingSpendingKey();
|
||||
auto expsk = sk.expsk;
|
||||
auto fvk = expsk.full_viewing_key();
|
||||
auto pa = sk.DefaultAddress();
|
||||
|
@ -601,9 +597,7 @@ TEST(WalletTests, GetConflictedSaplingNotes) {
|
|||
TestWallet wallet;
|
||||
|
||||
// Generate Sapling address
|
||||
std::vector<unsigned char, secure_allocator<unsigned char>> rawSeed(32);
|
||||
HDSeed seed(rawSeed);
|
||||
auto sk = libzcash::SaplingExtendedSpendingKey::Master(seed);
|
||||
auto sk = GetMasterSaplingSpendingKey();
|
||||
auto expsk = sk.expsk;
|
||||
auto fvk = expsk.full_viewing_key();
|
||||
auto ivk = fvk.in_viewing_key();
|
||||
|
@ -760,9 +754,7 @@ TEST(WalletTests, SaplingNullifierIsSpent) {
|
|||
TestWallet wallet;
|
||||
|
||||
// Generate dummy Sapling address
|
||||
std::vector<unsigned char, secure_allocator<unsigned char>> rawSeed(32);
|
||||
HDSeed seed(rawSeed);
|
||||
auto sk = libzcash::SaplingExtendedSpendingKey::Master(seed);
|
||||
auto sk = GetMasterSaplingSpendingKey();
|
||||
auto expsk = sk.expsk;
|
||||
auto fvk = expsk.full_viewing_key();
|
||||
auto pa = sk.DefaultAddress();
|
||||
|
@ -845,9 +837,7 @@ TEST(WalletTests, NavigateFromSaplingNullifierToNote) {
|
|||
TestWallet wallet;
|
||||
|
||||
// Generate dummy Sapling address
|
||||
std::vector<unsigned char, secure_allocator<unsigned char>> rawSeed(32);
|
||||
HDSeed seed(rawSeed);
|
||||
auto sk = libzcash::SaplingExtendedSpendingKey::Master(seed);
|
||||
auto sk = GetMasterSaplingSpendingKey();
|
||||
auto expsk = sk.expsk;
|
||||
auto fvk = expsk.full_viewing_key();
|
||||
auto pa = sk.DefaultAddress();
|
||||
|
@ -968,9 +958,7 @@ TEST(WalletTests, SpentSaplingNoteIsFromMe) {
|
|||
TestWallet wallet;
|
||||
|
||||
// Generate Sapling address
|
||||
std::vector<unsigned char, secure_allocator<unsigned char>> rawSeed(32);
|
||||
HDSeed seed(rawSeed);
|
||||
auto sk = libzcash::SaplingExtendedSpendingKey::Master(seed);
|
||||
auto sk = GetMasterSaplingSpendingKey();
|
||||
auto expsk = sk.expsk;
|
||||
auto fvk = expsk.full_viewing_key();
|
||||
auto ivk = fvk.in_viewing_key();
|
||||
|
@ -1744,9 +1732,7 @@ TEST(WalletTests, UpdatedSaplingNoteData) {
|
|||
|
||||
TestWallet wallet;
|
||||
|
||||
std::vector<unsigned char, secure_allocator<unsigned char>> rawSeed(32);
|
||||
HDSeed seed(rawSeed);
|
||||
auto m = libzcash::SaplingExtendedSpendingKey::Master(seed);
|
||||
auto m = GetMasterSaplingSpendingKey();
|
||||
|
||||
// Generate dummy Sapling address
|
||||
auto sk = m.Derive(0);
|
||||
|
@ -1888,9 +1874,7 @@ TEST(WalletTests, MarkAffectedSaplingTransactionsDirty) {
|
|||
TestWallet wallet;
|
||||
|
||||
// Generate Sapling address
|
||||
std::vector<unsigned char, secure_allocator<unsigned char>> rawSeed(32);
|
||||
HDSeed seed(rawSeed);
|
||||
auto sk = libzcash::SaplingExtendedSpendingKey::Master(seed);
|
||||
auto sk = GetMasterSaplingSpendingKey();
|
||||
auto expsk = sk.expsk;
|
||||
auto fvk = expsk.full_viewing_key();
|
||||
auto ivk = fvk.in_viewing_key();
|
||||
|
|
|
@ -302,9 +302,7 @@ double benchmark_try_decrypt_sapling_notes(size_t nAddrs)
|
|||
// Set params
|
||||
auto consensusParams = ActivateSapling();
|
||||
|
||||
std::vector<unsigned char, secure_allocator<unsigned char>> rawSeed(32);
|
||||
HDSeed seed(rawSeed);
|
||||
auto masterKey = libzcash::SaplingExtendedSpendingKey::Master(seed);
|
||||
auto masterKey = GetMasterSaplingSpendingKey();
|
||||
|
||||
CWallet wallet;
|
||||
wallet.AddSaplingSpendingKey(masterKey, masterKey.DefaultAddress());
|
||||
|
|
Loading…
Reference in New Issue