From 74372eaa4c0051c7f1c1cddc3423ff56ac4c0156 Mon Sep 17 00:00:00 2001 From: Jack Grigg Date: Thu, 3 Nov 2016 13:07:54 -0500 Subject: [PATCH] Initialise walletdb system in a temp dir for all gtests --- src/gtest/main.cpp | 10 ++++++++++ src/gtest/test_wallet_zkeys.cpp | 14 -------------- 2 files changed, 10 insertions(+), 14 deletions(-) diff --git a/src/gtest/main.cpp b/src/gtest/main.cpp index 84e6f867c..810e4df1d 100644 --- a/src/gtest/main.cpp +++ b/src/gtest/main.cpp @@ -1,14 +1,24 @@ #include "gtest/gtest.h" #include "crypto/common.h" +#include "wallet/db.h" #include "libsnark/common/default_types/r1cs_ppzksnark_pp.hpp" #include "libsnark/zk_proof_systems/ppzksnark/r1cs_ppzksnark/r1cs_ppzksnark.hpp" +#include + int main(int argc, char **argv) { assert(init_and_check_sodium() != -1); libsnark::default_r1cs_ppzksnark_pp::init_public_params(); libsnark::inhibit_profiling_info = true; libsnark::inhibit_profiling_counters = true; + + // Get temporary and unique path for walletdb. + // bitdb.Open() only intialises once, so this dir is used for all tests. + // Note: / operator to append paths + boost::filesystem::path pathTemp = boost::filesystem::temp_directory_path() / boost::filesystem::unique_path(); + boost::filesystem::create_directories(pathTemp); + bitdb.Open(pathTemp); testing::InitGoogleTest(&argc, argv); return RUN_ALL_TESTS(); diff --git a/src/gtest/test_wallet_zkeys.cpp b/src/gtest/test_wallet_zkeys.cpp index c7912ae7a..73ec43fd5 100644 --- a/src/gtest/test_wallet_zkeys.cpp +++ b/src/gtest/test_wallet_zkeys.cpp @@ -5,8 +5,6 @@ #include "wallet/walletdb.h" #include "util.h" -#include - /** * This test covers methods on CWallet * GenerateNewZKey() @@ -73,12 +71,6 @@ TEST(wallet_zkeys_tests, store_and_load_zkeys) { TEST(wallet_zkeys_tests, write_zkey_direct_to_db) { SelectParams(CBaseChainParams::TESTNET); - // Get temporary and unique path for file. - // Note: / operator to append paths - boost::filesystem::path pathTemp = boost::filesystem::temp_directory_path() / boost::filesystem::unique_path(); - boost::filesystem::create_directories(pathTemp); - mapArgs["-datadir"] = pathTemp.string(); - bool fFirstRun; CWallet wallet("wallet.dat"); ASSERT_EQ(DB_LOAD_OK, wallet.LoadWallet(fFirstRun)); @@ -148,12 +140,6 @@ TEST(wallet_zkeys_tests, write_cryptedzkey_direct_to_db) { SelectParams(CBaseChainParams::TESTNET); - // Get temporary and unique path for file. - // Note: / operator to append paths - boost::filesystem::path pathTemp = boost::filesystem::temp_directory_path() / boost::filesystem::unique_path(); - boost::filesystem::create_directories(pathTemp); - mapArgs["-datadir"] = pathTemp.string(); - bool fFirstRun; CWallet wallet("wallet_crypted.dat"); ASSERT_EQ(DB_LOAD_OK, wallet.LoadWallet(fFirstRun));