Fixes #1478 by ensuring wallet tests have the -datadir environment set appropriately.

This commit is contained in:
Simon 2016-10-10 20:23:24 -07:00
parent bc0629230a
commit 32bf097f90
2 changed files with 16 additions and 14 deletions

View File

@ -12,6 +12,7 @@
#include <set> #include <set>
#include <vector> #include <vector>
#include <boost/filesystem.hpp> #include <boost/filesystem.hpp>
#include "util.h"
// To run tests: // To run tests:
// ./zcash-gtest --gtest_filter="founders_reward_test.*" // ./zcash-gtest --gtest_filter="founders_reward_test.*"
@ -25,13 +26,14 @@
TEST(founders_reward_test, create_testnet_2of3multisig) { TEST(founders_reward_test, create_testnet_2of3multisig) {
ECC_Start(); ECC_Start();
SelectParams(CBaseChainParams::TESTNET); SelectParams(CBaseChainParams::TESTNET);
boost::filesystem::path temp = boost::filesystem::temp_directory_path() / boost::filesystem::unique_path(); boost::filesystem::path pathTemp = boost::filesystem::temp_directory_path() / boost::filesystem::unique_path();
const std::string path = temp.native() + "-wallet.dat"; boost::filesystem::create_directories(pathTemp);
mapArgs["-datadir"] = pathTemp.string();
bool fFirstRun; bool fFirstRun;
auto pWallet = std::make_shared<CWallet>(path); auto pWallet = std::make_shared<CWallet>("wallet.dat");
ASSERT_EQ(DB_LOAD_OK, pWallet->LoadWallet(fFirstRun)); ASSERT_EQ(DB_LOAD_OK, pWallet->LoadWallet(fFirstRun));
pWallet->TopUpKeyPool(); pWallet->TopUpKeyPool();
std::cout << "Test wallet file path: " << path << std::endl; std::cout << "Test wallet and logs saved in folder: " << pathTemp.native() << std::endl;
int numKeys = 48; int numKeys = 48;
std::vector<CPubKey> pubkeys; std::vector<CPubKey> pubkeys;

View File

@ -75,12 +75,12 @@ TEST(wallet_zkeys_tests, write_zkey_direct_to_db) {
// Get temporary and unique path for file. // Get temporary and unique path for file.
// Note: / operator to append paths // Note: / operator to append paths
boost::filesystem::path temp = boost::filesystem::temp_directory_path() / boost::filesystem::path pathTemp = boost::filesystem::temp_directory_path() / boost::filesystem::unique_path();
boost::filesystem::unique_path(); boost::filesystem::create_directories(pathTemp);
const std::string path = temp.native(); mapArgs["-datadir"] = pathTemp.string();
bool fFirstRun; bool fFirstRun;
CWallet wallet(path); CWallet wallet("wallet.dat");
ASSERT_EQ(DB_LOAD_OK, wallet.LoadWallet(fFirstRun)); ASSERT_EQ(DB_LOAD_OK, wallet.LoadWallet(fFirstRun));
// No default CPubKey set // No default CPubKey set
@ -103,7 +103,7 @@ TEST(wallet_zkeys_tests, write_zkey_direct_to_db) {
auto addr = sk.address(); auto addr = sk.address();
int64_t now = GetTime(); int64_t now = GetTime();
CKeyMetadata meta(now); CKeyMetadata meta(now);
CWalletDB db(path); CWalletDB db("wallet.dat");
db.WriteZKey(addr, sk, meta); db.WriteZKey(addr, sk, meta);
// wallet should not be aware of key // wallet should not be aware of key
@ -150,12 +150,12 @@ TEST(wallet_zkeys_tests, write_cryptedzkey_direct_to_db) {
// Get temporary and unique path for file. // Get temporary and unique path for file.
// Note: / operator to append paths // Note: / operator to append paths
boost::filesystem::path temp = boost::filesystem::temp_directory_path() / boost::filesystem::path pathTemp = boost::filesystem::temp_directory_path() / boost::filesystem::unique_path();
boost::filesystem::unique_path(); boost::filesystem::create_directories(pathTemp);
const std::string path = temp.native(); mapArgs["-datadir"] = pathTemp.string();
bool fFirstRun; bool fFirstRun;
CWallet wallet(path); CWallet wallet("wallet_crypted.dat");
ASSERT_EQ(DB_LOAD_OK, wallet.LoadWallet(fFirstRun)); ASSERT_EQ(DB_LOAD_OK, wallet.LoadWallet(fFirstRun));
// No default CPubKey set // No default CPubKey set
@ -187,7 +187,7 @@ TEST(wallet_zkeys_tests, write_cryptedzkey_direct_to_db) {
auto paymentAddress2 = wallet.GenerateNewZKey(); auto paymentAddress2 = wallet.GenerateNewZKey();
// Create a new wallet from the existing wallet path // Create a new wallet from the existing wallet path
CWallet wallet2(path); CWallet wallet2("wallet_crypted.dat");
ASSERT_EQ(DB_LOAD_OK, wallet2.LoadWallet(fFirstRun)); ASSERT_EQ(DB_LOAD_OK, wallet2.LoadWallet(fFirstRun));
// Confirm it's not the same as the other wallet // Confirm it's not the same as the other wallet