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 
7 #include <wallet/test/init_test_fixture.h>
8 
InitWalletDirTestingSetup(const std::string & chainName)9 InitWalletDirTestingSetup::InitWalletDirTestingSetup(const std::string& chainName): BasicTestingSetup(chainName)
10 {
11     m_chain_client = MakeWalletClient(*m_chain, {});
12 
13     std::string sep;
14     sep += fs::path::preferred_separator;
15 
16     m_datadir = SetDataDir("tempdir");
17     m_cwd = fs::current_path();
18 
19     m_walletdir_path_cases["default"] = m_datadir / "wallets";
20     m_walletdir_path_cases["custom"] = m_datadir / "my_wallets";
21     m_walletdir_path_cases["nonexistent"] = m_datadir / "path_does_not_exist";
22     m_walletdir_path_cases["file"] = m_datadir / "not_a_directory.dat";
23     m_walletdir_path_cases["trailing"] = m_datadir / "wallets" / sep;
24     m_walletdir_path_cases["trailing2"] = m_datadir / "wallets" / sep / sep;
25 
26     fs::current_path(m_datadir);
27     m_walletdir_path_cases["relative"] = "wallets";
28 
29     fs::create_directories(m_walletdir_path_cases["default"]);
30     fs::create_directories(m_walletdir_path_cases["custom"]);
31     fs::create_directories(m_walletdir_path_cases["relative"]);
32     std::ofstream f(m_walletdir_path_cases["file"].BOOST_FILESYSTEM_C_STR);
33     f.close();
34 }
35 
~InitWalletDirTestingSetup()36 InitWalletDirTestingSetup::~InitWalletDirTestingSetup()
37 {
38     fs::current_path(m_cwd);
39 }
40 
SetWalletDir(const fs::path & walletdir_path)41 void InitWalletDirTestingSetup::SetWalletDir(const fs::path& walletdir_path)
42 {
43     gArgs.ForceSetArg("-walletdir", walletdir_path.string());
44 }