11
11
from test_framework .util import (
12
12
assert_equal ,
13
13
connect_nodes ,
14
- assert_raises_rpc_error
14
+ assert_raises_rpc_error ,
15
15
)
16
16
17
17
@@ -32,11 +32,11 @@ def run_test(self):
32
32
33
33
# create an internal key
34
34
change_addr = self .nodes [1 ].getrawchangeaddress ()
35
- change_addrV = self .nodes [1 ].getaddressinfo (change_addr )
35
+ change_addrV = self .nodes [1 ].getaddressinfo (change_addr )
36
36
if self .options .descriptors :
37
37
assert_equal (change_addrV ["hdkeypath" ], "m/84'/1'/0'/1/0" )
38
38
else :
39
- assert_equal (change_addrV ["hdkeypath" ], "m/0'/1'/0'" ) #first internal child key
39
+ assert_equal (change_addrV ["hdkeypath" ], "m/0'/1'/0'" ) #first internal child key
40
40
41
41
# Import a non-HD private key in the HD wallet
42
42
non_hd_add = 'bcrt1qmevj8zfx0wdvp05cqwkmr6mxkfx60yezwjksmt'
@@ -58,7 +58,7 @@ def run_test(self):
58
58
if self .options .descriptors :
59
59
assert_equal (hd_info ["hdkeypath" ], "m/84'/1'/0'/0/" + str (i ))
60
60
else :
61
- assert_equal (hd_info ["hdkeypath" ], "m/0'/0'/" + str (i )+ "'" )
61
+ assert_equal (hd_info ["hdkeypath" ], "m/0'/0'/" + str (i ) + "'" )
62
62
assert_equal (hd_info ["hdmasterfingerprint" ], hd_fingerprint )
63
63
self .nodes [0 ].sendtoaddress (hd_add , 1 )
64
64
self .nodes [0 ].generate (1 )
@@ -67,11 +67,11 @@ def run_test(self):
67
67
68
68
# create an internal key (again)
69
69
change_addr = self .nodes [1 ].getrawchangeaddress ()
70
- change_addrV = self .nodes [1 ].getaddressinfo (change_addr )
70
+ change_addrV = self .nodes [1 ].getaddressinfo (change_addr )
71
71
if self .options .descriptors :
72
72
assert_equal (change_addrV ["hdkeypath" ], "m/84'/1'/0'/1/1" )
73
73
else :
74
- assert_equal (change_addrV ["hdkeypath" ], "m/0'/1'/1'" ) #second internal child key
74
+ assert_equal (change_addrV ["hdkeypath" ], "m/0'/1'/1'" ) #second internal child key
75
75
76
76
self .sync_all ()
77
77
assert_equal (self .nodes [1 ].getbalance (), NUM_HD_ADDS + 1 )
@@ -82,7 +82,10 @@ def run_test(self):
82
82
# otherwise node1 would auto-recover all funds in flag the keypool keys as used
83
83
shutil .rmtree (os .path .join (self .nodes [1 ].datadir , self .chain , "blocks" ))
84
84
shutil .rmtree (os .path .join (self .nodes [1 ].datadir , self .chain , "chainstate" ))
85
- shutil .copyfile (os .path .join (self .nodes [1 ].datadir , "hd.bak" ), os .path .join (self .nodes [1 ].datadir , self .chain , 'wallets' , "wallet.dat" ))
85
+ shutil .copyfile (
86
+ os .path .join (self .nodes [1 ].datadir , "hd.bak" ),
87
+ os .path .join (self .nodes [1 ].datadir , self .chain , 'wallets' , "wallet.dat" ),
88
+ )
86
89
self .start_node (1 )
87
90
88
91
# Assert that derivation is deterministic
@@ -93,7 +96,7 @@ def run_test(self):
93
96
if self .options .descriptors :
94
97
assert_equal (hd_info_2 ["hdkeypath" ], "m/84'/1'/0'/0/" + str (i ))
95
98
else :
96
- assert_equal (hd_info_2 ["hdkeypath" ], "m/0'/0'/" + str (i )+ "'" )
99
+ assert_equal (hd_info_2 ["hdkeypath" ], "m/0'/0'/" + str (i ) + "'" )
97
100
assert_equal (hd_info_2 ["hdmasterfingerprint" ], hd_fingerprint )
98
101
assert_equal (hd_add , hd_add_2 )
99
102
connect_nodes (self .nodes [0 ], 1 )
@@ -108,7 +111,10 @@ def run_test(self):
108
111
self .stop_node (1 )
109
112
shutil .rmtree (os .path .join (self .nodes [1 ].datadir , self .chain , "blocks" ))
110
113
shutil .rmtree (os .path .join (self .nodes [1 ].datadir , self .chain , "chainstate" ))
111
- shutil .copyfile (os .path .join (self .nodes [1 ].datadir , "hd.bak" ), os .path .join (self .nodes [1 ].datadir , self .chain , "wallets" , "wallet.dat" ))
114
+ shutil .copyfile (
115
+ os .path .join (self .nodes [1 ].datadir , "hd.bak" ),
116
+ os .path .join (self .nodes [1 ].datadir , self .chain , "wallets" , "wallet.dat" ),
117
+ )
112
118
self .start_node (1 , extra_args = self .extra_args [1 ])
113
119
connect_nodes (self .nodes [0 ], 1 )
114
120
self .sync_all ()
@@ -142,8 +148,9 @@ def run_test(self):
142
148
new_masterkeyid = self .nodes [1 ].getwalletinfo ()['hdseedid' ]
143
149
assert orig_masterkeyid != new_masterkeyid
144
150
addr = self .nodes [1 ].getnewaddress ()
145
- assert_equal (self .nodes [1 ].getaddressinfo (addr )['hdkeypath' ], 'm/0\' /0\' /0\' ' ) # Make sure the new address is the first from the keypool
146
- self .nodes [1 ].keypoolrefill (1 ) # Fill keypool with 1 key
151
+ # Make sure the new address is the first from the keypool
152
+ assert_equal (self .nodes [1 ].getaddressinfo (addr )['hdkeypath' ], 'm/0\' /0\' /0\' ' )
153
+ self .nodes [1 ].keypoolrefill (1 ) # Fill keypool with 1 key
147
154
148
155
# Set a new HD seed on node 1 without flushing the keypool
149
156
new_seed = self .nodes [0 ].dumpprivkey (self .nodes [0 ].getnewaddress ())
@@ -153,13 +160,15 @@ def run_test(self):
153
160
assert orig_masterkeyid != new_masterkeyid
154
161
addr = self .nodes [1 ].getnewaddress ()
155
162
assert_equal (orig_masterkeyid , self .nodes [1 ].getaddressinfo (addr )['hdseedid' ])
156
- assert_equal (self .nodes [1 ].getaddressinfo (addr )['hdkeypath' ], 'm/0\' /0\' /1\' ' ) # Make sure the new address continues previous keypool
163
+ # Make sure the new address continues previous keypool
164
+ assert_equal (self .nodes [1 ].getaddressinfo (addr )['hdkeypath' ], 'm/0\' /0\' /1\' ' )
157
165
158
166
# Check that the next address is from the new seed
159
167
self .nodes [1 ].keypoolrefill (1 )
160
168
next_addr = self .nodes [1 ].getnewaddress ()
161
169
assert_equal (new_masterkeyid , self .nodes [1 ].getaddressinfo (next_addr )['hdseedid' ])
162
- assert_equal (self .nodes [1 ].getaddressinfo (next_addr )['hdkeypath' ], 'm/0\' /0\' /0\' ' ) # Make sure the new address is not from previous keypool
170
+ # Make sure the new address is not from previous keypool
171
+ assert_equal (self .nodes [1 ].getaddressinfo (next_addr )['hdkeypath' ], 'm/0\' /0\' /0\' ' )
163
172
assert next_addr != addr
164
173
165
174
# Sethdseed parameter validity
@@ -185,13 +194,13 @@ def run_test(self):
185
194
186
195
self .nodes [1 ].createwallet (wallet_name = 'restore' , blank = True )
187
196
restore_rpc = self .nodes [1 ].get_wallet_rpc ('restore' )
188
- restore_rpc .sethdseed (True , seed ) # Set to be the same seed as origin_rpc
189
- restore_rpc .sethdseed (True ) # Rotate to a new seed, making original `seed` inactive
197
+ restore_rpc .sethdseed (True , seed ) # Set to be the same seed as origin_rpc
198
+ restore_rpc .sethdseed (True ) # Rotate to a new seed, making original `seed` inactive
190
199
191
200
self .nodes [1 ].createwallet (wallet_name = 'restore2' , blank = True )
192
201
restore2_rpc = self .nodes [1 ].get_wallet_rpc ('restore2' )
193
- restore2_rpc .sethdseed (True , seed ) # Set to be the same seed as origin_rpc
194
- restore2_rpc .sethdseed (True ) # Rotate to a new seed, making original `seed` inactive
202
+ restore2_rpc .sethdseed (True , seed ) # Set to be the same seed as origin_rpc
203
+ restore2_rpc .sethdseed (True ) # Rotate to a new seed, making original `seed` inactive
195
204
196
205
# Check persistence of inactive seed by reloading restore. restore2 is still loaded to test the case where the wallet is not reloaded
197
206
restore_rpc .unloadwallet ()
@@ -201,8 +210,8 @@ def run_test(self):
201
210
# Empty origin keypool and get an address that is beyond the initial keypool
202
211
origin_rpc .getnewaddress ()
203
212
origin_rpc .getnewaddress ()
204
- last_addr = origin_rpc .getnewaddress () # Last address of initial keypool
205
- addr = origin_rpc .getnewaddress () # First address beyond initial keypool
213
+ last_addr = origin_rpc .getnewaddress () # Last address of initial keypool
214
+ addr = origin_rpc .getnewaddress () # First address beyond initial keypool
206
215
207
216
# Check that the restored seed has last_addr but does not have addr
208
217
info = restore_rpc .getaddressinfo (last_addr )
@@ -266,5 +275,6 @@ def run_test(self):
266
275
info = restore2_rpc .getaddressinfo (addr )
267
276
assert_equal (info ['ismine' ], False )
268
277
278
+
269
279
if __name__ == '__main__' :
270
- WalletHDTest ().main ()
280
+ WalletHDTest ().main ()
0 commit comments