Add a method for generating a test CKey

This commit is contained in:
Eirik Ogilvie-Wigley 2018-11-12 17:48:04 -07:00
parent 010481c7e5
commit 275bd8f67a
4 changed files with 16 additions and 14 deletions

View File

@ -12,15 +12,12 @@
#include <gmock/gmock.h> #include <gmock/gmock.h>
#include <gtest/gtest.h> #include <gtest/gtest.h>
static const std::string tSecretRegtest = "cND2ZvtabDbJ1gucx9GWH6XT9kgTAqfb6cotPt5Q5CyxVDhid2EN";
TEST(TransactionBuilder, Invoke) TEST(TransactionBuilder, Invoke)
{ {
auto consensusParams = ActivateSapling(); auto consensusParams = ActivateSapling();
CBasicKeyStore keystore; CBasicKeyStore keystore;
CKey tsk = DecodeSecret(tSecretRegtest); CKey tsk = AddCKeyToKeyStore(keystore);
keystore.AddKey(tsk);
auto scriptPubKey = GetScriptForDestination(tsk.GetPubKey().GetID()); auto scriptPubKey = GetScriptForDestination(tsk.GetPubKey().GetID());
auto sk_from = libzcash::SaplingSpendingKey::random(); auto sk_from = libzcash::SaplingSpendingKey::random();
@ -131,8 +128,7 @@ TEST(TransactionBuilder, FailsWithNegativeChange)
// Set up dummy transparent address // Set up dummy transparent address
CBasicKeyStore keystore; CBasicKeyStore keystore;
CKey tsk = DecodeSecret(tSecretRegtest); CKey tsk = AddCKeyToKeyStore(keystore);
keystore.AddKey(tsk);
auto tkeyid = tsk.GetPubKey().GetID(); auto tkeyid = tsk.GetPubKey().GetID();
auto scriptPubKey = GetScriptForDestination(tkeyid); auto scriptPubKey = GetScriptForDestination(tkeyid);
CTxDestination taddr = tkeyid; CTxDestination taddr = tkeyid;
@ -182,8 +178,7 @@ TEST(TransactionBuilder, ChangeOutput)
// Set up dummy transparent address // Set up dummy transparent address
CBasicKeyStore keystore; CBasicKeyStore keystore;
CKey tsk = DecodeSecret(tSecretRegtest); CKey tsk = AddCKeyToKeyStore(keystore);
keystore.AddKey(tsk);
auto tkeyid = tsk.GetPubKey().GetID(); auto tkeyid = tsk.GetPubKey().GetID();
auto scriptPubKey = GetScriptForDestination(tkeyid); auto scriptPubKey = GetScriptForDestination(tkeyid);
CTxDestination taddr = tkeyid; CTxDestination taddr = tkeyid;

View File

@ -175,6 +175,12 @@ libzcash::SaplingExtendedSpendingKey GetMasterSaplingSpendingKey() {
return libzcash::SaplingExtendedSpendingKey::Master(seed); return libzcash::SaplingExtendedSpendingKey::Master(seed);
} }
CKey AddCKeyToKeyStore(CBasicKeyStore& keyStore) {
CKey tsk = DecodeSecret(T_SECRET_REGTEST);
keyStore.AddKey(tsk);
return tsk;
}
TestSaplingNote GetTestSaplingNote(const libzcash::SaplingPaymentAddress& pa, CAmount value) { TestSaplingNote GetTestSaplingNote(const libzcash::SaplingPaymentAddress& pa, CAmount value) {
// Generate dummy Sapling note // Generate dummy Sapling note
libzcash::SaplingNote note(pa, value); libzcash::SaplingNote note(pa, value);

View File

@ -5,6 +5,7 @@
#ifndef ZCASH_UTIL_TEST_H #ifndef ZCASH_UTIL_TEST_H
#define ZCASH_UTIL_TEST_H #define ZCASH_UTIL_TEST_H
#include "key_io.h"
#include "wallet/wallet.h" #include "wallet/wallet.h"
#include "zcash/JoinSplit.hpp" #include "zcash/JoinSplit.hpp"
#include "zcash/Note.hpp" #include "zcash/Note.hpp"
@ -26,6 +27,8 @@ CWalletTx GetValidSproutSpend(ZCJoinSplit& params,
CAmount value); CAmount value);
// Sapling // Sapling
static const std::string T_SECRET_REGTEST = "cND2ZvtabDbJ1gucx9GWH6XT9kgTAqfb6cotPt5Q5CyxVDhid2EN";
struct TestSaplingNote { struct TestSaplingNote {
libzcash::SaplingNote note; libzcash::SaplingNote note;
SaplingMerkleTree tree; SaplingMerkleTree tree;
@ -37,6 +40,8 @@ void DeactivateSapling();
libzcash::SaplingExtendedSpendingKey GetMasterSaplingSpendingKey(); libzcash::SaplingExtendedSpendingKey GetMasterSaplingSpendingKey();
CKey AddCKeyToKeyStore(CBasicKeyStore& keyStore);
/** /**
* Generate a dummy SaplingNote and a SaplingMerkleTree with that note's commitment. * Generate a dummy SaplingNote and a SaplingMerkleTree with that note's commitment.
*/ */

View File

@ -25,8 +25,6 @@ ACTION(ThrowLogicError) {
throw std::logic_error("Boom"); throw std::logic_error("Boom");
} }
static const std::string tSecretRegtest = "cND2ZvtabDbJ1gucx9GWH6XT9kgTAqfb6cotPt5Q5CyxVDhid2EN";
class MockWalletDB { class MockWalletDB {
public: public:
MOCK_METHOD0(TxnBegin, bool()); MOCK_METHOD0(TxnBegin, bool());
@ -1571,8 +1569,7 @@ TEST(WalletTests, SetBestChainIgnoresTxsWithoutShieldedData) {
CBlockLocator loc; CBlockLocator loc;
// Set up transparent address // Set up transparent address
CKey tsk = DecodeSecret(tSecretRegtest); CKey tsk = AddCKeyToKeyStore(wallet);
wallet.AddKey(tsk);
auto scriptPubKey = GetScriptForDestination(tsk.GetPubKey().GetID()); auto scriptPubKey = GetScriptForDestination(tsk.GetPubKey().GetID());
// Set up a Sprout address // Set up a Sprout address
@ -1885,8 +1882,7 @@ TEST(WalletTests, MarkAffectedSaplingTransactionsDirty) {
// Set up transparent address // Set up transparent address
CBasicKeyStore keystore; CBasicKeyStore keystore;
CKey tsk = DecodeSecret(tSecretRegtest); CKey tsk = AddCKeyToKeyStore(keystore);
keystore.AddKey(tsk);
auto scriptPubKey = GetScriptForDestination(tsk.GetPubKey().GetID()); auto scriptPubKey = GetScriptForDestination(tsk.GetPubKey().GetID());
// Generate shielding tx from transparent to Sapling // Generate shielding tx from transparent to Sapling