2019-05-06 14:05:28 -04:00
|
|
|
// Copyright (c) 2018-2019 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.
|
|
|
|
|
|
|
|
#include <boost/test/unit_test.hpp>
|
|
|
|
|
2019-06-24 17:14:43 +02:00
|
|
|
#include <noui.h>
|
2019-11-05 15:18:59 -05:00
|
|
|
#include <test/util/logging.h>
|
|
|
|
#include <test/util/setup_common.h>
|
2019-06-24 17:22:28 +02:00
|
|
|
#include <util/system.h>
|
2018-09-10 20:49:17 -04:00
|
|
|
#include <wallet/test/init_test_fixture.h>
|
|
|
|
|
|
|
|
BOOST_FIXTURE_TEST_SUITE(init_tests, InitWalletDirTestingSetup)
|
|
|
|
|
|
|
|
BOOST_AUTO_TEST_CASE(walletinit_verify_walletdir_default)
|
|
|
|
{
|
|
|
|
SetWalletDir(m_walletdir_path_cases["default"]);
|
2020-05-28 09:48:30 -04:00
|
|
|
bool result = m_wallet_client->verify();
|
2018-09-10 20:49:17 -04:00
|
|
|
BOOST_CHECK(result == true);
|
|
|
|
fs::path walletdir = gArgs.GetArg("-walletdir", "");
|
|
|
|
fs::path expected_path = fs::canonical(m_walletdir_path_cases["default"]);
|
|
|
|
BOOST_CHECK(walletdir == expected_path);
|
|
|
|
}
|
|
|
|
|
|
|
|
BOOST_AUTO_TEST_CASE(walletinit_verify_walletdir_custom)
|
|
|
|
{
|
|
|
|
SetWalletDir(m_walletdir_path_cases["custom"]);
|
2020-05-28 09:48:30 -04:00
|
|
|
bool result = m_wallet_client->verify();
|
2018-09-10 20:49:17 -04:00
|
|
|
BOOST_CHECK(result == true);
|
|
|
|
fs::path walletdir = gArgs.GetArg("-walletdir", "");
|
|
|
|
fs::path expected_path = fs::canonical(m_walletdir_path_cases["custom"]);
|
|
|
|
BOOST_CHECK(walletdir == expected_path);
|
|
|
|
}
|
|
|
|
|
|
|
|
BOOST_AUTO_TEST_CASE(walletinit_verify_walletdir_does_not_exist)
|
|
|
|
{
|
|
|
|
SetWalletDir(m_walletdir_path_cases["nonexistent"]);
|
2019-08-02 17:06:37 -04:00
|
|
|
{
|
|
|
|
ASSERT_DEBUG_LOG("does not exist");
|
2020-05-28 09:48:30 -04:00
|
|
|
bool result = m_wallet_client->verify();
|
2019-08-02 17:06:37 -04:00
|
|
|
BOOST_CHECK(result == false);
|
|
|
|
}
|
2018-09-10 20:49:17 -04:00
|
|
|
}
|
|
|
|
|
|
|
|
BOOST_AUTO_TEST_CASE(walletinit_verify_walletdir_is_not_directory)
|
|
|
|
{
|
|
|
|
SetWalletDir(m_walletdir_path_cases["file"]);
|
2019-08-02 17:06:37 -04:00
|
|
|
{
|
|
|
|
ASSERT_DEBUG_LOG("is not a directory");
|
2020-05-28 09:48:30 -04:00
|
|
|
bool result = m_wallet_client->verify();
|
2019-08-02 17:06:37 -04:00
|
|
|
BOOST_CHECK(result == false);
|
|
|
|
}
|
2018-09-10 20:49:17 -04:00
|
|
|
}
|
|
|
|
|
|
|
|
BOOST_AUTO_TEST_CASE(walletinit_verify_walletdir_is_not_relative)
|
|
|
|
{
|
|
|
|
SetWalletDir(m_walletdir_path_cases["relative"]);
|
2019-08-02 17:06:37 -04:00
|
|
|
{
|
|
|
|
ASSERT_DEBUG_LOG("is a relative path");
|
2020-05-28 09:48:30 -04:00
|
|
|
bool result = m_wallet_client->verify();
|
2019-08-02 17:06:37 -04:00
|
|
|
BOOST_CHECK(result == false);
|
|
|
|
}
|
2018-09-10 20:49:17 -04:00
|
|
|
}
|
|
|
|
|
2018-09-10 20:50:42 -04:00
|
|
|
BOOST_AUTO_TEST_CASE(walletinit_verify_walletdir_no_trailing)
|
|
|
|
{
|
|
|
|
SetWalletDir(m_walletdir_path_cases["trailing"]);
|
2020-05-28 09:48:30 -04:00
|
|
|
bool result = m_wallet_client->verify();
|
2018-09-10 20:50:42 -04:00
|
|
|
BOOST_CHECK(result == true);
|
|
|
|
fs::path walletdir = gArgs.GetArg("-walletdir", "");
|
|
|
|
fs::path expected_path = fs::canonical(m_walletdir_path_cases["default"]);
|
|
|
|
BOOST_CHECK(walletdir == expected_path);
|
|
|
|
}
|
|
|
|
|
|
|
|
BOOST_AUTO_TEST_CASE(walletinit_verify_walletdir_no_trailing2)
|
|
|
|
{
|
|
|
|
SetWalletDir(m_walletdir_path_cases["trailing2"]);
|
2020-05-28 09:48:30 -04:00
|
|
|
bool result = m_wallet_client->verify();
|
2018-09-10 20:50:42 -04:00
|
|
|
BOOST_CHECK(result == true);
|
|
|
|
fs::path walletdir = gArgs.GetArg("-walletdir", "");
|
|
|
|
fs::path expected_path = fs::canonical(m_walletdir_path_cases["default"]);
|
|
|
|
BOOST_CHECK(walletdir == expected_path);
|
|
|
|
}
|
|
|
|
|
2018-09-10 20:49:17 -04:00
|
|
|
BOOST_AUTO_TEST_SUITE_END()
|