BSHA3  0.17.99
P2P Blockchain, based on Bitcoin
init_test_fixture.cpp
Go to the documentation of this file.
1 // Copyright (c) 2018 The Bitcoin Core developers
2 // Distributed under the MIT software license, see the accompanying
3 // file COPYING or http://www.opensource.org/licenses/mit-license.php.
4 
5 #include <fs.h>
6 
8 
9 InitWalletDirTestingSetup::InitWalletDirTestingSetup(const std::string& chainName): BasicTestingSetup(chainName)
10 {
11  std::string sep;
12  sep += fs::path::preferred_separator;
13 
14  m_datadir = SetDataDir("tempdir");
15  m_cwd = fs::current_path();
16 
17  m_walletdir_path_cases["default"] = m_datadir / "wallets";
18  m_walletdir_path_cases["custom"] = m_datadir / "my_wallets";
19  m_walletdir_path_cases["nonexistent"] = m_datadir / "path_does_not_exist";
20  m_walletdir_path_cases["file"] = m_datadir / "not_a_directory.dat";
21  m_walletdir_path_cases["trailing"] = m_datadir / "wallets" / sep;
22  m_walletdir_path_cases["trailing2"] = m_datadir / "wallets" / sep / sep;
23 
24  fs::current_path(m_datadir);
25  m_walletdir_path_cases["relative"] = "wallets";
26 
27  fs::create_directories(m_walletdir_path_cases["default"]);
28  fs::create_directories(m_walletdir_path_cases["custom"]);
29  fs::create_directories(m_walletdir_path_cases["relative"]);
30  std::ofstream f(m_walletdir_path_cases["file"].BOOST_FILESYSTEM_C_STR);
31  f.close();
32 }
33 
35 {
36  fs::current_path(m_cwd);
37 }
38 
39 void InitWalletDirTestingSetup::SetWalletDir(const fs::path& walletdir_path)
40 {
41  gArgs.ForceSetArg("-walletdir", walletdir_path.string());
42 }
InitWalletDirTestingSetup(const std::string &chainName=CBaseChainParams::MAIN)
void ForceSetArg(const std::string &strArg, const std::string &strValue)
Definition: util.cpp:566
fs::ofstream ofstream
Definition: fs.h:91
void SetWalletDir(const fs::path &walletdir_path)
std::map< std::string, fs::path > m_walletdir_path_cases
ArgsManager gArgs
Definition: util.cpp:88