Skip to content

Commit eeeed51

Browse files
author
MarcoFalke
committed
test: pep-8 wallet_hd
1 parent dec067f commit eeeed51

File tree

1 file changed

+30
-20
lines changed

1 file changed

+30
-20
lines changed

test/functional/wallet_hd.py

Lines changed: 30 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,7 @@
1111
from test_framework.util import (
1212
assert_equal,
1313
connect_nodes,
14-
assert_raises_rpc_error
14+
assert_raises_rpc_error,
1515
)
1616

1717

@@ -32,11 +32,11 @@ def run_test(self):
3232

3333
# create an internal key
3434
change_addr = self.nodes[1].getrawchangeaddress()
35-
change_addrV= self.nodes[1].getaddressinfo(change_addr)
35+
change_addrV = self.nodes[1].getaddressinfo(change_addr)
3636
if self.options.descriptors:
3737
assert_equal(change_addrV["hdkeypath"], "m/84'/1'/0'/1/0")
3838
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
4040

4141
# Import a non-HD private key in the HD wallet
4242
non_hd_add = 'bcrt1qmevj8zfx0wdvp05cqwkmr6mxkfx60yezwjksmt'
@@ -58,7 +58,7 @@ def run_test(self):
5858
if self.options.descriptors:
5959
assert_equal(hd_info["hdkeypath"], "m/84'/1'/0'/0/" + str(i))
6060
else:
61-
assert_equal(hd_info["hdkeypath"], "m/0'/0'/"+str(i)+"'")
61+
assert_equal(hd_info["hdkeypath"], "m/0'/0'/" + str(i) + "'")
6262
assert_equal(hd_info["hdmasterfingerprint"], hd_fingerprint)
6363
self.nodes[0].sendtoaddress(hd_add, 1)
6464
self.nodes[0].generate(1)
@@ -67,11 +67,11 @@ def run_test(self):
6767

6868
# create an internal key (again)
6969
change_addr = self.nodes[1].getrawchangeaddress()
70-
change_addrV= self.nodes[1].getaddressinfo(change_addr)
70+
change_addrV = self.nodes[1].getaddressinfo(change_addr)
7171
if self.options.descriptors:
7272
assert_equal(change_addrV["hdkeypath"], "m/84'/1'/0'/1/1")
7373
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
7575

7676
self.sync_all()
7777
assert_equal(self.nodes[1].getbalance(), NUM_HD_ADDS + 1)
@@ -82,7 +82,10 @@ def run_test(self):
8282
# otherwise node1 would auto-recover all funds in flag the keypool keys as used
8383
shutil.rmtree(os.path.join(self.nodes[1].datadir, self.chain, "blocks"))
8484
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+
)
8689
self.start_node(1)
8790

8891
# Assert that derivation is deterministic
@@ -93,7 +96,7 @@ def run_test(self):
9396
if self.options.descriptors:
9497
assert_equal(hd_info_2["hdkeypath"], "m/84'/1'/0'/0/" + str(i))
9598
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) + "'")
97100
assert_equal(hd_info_2["hdmasterfingerprint"], hd_fingerprint)
98101
assert_equal(hd_add, hd_add_2)
99102
connect_nodes(self.nodes[0], 1)
@@ -108,7 +111,10 @@ def run_test(self):
108111
self.stop_node(1)
109112
shutil.rmtree(os.path.join(self.nodes[1].datadir, self.chain, "blocks"))
110113
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+
)
112118
self.start_node(1, extra_args=self.extra_args[1])
113119
connect_nodes(self.nodes[0], 1)
114120
self.sync_all()
@@ -142,8 +148,9 @@ def run_test(self):
142148
new_masterkeyid = self.nodes[1].getwalletinfo()['hdseedid']
143149
assert orig_masterkeyid != new_masterkeyid
144150
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
147154

148155
# Set a new HD seed on node 1 without flushing the keypool
149156
new_seed = self.nodes[0].dumpprivkey(self.nodes[0].getnewaddress())
@@ -153,13 +160,15 @@ def run_test(self):
153160
assert orig_masterkeyid != new_masterkeyid
154161
addr = self.nodes[1].getnewaddress()
155162
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\'')
157165

158166
# Check that the next address is from the new seed
159167
self.nodes[1].keypoolrefill(1)
160168
next_addr = self.nodes[1].getnewaddress()
161169
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\'')
163172
assert next_addr != addr
164173

165174
# Sethdseed parameter validity
@@ -185,13 +194,13 @@ def run_test(self):
185194

186195
self.nodes[1].createwallet(wallet_name='restore', blank=True)
187196
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
190199

191200
self.nodes[1].createwallet(wallet_name='restore2', blank=True)
192201
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
195204

196205
# Check persistence of inactive seed by reloading restore. restore2 is still loaded to test the case where the wallet is not reloaded
197206
restore_rpc.unloadwallet()
@@ -201,8 +210,8 @@ def run_test(self):
201210
# Empty origin keypool and get an address that is beyond the initial keypool
202211
origin_rpc.getnewaddress()
203212
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
206215

207216
# Check that the restored seed has last_addr but does not have addr
208217
info = restore_rpc.getaddressinfo(last_addr)
@@ -266,5 +275,6 @@ def run_test(self):
266275
info = restore2_rpc.getaddressinfo(addr)
267276
assert_equal(info['ismine'], False)
268277

278+
269279
if __name__ == '__main__':
270-
WalletHDTest().main ()
280+
WalletHDTest().main()

0 commit comments

Comments
 (0)