Bitcoin ABC  0.22.13
P2P Digital Currency
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 
6 
7 #include <chainparams.h>
8 #include <fs.h>
9 #include <util/check.h>
10 #include <util/system.h>
11 
13  const std::string &chainName)
14  : BasicTestingSetup(chainName) {
17 
18  std::string sep;
19  sep += fs::path::preferred_separator;
20 
22  m_cwd = fs::current_path();
23 
24  m_walletdir_path_cases["default"] = m_datadir / "wallets";
25  m_walletdir_path_cases["custom"] = m_datadir / "my_wallets";
26  m_walletdir_path_cases["nonexistent"] = m_datadir / "path_does_not_exist";
27  m_walletdir_path_cases["file"] = m_datadir / "not_a_directory.dat";
28  m_walletdir_path_cases["trailing"] = m_datadir / "wallets" / sep;
29  m_walletdir_path_cases["trailing2"] = m_datadir / "wallets" / sep / sep;
30 
31  fs::current_path(m_datadir);
32  m_walletdir_path_cases["relative"] = "wallets";
33 
34  fs::create_directories(m_walletdir_path_cases["default"]);
35  fs::create_directories(m_walletdir_path_cases["custom"]);
36  fs::create_directories(m_walletdir_path_cases["relative"]);
37  std::ofstream f(m_walletdir_path_cases["file"].BOOST_FILESYSTEM_C_STR);
38  f.close();
39 }
40 
42  fs::current_path(m_cwd);
43 }
44 
45 void InitWalletDirTestingSetup::SetWalletDir(const fs::path &walletdir_path) {
46  gArgs.ForceSetArg("-walletdir", walletdir_path.string());
47 }
std::unique_ptr< interfaces::ChainClient > m_chain_client
InitWalletDirTestingSetup(const std::string &chainName=CBaseChainParams::MAIN)
std::unique_ptr< interfaces::Chain > m_chain
NodeContext & m_node
Definition: chain.cpp:442
void ForceSetArg(const std::string &strArg, const std::string &strValue)
Definition: system.cpp:523
fs::ofstream ofstream
Definition: fs.h:99
void SetWalletDir(const fs::path &walletdir_path)
const fs::path & GetDataDir(bool fNetSpecific)
Definition: system.cpp:760
std::map< std::string, fs::path > m_walletdir_path_cases
ArgsManager * args
Definition: context.h:44
const CChainParams & Params()
Return the currently selected parameters.
ArgsManager gArgs
Definition: system.cpp:76
std::unique_ptr< ChainClient > MakeWalletClient(Chain &chain, ArgsManager &args, std::vector< std::string > wallet_filenames)
Return implementation of ChainClient interface for a wallet client.
Definition: wallet.cpp:532
#define Assert(val)
Identity function.
Definition: check.h:57
std::unique_ptr< Chain > MakeChain(NodeContext &node, const CChainParams &params)
Return implementation of Chain interface.
Definition: chain.cpp:448