forked from zcash/zcash
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathfeature_walletfile.py
executable file
·50 lines (39 loc) · 2.07 KB
/
feature_walletfile.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
#!/usr/bin/env python3
# Copyright (c) 2017 The Bitcoin Core developers
# Distributed under the MIT software license, see the accompanying
# file COPYING or https://www.opensource.org/licenses/mit-license.php .
"""Test wallet file location."""
import os
from test_framework.util import start_node, stop_node, assert_start_raises_init_error
from test_framework.test_framework import BitcoinTestFramework
class WalletFileTest(BitcoinTestFramework):
def set_test_params(self):
self.num_nodes = 1
self.setup_clean_chain = True
def run_test(self):
# test default wallet location
assert os.path.isfile(os.path.join(self.options.tmpdir, "node0", "regtest", "wallet.dat"))
# test alternative wallet file name in datadir
stop_node(self.nodes[0], 0)
self.nodes[0] = start_node(0, self.options.tmpdir, ["-wallet=altwallet.dat"])
assert os.path.isfile(os.path.join(self.options.tmpdir, "node0", "regtest", "altwallet.dat"))
# test wallet file outside datadir
tempname = os.path.join(self.options.tmpdir, "outsidewallet.dat")
stop_node(self.nodes[0], 0)
self.nodes[0] = start_node(0, self.options.tmpdir, ["-wallet=%s" % tempname])
assert os.path.isfile(tempname)
# test the case where absolute path does not exist
assert not os.path.isdir("/this_directory_must_not_exist")
invalidpath = os.path.join("/this_directory_must_not_exist/", "foo.dat")
stop_node(self.nodes[0], 0)
assert_start_raises_init_error(0, "-wallet=%s" % invalidpath,
"Error: Absolute path %s does not exist")
# relative path does not exist
invalidpath = os.path.join("wallet", "foo.dat")
assert_start_raises_init_error(0, "-wallet=%s" % invalidpath,
"Error: Relative path %s does not exist")
# create dir and retry
os.mkdir(os.path.join(self.options.tmpdir, "node0", "regtest", "wallet"))
self.nodes[0] = start_node(0, self.options.tmpdir, ["-wallet=%s" % invalidpath])
if __name__ == '__main__':
WalletFileTest().main()