mirror of
https://github.com/bitcoin/bitcoin.git
synced 2025-02-09 10:43:19 -05:00
test: pep-8 wallet_hd
This commit is contained in:
parent
dec067f5a0
commit
eeeed51f58
1 changed files with 30 additions and 20 deletions
|
@ -11,7 +11,7 @@ from test_framework.test_framework import BitcoinTestFramework
|
|||
from test_framework.util import (
|
||||
assert_equal,
|
||||
connect_nodes,
|
||||
assert_raises_rpc_error
|
||||
assert_raises_rpc_error,
|
||||
)
|
||||
|
||||
|
||||
|
@ -32,7 +32,7 @@ class WalletHDTest(BitcoinTestFramework):
|
|||
|
||||
# create an internal key
|
||||
change_addr = self.nodes[1].getrawchangeaddress()
|
||||
change_addrV= self.nodes[1].getaddressinfo(change_addr)
|
||||
change_addrV = self.nodes[1].getaddressinfo(change_addr)
|
||||
if self.options.descriptors:
|
||||
assert_equal(change_addrV["hdkeypath"], "m/84'/1'/0'/1/0")
|
||||
else:
|
||||
|
@ -58,7 +58,7 @@ class WalletHDTest(BitcoinTestFramework):
|
|||
if self.options.descriptors:
|
||||
assert_equal(hd_info["hdkeypath"], "m/84'/1'/0'/0/" + str(i))
|
||||
else:
|
||||
assert_equal(hd_info["hdkeypath"], "m/0'/0'/"+str(i)+"'")
|
||||
assert_equal(hd_info["hdkeypath"], "m/0'/0'/" + str(i) + "'")
|
||||
assert_equal(hd_info["hdmasterfingerprint"], hd_fingerprint)
|
||||
self.nodes[0].sendtoaddress(hd_add, 1)
|
||||
self.nodes[0].generate(1)
|
||||
|
@ -67,7 +67,7 @@ class WalletHDTest(BitcoinTestFramework):
|
|||
|
||||
# create an internal key (again)
|
||||
change_addr = self.nodes[1].getrawchangeaddress()
|
||||
change_addrV= self.nodes[1].getaddressinfo(change_addr)
|
||||
change_addrV = self.nodes[1].getaddressinfo(change_addr)
|
||||
if self.options.descriptors:
|
||||
assert_equal(change_addrV["hdkeypath"], "m/84'/1'/0'/1/1")
|
||||
else:
|
||||
|
@ -82,7 +82,10 @@ class WalletHDTest(BitcoinTestFramework):
|
|||
# otherwise node1 would auto-recover all funds in flag the keypool keys as used
|
||||
shutil.rmtree(os.path.join(self.nodes[1].datadir, self.chain, "blocks"))
|
||||
shutil.rmtree(os.path.join(self.nodes[1].datadir, self.chain, "chainstate"))
|
||||
shutil.copyfile(os.path.join(self.nodes[1].datadir, "hd.bak"), os.path.join(self.nodes[1].datadir, self.chain, 'wallets', "wallet.dat"))
|
||||
shutil.copyfile(
|
||||
os.path.join(self.nodes[1].datadir, "hd.bak"),
|
||||
os.path.join(self.nodes[1].datadir, self.chain, 'wallets', "wallet.dat"),
|
||||
)
|
||||
self.start_node(1)
|
||||
|
||||
# Assert that derivation is deterministic
|
||||
|
@ -93,7 +96,7 @@ class WalletHDTest(BitcoinTestFramework):
|
|||
if self.options.descriptors:
|
||||
assert_equal(hd_info_2["hdkeypath"], "m/84'/1'/0'/0/" + str(i))
|
||||
else:
|
||||
assert_equal(hd_info_2["hdkeypath"], "m/0'/0'/"+str(i)+"'")
|
||||
assert_equal(hd_info_2["hdkeypath"], "m/0'/0'/" + str(i) + "'")
|
||||
assert_equal(hd_info_2["hdmasterfingerprint"], hd_fingerprint)
|
||||
assert_equal(hd_add, hd_add_2)
|
||||
connect_nodes(self.nodes[0], 1)
|
||||
|
@ -108,7 +111,10 @@ class WalletHDTest(BitcoinTestFramework):
|
|||
self.stop_node(1)
|
||||
shutil.rmtree(os.path.join(self.nodes[1].datadir, self.chain, "blocks"))
|
||||
shutil.rmtree(os.path.join(self.nodes[1].datadir, self.chain, "chainstate"))
|
||||
shutil.copyfile(os.path.join(self.nodes[1].datadir, "hd.bak"), os.path.join(self.nodes[1].datadir, self.chain, "wallets", "wallet.dat"))
|
||||
shutil.copyfile(
|
||||
os.path.join(self.nodes[1].datadir, "hd.bak"),
|
||||
os.path.join(self.nodes[1].datadir, self.chain, "wallets", "wallet.dat"),
|
||||
)
|
||||
self.start_node(1, extra_args=self.extra_args[1])
|
||||
connect_nodes(self.nodes[0], 1)
|
||||
self.sync_all()
|
||||
|
@ -142,7 +148,8 @@ class WalletHDTest(BitcoinTestFramework):
|
|||
new_masterkeyid = self.nodes[1].getwalletinfo()['hdseedid']
|
||||
assert orig_masterkeyid != new_masterkeyid
|
||||
addr = self.nodes[1].getnewaddress()
|
||||
assert_equal(self.nodes[1].getaddressinfo(addr)['hdkeypath'], 'm/0\'/0\'/0\'') # Make sure the new address is the first from the keypool
|
||||
# Make sure the new address is the first from the keypool
|
||||
assert_equal(self.nodes[1].getaddressinfo(addr)['hdkeypath'], 'm/0\'/0\'/0\'')
|
||||
self.nodes[1].keypoolrefill(1) # Fill keypool with 1 key
|
||||
|
||||
# Set a new HD seed on node 1 without flushing the keypool
|
||||
|
@ -153,13 +160,15 @@ class WalletHDTest(BitcoinTestFramework):
|
|||
assert orig_masterkeyid != new_masterkeyid
|
||||
addr = self.nodes[1].getnewaddress()
|
||||
assert_equal(orig_masterkeyid, self.nodes[1].getaddressinfo(addr)['hdseedid'])
|
||||
assert_equal(self.nodes[1].getaddressinfo(addr)['hdkeypath'], 'm/0\'/0\'/1\'') # Make sure the new address continues previous keypool
|
||||
# Make sure the new address continues previous keypool
|
||||
assert_equal(self.nodes[1].getaddressinfo(addr)['hdkeypath'], 'm/0\'/0\'/1\'')
|
||||
|
||||
# Check that the next address is from the new seed
|
||||
self.nodes[1].keypoolrefill(1)
|
||||
next_addr = self.nodes[1].getnewaddress()
|
||||
assert_equal(new_masterkeyid, self.nodes[1].getaddressinfo(next_addr)['hdseedid'])
|
||||
assert_equal(self.nodes[1].getaddressinfo(next_addr)['hdkeypath'], 'm/0\'/0\'/0\'') # Make sure the new address is not from previous keypool
|
||||
# Make sure the new address is not from previous keypool
|
||||
assert_equal(self.nodes[1].getaddressinfo(next_addr)['hdkeypath'], 'm/0\'/0\'/0\'')
|
||||
assert next_addr != addr
|
||||
|
||||
# Sethdseed parameter validity
|
||||
|
@ -266,5 +275,6 @@ class WalletHDTest(BitcoinTestFramework):
|
|||
info = restore2_rpc.getaddressinfo(addr)
|
||||
assert_equal(info['ismine'], False)
|
||||
|
||||
|
||||
if __name__ == '__main__':
|
||||
WalletHDTest().main ()
|
||||
WalletHDTest().main()
|
||||
|
|
Loading…
Add table
Reference in a new issue