2022-12-24 23:49:50 +00:00
|
|
|
// Copyright (c) 2018-2022 The Bitcoin Core developers
|
2018-09-10 20:49:17 -04:00
|
|
|
// Distributed under the MIT software license, see the accompanying
|
|
|
|
// file COPYING or http://www.opensource.org/licenses/mit-license.php.
|
|
|
|
|
2023-03-23 12:23:29 +01:00
|
|
|
#include <common/args.h>
|
2021-01-15 07:26:51 +00:00
|
|
|
#include <univalue.h>
|
2023-04-17 22:20:59 +02:00
|
|
|
#include <util/chaintype.h>
|
2020-05-11 17:40:21 +02:00
|
|
|
#include <util/check.h>
|
2023-03-15 11:18:06 +01:00
|
|
|
#include <util/fs.h>
|
2018-09-10 20:49:17 -04:00
|
|
|
|
2020-06-11 08:58:46 +02:00
|
|
|
#include <fstream>
|
|
|
|
#include <string>
|
|
|
|
|
2018-09-10 20:49:17 -04:00
|
|
|
#include <wallet/test/init_test_fixture.h>
|
|
|
|
|
2021-11-12 11:13:29 -05:00
|
|
|
namespace wallet {
|
2023-04-17 22:20:59 +02:00
|
|
|
InitWalletDirTestingSetup::InitWalletDirTestingSetup(const ChainType chainType) : BasicTestingSetup(chainType)
|
2018-09-10 20:49:17 -04:00
|
|
|
{
|
2021-12-02 21:21:05 +01:00
|
|
|
m_wallet_loader = MakeWalletLoader(*m_node.chain, m_args);
|
2017-09-28 14:13:29 -04:00
|
|
|
|
2022-03-03 14:40:18 -05:00
|
|
|
const auto sep = fs::path::preferred_separator;
|
2018-09-10 20:49:17 -04:00
|
|
|
|
2021-12-02 21:21:05 +01:00
|
|
|
m_datadir = m_args.GetDataDirNet();
|
2018-09-10 20:49:17 -04:00
|
|
|
m_cwd = fs::current_path();
|
|
|
|
|
|
|
|
m_walletdir_path_cases["default"] = m_datadir / "wallets";
|
|
|
|
m_walletdir_path_cases["custom"] = m_datadir / "my_wallets";
|
|
|
|
m_walletdir_path_cases["nonexistent"] = m_datadir / "path_does_not_exist";
|
|
|
|
m_walletdir_path_cases["file"] = m_datadir / "not_a_directory.dat";
|
2022-03-03 14:40:18 -05:00
|
|
|
m_walletdir_path_cases["trailing"] = (m_datadir / "wallets") + sep;
|
|
|
|
m_walletdir_path_cases["trailing2"] = (m_datadir / "wallets") + sep + sep;
|
2018-09-10 20:49:17 -04:00
|
|
|
|
|
|
|
fs::current_path(m_datadir);
|
|
|
|
m_walletdir_path_cases["relative"] = "wallets";
|
|
|
|
|
|
|
|
fs::create_directories(m_walletdir_path_cases["default"]);
|
|
|
|
fs::create_directories(m_walletdir_path_cases["custom"]);
|
|
|
|
fs::create_directories(m_walletdir_path_cases["relative"]);
|
2020-06-11 08:58:46 +02:00
|
|
|
std::ofstream f{m_walletdir_path_cases["file"]};
|
2018-09-10 20:49:17 -04:00
|
|
|
f.close();
|
|
|
|
}
|
|
|
|
|
|
|
|
InitWalletDirTestingSetup::~InitWalletDirTestingSetup()
|
|
|
|
{
|
|
|
|
fs::current_path(m_cwd);
|
|
|
|
}
|
|
|
|
|
|
|
|
void InitWalletDirTestingSetup::SetWalletDir(const fs::path& walletdir_path)
|
|
|
|
{
|
2021-12-02 21:21:05 +01:00
|
|
|
m_args.ForceSetArg("-walletdir", fs::PathToString(walletdir_path));
|
2019-06-19 17:52:35 -04:00
|
|
|
}
|
2021-11-12 11:13:29 -05:00
|
|
|
} // namespace wallet
|