From 32bf097f900c1508f817adf229e8bdaf12af6c81 Mon Sep 17 00:00:00 2001 From: Simon Date: Mon, 10 Oct 2016 20:23:24 -0700 Subject: [PATCH 1/3] Fixes #1478 by ensuring wallet tests have the -datadir environment set appropriately. --- src/gtest/test_foundersreward.cpp | 10 ++++++---- src/gtest/test_wallet_zkeys.cpp | 20 ++++++++++---------- 2 files changed, 16 insertions(+), 14 deletions(-) diff --git a/src/gtest/test_foundersreward.cpp b/src/gtest/test_foundersreward.cpp index 4c65b11a8..b7515f55d 100644 --- a/src/gtest/test_foundersreward.cpp +++ b/src/gtest/test_foundersreward.cpp @@ -12,6 +12,7 @@ #include #include #include +#include "util.h" // To run tests: // ./zcash-gtest --gtest_filter="founders_reward_test.*" @@ -25,13 +26,14 @@ TEST(founders_reward_test, create_testnet_2of3multisig) { ECC_Start(); SelectParams(CBaseChainParams::TESTNET); - boost::filesystem::path temp = boost::filesystem::temp_directory_path() / boost::filesystem::unique_path(); - const std::string path = temp.native() + "-wallet.dat"; + boost::filesystem::path pathTemp = boost::filesystem::temp_directory_path() / boost::filesystem::unique_path(); + boost::filesystem::create_directories(pathTemp); + mapArgs["-datadir"] = pathTemp.string(); bool fFirstRun; - auto pWallet = std::make_shared(path); + auto pWallet = std::make_shared("wallet.dat"); ASSERT_EQ(DB_LOAD_OK, pWallet->LoadWallet(fFirstRun)); 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; std::vector pubkeys; diff --git a/src/gtest/test_wallet_zkeys.cpp b/src/gtest/test_wallet_zkeys.cpp index 31a930de0..c7912ae7a 100644 --- a/src/gtest/test_wallet_zkeys.cpp +++ b/src/gtest/test_wallet_zkeys.cpp @@ -75,12 +75,12 @@ TEST(wallet_zkeys_tests, write_zkey_direct_to_db) { // Get temporary and unique path for file. // Note: / operator to append paths - boost::filesystem::path temp = boost::filesystem::temp_directory_path() / - boost::filesystem::unique_path(); - const std::string path = temp.native(); + 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(path); + CWallet wallet("wallet.dat"); ASSERT_EQ(DB_LOAD_OK, wallet.LoadWallet(fFirstRun)); // No default CPubKey set @@ -103,7 +103,7 @@ TEST(wallet_zkeys_tests, write_zkey_direct_to_db) { auto addr = sk.address(); int64_t now = GetTime(); CKeyMetadata meta(now); - CWalletDB db(path); + CWalletDB db("wallet.dat"); db.WriteZKey(addr, sk, meta); // 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. // Note: / operator to append paths - boost::filesystem::path temp = boost::filesystem::temp_directory_path() / - boost::filesystem::unique_path(); - const std::string path = temp.native(); + 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(path); + CWallet wallet("wallet_crypted.dat"); ASSERT_EQ(DB_LOAD_OK, wallet.LoadWallet(fFirstRun)); // No default CPubKey set @@ -187,7 +187,7 @@ TEST(wallet_zkeys_tests, write_cryptedzkey_direct_to_db) { auto paymentAddress2 = wallet.GenerateNewZKey(); // 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)); // Confirm it's not the same as the other wallet From 6be367ea6dc4127b3b0a95d71d8dbd3bfd0225ed Mon Sep 17 00:00:00 2001 From: Simon Date: Fri, 14 Oct 2016 12:44:22 -0700 Subject: [PATCH 2/3] Fix test so that the encrypted wallet is output to the test_bitcoin -datadir folder. --- src/test/rpc_wallet_tests.cpp | 3 +++ 1 file changed, 3 insertions(+) diff --git a/src/test/rpc_wallet_tests.cpp b/src/test/rpc_wallet_tests.cpp index 5a4bd3a00..c956c7e8c 100644 --- a/src/test/rpc_wallet_tests.cpp +++ b/src/test/rpc_wallet_tests.cpp @@ -29,6 +29,7 @@ #include #include #include +#include using namespace std; using namespace json_spirit; @@ -1069,6 +1070,8 @@ BOOST_AUTO_TEST_CASE(rpc_wallet_encrypted_wallet_zkeys) SecureString strWalletPass; strWalletPass.reserve(100); strWalletPass = "hello"; + + boost::filesystem::current_path(GetArg("-datadir","/tmp/thisshouldnothappen")); BOOST_CHECK(pwalletMain->EncryptWallet(strWalletPass)); // Verify we can still list the keys imported From b13a87c6d7c334336aef98333c02a45bcc012ead Mon Sep 17 00:00:00 2001 From: Simon Date: Fri, 14 Oct 2016 13:36:53 -0700 Subject: [PATCH 3/3] Reorder gtests in zcash-gtest. There is an issue where checktransaction_tests will output errors to ~/.zcash/testnet3/debug.log because other tests which run before it select the testnet chain parameters. --- src/Makefile.gtest.include | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/src/Makefile.gtest.include b/src/Makefile.gtest.include index b4cfd3c26..d08b7d607 100644 --- a/src/Makefile.gtest.include +++ b/src/Makefile.gtest.include @@ -4,11 +4,12 @@ bin_PROGRAMS += zcash-gtest # tool for generating our public parameters zcash_gtest_SOURCES = \ gtest/main.cpp \ + gtest/test_checktransaction.cpp \ gtest/json_test_vectors.cpp \ gtest/test_foundersreward.cpp \ + gtest/test_wallet_zkeys.cpp \ gtest/test_jsonspirit.cpp \ gtest/test_tautology.cpp \ - gtest/test_checktransaction.cpp \ gtest/test_equihash.cpp \ gtest/test_joinsplit.cpp \ gtest/test_keystore.cpp \ @@ -18,7 +19,6 @@ zcash_gtest_SOURCES = \ gtest/test_rpc.cpp \ gtest/test_circuit.cpp \ gtest/test_txid.cpp \ - gtest/test_wallet_zkeys.cpp \ gtest/test_libzcash_utils.cpp \ gtest/test_proofs.cpp \ wallet/gtest/test_wallet.cpp