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

View File

@ -175,6 +175,12 @@ libzcash::SaplingExtendedSpendingKey GetMasterSaplingSpendingKey() {
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) {
// Generate dummy Sapling note
libzcash::SaplingNote note(pa, value);

View File

@ -5,6 +5,7 @@
#ifndef ZCASH_UTIL_TEST_H
#define ZCASH_UTIL_TEST_H
#include "key_io.h"
#include "wallet/wallet.h"
#include "zcash/JoinSplit.hpp"
#include "zcash/Note.hpp"
@ -26,6 +27,8 @@ CWalletTx GetValidSproutSpend(ZCJoinSplit& params,
CAmount value);
// Sapling
static const std::string T_SECRET_REGTEST = "cND2ZvtabDbJ1gucx9GWH6XT9kgTAqfb6cotPt5Q5CyxVDhid2EN";
struct TestSaplingNote {
libzcash::SaplingNote note;
SaplingMerkleTree tree;
@ -37,6 +40,8 @@ void DeactivateSapling();
libzcash::SaplingExtendedSpendingKey GetMasterSaplingSpendingKey();
CKey AddCKeyToKeyStore(CBasicKeyStore& keyStore);
/**
* 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");
}
static const std::string tSecretRegtest = "cND2ZvtabDbJ1gucx9GWH6XT9kgTAqfb6cotPt5Q5CyxVDhid2EN";
class MockWalletDB {
public:
MOCK_METHOD0(TxnBegin, bool());
@ -1571,8 +1569,7 @@ TEST(WalletTests, SetBestChainIgnoresTxsWithoutShieldedData) {
CBlockLocator loc;
// Set up transparent address
CKey tsk = DecodeSecret(tSecretRegtest);
wallet.AddKey(tsk);
CKey tsk = AddCKeyToKeyStore(wallet);
auto scriptPubKey = GetScriptForDestination(tsk.GetPubKey().GetID());
// Set up a Sprout address
@ -1885,8 +1882,7 @@ TEST(WalletTests, MarkAffectedSaplingTransactionsDirty) {
// Set up transparent address
CBasicKeyStore keystore;
CKey tsk = DecodeSecret(tSecretRegtest);
keystore.AddKey(tsk);
CKey tsk = AddCKeyToKeyStore(keystore);
auto scriptPubKey = GetScriptForDestination(tsk.GetPubKey().GetID());
// Generate shielding tx from transparent to Sapling