Bitcoin Core  0.20.99
P2P Digital Currency
init_test_fixture.cpp
Go to the documentation of this file.
1 // Copyright (c) 2018-2019 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 #include <util/system.h>
7 
9 
10 InitWalletDirTestingSetup::InitWalletDirTestingSetup(const std::string& chainName): BasicTestingSetup(chainName)
11 {
13 
14  std::string sep;
15  sep += fs::path::preferred_separator;
16 
18  m_cwd = fs::current_path();
19 
20  m_walletdir_path_cases["default"] = m_datadir / "wallets";
21  m_walletdir_path_cases["custom"] = m_datadir / "my_wallets";
22  m_walletdir_path_cases["nonexistent"] = m_datadir / "path_does_not_exist";
23  m_walletdir_path_cases["file"] = m_datadir / "not_a_directory.dat";
24  m_walletdir_path_cases["trailing"] = m_datadir / "wallets" / sep;
25  m_walletdir_path_cases["trailing2"] = m_datadir / "wallets" / sep / sep;
26 
27  fs::current_path(m_datadir);
28  m_walletdir_path_cases["relative"] = "wallets";
29 
30  fs::create_directories(m_walletdir_path_cases["default"]);
31  fs::create_directories(m_walletdir_path_cases["custom"]);
32  fs::create_directories(m_walletdir_path_cases["relative"]);
33  std::ofstream f(m_walletdir_path_cases["file"].BOOST_FILESYSTEM_C_STR);
34  f.close();
35 }
36 
38 {
39  fs::current_path(m_cwd);
40 }
41 
42 void InitWalletDirTestingSetup::SetWalletDir(const fs::path& walletdir_path)
43 {
44  gArgs.ForceSetArg("-walletdir", walletdir_path.string());
45 }
std::unique_ptr< interfaces::ChainClient > m_chain_client
InitWalletDirTestingSetup(const std::string &chainName=CBaseChainParams::MAIN)
std::unique_ptr< interfaces::Chain > m_chain
std::unique_ptr< ChainClient > MakeWalletClient(Chain &chain, std::vector< std::string > wallet_filenames)
Return implementation of ChainClient interface for a wallet client.
Definition: wallet.cpp:517
void ForceSetArg(const std::string &strArg, const std::string &strValue)
Definition: system.cpp:414
fs::ofstream ofstream
Definition: fs.h:91
void SetWalletDir(const fs::path &walletdir_path)
const fs::path & GetDataDir(bool fNetSpecific)
Definition: system.cpp:620
std::map< std::string, fs::path > m_walletdir_path_cases
ArgsManager gArgs
Definition: system.cpp:77