@@ -17,69 +17,75 @@ def set_test_params(self):
17
17
self .setup_clean_chain = True
18
18
self .num_nodes = 1
19
19
self .extra_args = [['-wallet=w1' , '-wallet=w2' , '-wallet=w3' , '-wallet=w' ]]
20
+ self .supports_cli = True
20
21
21
22
def run_test (self ):
22
- assert_equal (set (self .nodes [0 ].listwallets ()), {"w1" , "w2" , "w3" , "w" })
23
+ node = self .nodes [0 ]
24
+
25
+ data_dir = lambda * p : os .path .join (node .datadir , 'regtest' , * p )
26
+ wallet_dir = lambda * p : data_dir ('wallets' , * p )
27
+ wallet = lambda name : node .get_wallet_rpc (name )
28
+
29
+ assert_equal (set (node .listwallets ()), {"w1" , "w2" , "w3" , "w" })
23
30
24
31
self .stop_node (0 )
25
32
26
33
# should not initialize if there are duplicate wallets
27
34
self .assert_start_raises_init_error (0 , ['-wallet=w1' , '-wallet=w1' ], 'Error loading wallet w1. Duplicate -wallet filename specified.' )
28
35
29
36
# should not initialize if wallet file is a directory
30
- wallet_dir = os .path .join (self .options .tmpdir , 'node0' , 'regtest' , 'wallets' )
31
- os .mkdir (os .path .join (wallet_dir , 'w11' ))
37
+ os .mkdir (wallet_dir ('w11' ))
32
38
self .assert_start_raises_init_error (0 , ['-wallet=w11' ], 'Error loading wallet w11. -wallet filename must be a regular file.' )
33
39
34
40
# should not initialize if one wallet is a copy of another
35
- shutil .copyfile (os . path . join ( wallet_dir , 'w2' ), os . path . join ( wallet_dir , 'w22' ))
41
+ shutil .copyfile (wallet_dir ( 'w2' ), wallet_dir ( 'w22' ))
36
42
self .assert_start_raises_init_error (0 , ['-wallet=w2' , '-wallet=w22' ], 'duplicates fileid' )
37
43
38
44
# should not initialize if wallet file is a symlink
39
- os .symlink (os . path . join ( wallet_dir , 'w1' ), os . path . join ( wallet_dir , 'w12' ))
45
+ os .symlink (wallet_dir ( 'w1' ), wallet_dir ( 'w12' ))
40
46
self .assert_start_raises_init_error (0 , ['-wallet=w12' ], 'Error loading wallet w12. -wallet filename must be a regular file.' )
41
47
42
48
# should not initialize if the specified walletdir does not exist
43
49
self .assert_start_raises_init_error (0 , ['-walletdir=bad' ], 'Error: Specified -walletdir "bad" does not exist' )
44
50
# should not initialize if the specified walletdir is not a directory
45
- not_a_dir = os . path . join ( wallet_dir , 'notadir' )
51
+ not_a_dir = wallet_dir ( 'notadir' )
46
52
open (not_a_dir , 'a' ).close ()
47
- self .assert_start_raises_init_error (0 , ['-walletdir=' + not_a_dir ], 'Error: Specified -walletdir "' + not_a_dir + '" is not a directory' )
53
+ self .assert_start_raises_init_error (0 , ['-walletdir=' + not_a_dir ], 'Error: Specified -walletdir "' + not_a_dir + '" is not a directory' )
48
54
49
55
# if wallets/ doesn't exist, datadir should be the default wallet dir
50
- wallet_dir2 = os . path . join ( self . options . tmpdir , 'node0' , 'regtest' , 'walletdir' )
51
- os .rename (wallet_dir , wallet_dir2 )
56
+ wallet_dir2 = data_dir ( 'walletdir' )
57
+ os .rename (wallet_dir () , wallet_dir2 )
52
58
self .start_node (0 , ['-wallet=w4' , '-wallet=w5' ])
53
- assert_equal (set (self . nodes [ 0 ] .listwallets ()), {"w4" , "w5" })
54
- w5 = self . nodes [ 0 ]. get_wallet_rpc ("w5" )
59
+ assert_equal (set (node .listwallets ()), {"w4" , "w5" })
60
+ w5 = wallet ("w5" )
55
61
w5 .generate (1 )
56
62
self .stop_node (0 )
57
63
58
64
# now if wallets/ exists again, but the rootdir is specified as the walletdir, w4 and w5 should still be loaded
59
- os .rename (wallet_dir2 , wallet_dir )
60
- self .start_node (0 , ['-wallet=w4' , '-wallet=w5' , '-walletdir=' + os . path . join ( self . options . tmpdir , 'node0' , 'regtest' )])
61
- assert_equal (set (self . nodes [ 0 ] .listwallets ()), {"w4" , "w5" })
62
- w5 = self . nodes [ 0 ]. get_wallet_rpc ("w5" )
65
+ os .rename (wallet_dir2 , wallet_dir () )
66
+ self .start_node (0 , ['-wallet=w4' , '-wallet=w5' , '-walletdir=' + data_dir ( )])
67
+ assert_equal (set (node .listwallets ()), {"w4" , "w5" })
68
+ w5 = wallet ("w5" )
63
69
w5_info = w5 .getwalletinfo ()
64
70
assert_equal (w5_info ['immature_balance' ], 50 )
65
71
66
72
self .stop_node (0 )
67
73
68
74
self .start_node (0 , self .extra_args [0 ])
69
75
70
- w1 = self . nodes [ 0 ]. get_wallet_rpc ("w1" )
71
- w2 = self . nodes [ 0 ]. get_wallet_rpc ("w2" )
72
- w3 = self . nodes [ 0 ]. get_wallet_rpc ("w3" )
73
- w4 = self . nodes [ 0 ]. get_wallet_rpc ("w" )
74
- wallet_bad = self . nodes [ 0 ]. get_wallet_rpc ("bad" )
76
+ w1 = wallet ("w1" )
77
+ w2 = wallet ("w2" )
78
+ w3 = wallet ("w3" )
79
+ w4 = wallet ("w" )
80
+ wallet_bad = wallet ("bad" )
75
81
76
82
w1 .generate (1 )
77
83
78
84
# accessing invalid wallet fails
79
85
assert_raises_rpc_error (- 18 , "Requested wallet does not exist or is not loaded" , wallet_bad .getwalletinfo )
80
86
81
87
# accessing wallet RPC without using wallet endpoint fails
82
- assert_raises_rpc_error (- 19 , "Wallet file not specified" , self . nodes [ 0 ] .getwalletinfo )
88
+ assert_raises_rpc_error (- 19 , "Wallet file not specified" , node .getwalletinfo )
83
89
84
90
# check w1 wallet balance
85
91
w1_info = w1 .getwalletinfo ()
0 commit comments