Line data Source code
1 : // Copyright (c) 2018-2021 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 <util/system.h> 10 : #include <wallet/test/init_test_fixture.h> 11 : 12 : namespace wallet { 13 146 : BOOST_FIXTURE_TEST_SUITE(init_tests, InitWalletDirTestingSetup) 14 : 15 148 : BOOST_AUTO_TEST_CASE(walletinit_verify_walletdir_default) 16 : { 17 1 : SetWalletDir(m_walletdir_path_cases["default"]); 18 : { 19 1 : ASSERT_DEBUG_LOG(""); 20 1 : bool result = m_wallet_loader->verify(); 21 1 : BOOST_CHECK(result == true); 22 1 : } 23 1 : fs::path walletdir = m_args.GetPathArg("-walletdir"); 24 1 : fs::path expected_path = fs::canonical(m_walletdir_path_cases["default"]); 25 1 : BOOST_CHECK_EQUAL(walletdir, expected_path); 26 1 : } 27 : 28 148 : BOOST_AUTO_TEST_CASE(walletinit_verify_walletdir_custom) 29 : { 30 1 : SetWalletDir(m_walletdir_path_cases["custom"]); 31 : { 32 1 : ASSERT_DEBUG_LOG(""); 33 1 : bool result = m_wallet_loader->verify(); 34 1 : BOOST_CHECK(result == true); 35 1 : } 36 1 : fs::path walletdir = m_args.GetPathArg("-walletdir"); 37 1 : fs::path expected_path = fs::canonical(m_walletdir_path_cases["custom"]); 38 1 : BOOST_CHECK_EQUAL(walletdir, expected_path); 39 1 : } 40 : 41 148 : BOOST_AUTO_TEST_CASE(walletinit_verify_walletdir_does_not_exist) 42 : { 43 1 : SetWalletDir(m_walletdir_path_cases["nonexistent"]); 44 : { 45 1 : ASSERT_DEBUG_LOG("does not exist"); 46 1 : bool result = m_wallet_loader->verify(); 47 1 : BOOST_CHECK(result == false); 48 1 : } 49 1 : } 50 : 51 148 : BOOST_AUTO_TEST_CASE(walletinit_verify_walletdir_is_not_directory) 52 : { 53 1 : SetWalletDir(m_walletdir_path_cases["file"]); 54 : { 55 1 : ASSERT_DEBUG_LOG("is not a directory"); 56 1 : bool result = m_wallet_loader->verify(); 57 1 : BOOST_CHECK(result == false); 58 1 : } 59 1 : } 60 : 61 148 : BOOST_AUTO_TEST_CASE(walletinit_verify_walletdir_is_not_relative) 62 : { 63 1 : SetWalletDir(m_walletdir_path_cases["relative"]); 64 : { 65 1 : ASSERT_DEBUG_LOG("is a relative path"); 66 1 : bool result = m_wallet_loader->verify(); 67 1 : BOOST_CHECK(result == false); 68 1 : } 69 1 : } 70 : 71 148 : BOOST_AUTO_TEST_CASE(walletinit_verify_walletdir_no_trailing) 72 : { 73 1 : SetWalletDir(m_walletdir_path_cases["trailing"]); 74 : { 75 1 : ASSERT_DEBUG_LOG(""); 76 1 : bool result = m_wallet_loader->verify(); 77 1 : BOOST_CHECK(result == true); 78 1 : } 79 1 : fs::path walletdir = m_args.GetPathArg("-walletdir"); 80 1 : fs::path expected_path = fs::canonical(m_walletdir_path_cases["default"]); 81 1 : BOOST_CHECK_EQUAL(walletdir, expected_path); 82 1 : } 83 : 84 148 : BOOST_AUTO_TEST_CASE(walletinit_verify_walletdir_no_trailing2) 85 : { 86 1 : SetWalletDir(m_walletdir_path_cases["trailing2"]); 87 : { 88 1 : ASSERT_DEBUG_LOG(""); 89 1 : bool result = m_wallet_loader->verify(); 90 1 : BOOST_CHECK(result == true); 91 1 : } 92 1 : fs::path walletdir = m_args.GetPathArg("-walletdir"); 93 1 : fs::path expected_path = fs::canonical(m_walletdir_path_cases["default"]); 94 1 : BOOST_CHECK_EQUAL(walletdir, expected_path); 95 1 : } 96 : 97 146 : BOOST_AUTO_TEST_SUITE_END() 98 : } // namespace wallet