Add dumpwallet scripts test
This commit is contained in:
parent
ef0c730220
commit
9e1184dd54
1 changed files with 24 additions and 6 deletions
|
@ -10,13 +10,14 @@ from test_framework.test_framework import BitcoinTestFramework
|
||||||
from test_framework.util import (assert_equal, assert_raises_rpc_error)
|
from test_framework.util import (assert_equal, assert_raises_rpc_error)
|
||||||
|
|
||||||
|
|
||||||
def read_dump(file_name, addrs, hd_master_addr_old):
|
def read_dump(file_name, addrs, script_addrs, hd_master_addr_old):
|
||||||
"""
|
"""
|
||||||
Read the given dump, count the addrs that match, count change and reserve.
|
Read the given dump, count the addrs that match, count change and reserve.
|
||||||
Also check that the old hd_master is inactive
|
Also check that the old hd_master is inactive
|
||||||
"""
|
"""
|
||||||
with open(file_name, encoding='utf8') as inputfile:
|
with open(file_name, encoding='utf8') as inputfile:
|
||||||
found_addr = 0
|
found_addr = 0
|
||||||
|
found_script_addr = 0
|
||||||
found_addr_chg = 0
|
found_addr_chg = 0
|
||||||
found_addr_rsv = 0
|
found_addr_rsv = 0
|
||||||
hd_master_addr_ret = None
|
hd_master_addr_ret = None
|
||||||
|
@ -38,6 +39,9 @@ def read_dump(file_name, addrs, hd_master_addr_old):
|
||||||
# ensure we have generated a new hd master key
|
# ensure we have generated a new hd master key
|
||||||
assert(hd_master_addr_old != addr)
|
assert(hd_master_addr_old != addr)
|
||||||
hd_master_addr_ret = addr
|
hd_master_addr_ret = addr
|
||||||
|
elif keytype == "script=1":
|
||||||
|
# scripts don't have keypaths
|
||||||
|
keypath = None
|
||||||
else:
|
else:
|
||||||
keypath = addr_keypath.rstrip().split("hdkeypath=")[1]
|
keypath = addr_keypath.rstrip().split("hdkeypath=")[1]
|
||||||
|
|
||||||
|
@ -52,7 +56,14 @@ def read_dump(file_name, addrs, hd_master_addr_old):
|
||||||
elif keytype == "reserve=1":
|
elif keytype == "reserve=1":
|
||||||
found_addr_rsv += 1
|
found_addr_rsv += 1
|
||||||
break
|
break
|
||||||
return found_addr, found_addr_chg, found_addr_rsv, hd_master_addr_ret
|
|
||||||
|
# count scripts
|
||||||
|
for script_addr in script_addrs:
|
||||||
|
if script_addr == addr.rstrip() and keytype == "script=1":
|
||||||
|
found_script_addr += 1
|
||||||
|
break
|
||||||
|
|
||||||
|
return found_addr, found_script_addr, found_addr_chg, found_addr_rsv, hd_master_addr_ret
|
||||||
|
|
||||||
|
|
||||||
class WalletDumpTest(BitcoinTestFramework):
|
class WalletDumpTest(BitcoinTestFramework):
|
||||||
|
@ -81,13 +92,19 @@ class WalletDumpTest(BitcoinTestFramework):
|
||||||
# Should be a no-op:
|
# Should be a no-op:
|
||||||
self.nodes[0].keypoolrefill()
|
self.nodes[0].keypoolrefill()
|
||||||
|
|
||||||
|
# Test scripts dump by adding a P2SH witness and a 1-of-1 multisig address
|
||||||
|
witness_addr = self.nodes[0].addwitnessaddress(addrs[0]["address"], True)
|
||||||
|
multisig_addr = self.nodes[0].addmultisigaddress(1, [addrs[1]["address"]])
|
||||||
|
script_addrs = [witness_addr, multisig_addr]
|
||||||
|
|
||||||
# dump unencrypted wallet
|
# dump unencrypted wallet
|
||||||
result = self.nodes[0].dumpwallet(tmpdir + "/node0/wallet.unencrypted.dump")
|
result = self.nodes[0].dumpwallet(tmpdir + "/node0/wallet.unencrypted.dump")
|
||||||
assert_equal(result['filename'], os.path.abspath(tmpdir + "/node0/wallet.unencrypted.dump"))
|
assert_equal(result['filename'], os.path.abspath(tmpdir + "/node0/wallet.unencrypted.dump"))
|
||||||
|
|
||||||
found_addr, found_addr_chg, found_addr_rsv, hd_master_addr_unenc = \
|
found_addr, found_script_addr, found_addr_chg, found_addr_rsv, hd_master_addr_unenc = \
|
||||||
read_dump(tmpdir + "/node0/wallet.unencrypted.dump", addrs, None)
|
read_dump(tmpdir + "/node0/wallet.unencrypted.dump", addrs, script_addrs, None)
|
||||||
assert_equal(found_addr, test_addr_count) # all keys must be in the dump
|
assert_equal(found_addr, test_addr_count) # all keys must be in the dump
|
||||||
|
assert_equal(found_script_addr, 2) # all scripts must be in the dump
|
||||||
assert_equal(found_addr_chg, 50) # 50 blocks where mined
|
assert_equal(found_addr_chg, 50) # 50 blocks where mined
|
||||||
assert_equal(found_addr_rsv, 90*2) # 90 keys plus 100% internal keys
|
assert_equal(found_addr_rsv, 90*2) # 90 keys plus 100% internal keys
|
||||||
|
|
||||||
|
@ -99,9 +116,10 @@ class WalletDumpTest(BitcoinTestFramework):
|
||||||
self.nodes[0].keypoolrefill()
|
self.nodes[0].keypoolrefill()
|
||||||
self.nodes[0].dumpwallet(tmpdir + "/node0/wallet.encrypted.dump")
|
self.nodes[0].dumpwallet(tmpdir + "/node0/wallet.encrypted.dump")
|
||||||
|
|
||||||
found_addr, found_addr_chg, found_addr_rsv, _ = \
|
found_addr, found_script_addr, found_addr_chg, found_addr_rsv, _ = \
|
||||||
read_dump(tmpdir + "/node0/wallet.encrypted.dump", addrs, hd_master_addr_unenc)
|
read_dump(tmpdir + "/node0/wallet.encrypted.dump", addrs, script_addrs, hd_master_addr_unenc)
|
||||||
assert_equal(found_addr, test_addr_count)
|
assert_equal(found_addr, test_addr_count)
|
||||||
|
assert_equal(found_script_addr, 2)
|
||||||
assert_equal(found_addr_chg, 90*2 + 50) # old reserve keys are marked as change now
|
assert_equal(found_addr_chg, 90*2 + 50) # old reserve keys are marked as change now
|
||||||
assert_equal(found_addr_rsv, 90*2)
|
assert_equal(found_addr_rsv, 90*2)
|
||||||
|
|
||||||
|
|
Loading…
Reference in a new issue