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 <boost/test/unit_test.hpp>
6 
7 #include <noui.h>
8 #include <test/util/logging.h>
9 #include <test/util/setup_common.h>
10 #include <util/system.h>
11 #include <wallet/test/init_test_fixture.h>
12 
BOOST_FIXTURE_TEST_SUITE(init_tests,InitWalletDirTestingSetup)13 BOOST_FIXTURE_TEST_SUITE(init_tests, InitWalletDirTestingSetup)
14 
15 BOOST_AUTO_TEST_CASE(walletinit_verify_walletdir_default)
16 {
17     SetWalletDir(m_walletdir_path_cases["default"]);
18     bool result = m_wallet_client->verify();
19     BOOST_CHECK(result == true);
20     fs::path walletdir = gArgs.GetArg("-walletdir", "");
21     fs::path expected_path = fs::canonical(m_walletdir_path_cases["default"]);
22     BOOST_CHECK(walletdir == expected_path);
23 }
24 
BOOST_AUTO_TEST_CASE(walletinit_verify_walletdir_custom)25 BOOST_AUTO_TEST_CASE(walletinit_verify_walletdir_custom)
26 {
27     SetWalletDir(m_walletdir_path_cases["custom"]);
28     bool result = m_wallet_client->verify();
29     BOOST_CHECK(result == true);
30     fs::path walletdir = gArgs.GetArg("-walletdir", "");
31     fs::path expected_path = fs::canonical(m_walletdir_path_cases["custom"]);
32     BOOST_CHECK(walletdir == expected_path);
33 }
34 
BOOST_AUTO_TEST_CASE(walletinit_verify_walletdir_does_not_exist)35 BOOST_AUTO_TEST_CASE(walletinit_verify_walletdir_does_not_exist)
36 {
37     SetWalletDir(m_walletdir_path_cases["nonexistent"]);
38     {
39         ASSERT_DEBUG_LOG("does not exist");
40         bool result = m_wallet_client->verify();
41         BOOST_CHECK(result == false);
42     }
43 }
44 
BOOST_AUTO_TEST_CASE(walletinit_verify_walletdir_is_not_directory)45 BOOST_AUTO_TEST_CASE(walletinit_verify_walletdir_is_not_directory)
46 {
47     SetWalletDir(m_walletdir_path_cases["file"]);
48     {
49         ASSERT_DEBUG_LOG("is not a directory");
50         bool result = m_wallet_client->verify();
51         BOOST_CHECK(result == false);
52     }
53 }
54 
BOOST_AUTO_TEST_CASE(walletinit_verify_walletdir_is_not_relative)55 BOOST_AUTO_TEST_CASE(walletinit_verify_walletdir_is_not_relative)
56 {
57     SetWalletDir(m_walletdir_path_cases["relative"]);
58     {
59         ASSERT_DEBUG_LOG("is a relative path");
60         bool result = m_wallet_client->verify();
61         BOOST_CHECK(result == false);
62     }
63 }
64 
BOOST_AUTO_TEST_CASE(walletinit_verify_walletdir_no_trailing)65 BOOST_AUTO_TEST_CASE(walletinit_verify_walletdir_no_trailing)
66 {
67     SetWalletDir(m_walletdir_path_cases["trailing"]);
68     bool result = m_wallet_client->verify();
69     BOOST_CHECK(result == true);
70     fs::path walletdir = gArgs.GetArg("-walletdir", "");
71     fs::path expected_path = fs::canonical(m_walletdir_path_cases["default"]);
72     BOOST_CHECK(walletdir == expected_path);
73 }
74 
BOOST_AUTO_TEST_CASE(walletinit_verify_walletdir_no_trailing2)75 BOOST_AUTO_TEST_CASE(walletinit_verify_walletdir_no_trailing2)
76 {
77     SetWalletDir(m_walletdir_path_cases["trailing2"]);
78     bool result = m_wallet_client->verify();
79     BOOST_CHECK(result == true);
80     fs::path walletdir = gArgs.GetArg("-walletdir", "");
81     fs::path expected_path = fs::canonical(m_walletdir_path_cases["default"]);
82     BOOST_CHECK(walletdir == expected_path);
83 }
84 
85 BOOST_AUTO_TEST_SUITE_END()
86