Skip to content

Commit 9e1184d

Browse files
committed
Add dumpwallet scripts test
1 parent ef0c730 commit 9e1184d

File tree

1 file changed

+24
-6
lines changed

1 file changed

+24
-6
lines changed

test/functional/wallet-dump.py

Lines changed: 24 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -10,13 +10,14 @@
1010
from test_framework.util import (assert_equal, assert_raises_rpc_error)
1111

1212

13-
def read_dump(file_name, addrs, hd_master_addr_old):
13+
def read_dump(file_name, addrs, script_addrs, hd_master_addr_old):
1414
"""
1515
Read the given dump, count the addrs that match, count change and reserve.
1616
Also check that the old hd_master is inactive
1717
"""
1818
with open(file_name, encoding='utf8') as inputfile:
1919
found_addr = 0
20+
found_script_addr = 0
2021
found_addr_chg = 0
2122
found_addr_rsv = 0
2223
hd_master_addr_ret = None
@@ -38,6 +39,9 @@ def read_dump(file_name, addrs, hd_master_addr_old):
3839
# ensure we have generated a new hd master key
3940
assert(hd_master_addr_old != addr)
4041
hd_master_addr_ret = addr
42+
elif keytype == "script=1":
43+
# scripts don't have keypaths
44+
keypath = None
4145
else:
4246
keypath = addr_keypath.rstrip().split("hdkeypath=")[1]
4347

@@ -52,7 +56,14 @@ def read_dump(file_name, addrs, hd_master_addr_old):
5256
elif keytype == "reserve=1":
5357
found_addr_rsv += 1
5458
break
55-
return found_addr, found_addr_chg, found_addr_rsv, hd_master_addr_ret
59+
60+
# count scripts
61+
for script_addr in script_addrs:
62+
if script_addr == addr.rstrip() and keytype == "script=1":
63+
found_script_addr += 1
64+
break
65+
66+
return found_addr, found_script_addr, found_addr_chg, found_addr_rsv, hd_master_addr_ret
5667

5768

5869
class WalletDumpTest(BitcoinTestFramework):
@@ -81,13 +92,19 @@ def run_test (self):
8192
# Should be a no-op:
8293
self.nodes[0].keypoolrefill()
8394

95+
# Test scripts dump by adding a P2SH witness and a 1-of-1 multisig address
96+
witness_addr = self.nodes[0].addwitnessaddress(addrs[0]["address"], True)
97+
multisig_addr = self.nodes[0].addmultisigaddress(1, [addrs[1]["address"]])
98+
script_addrs = [witness_addr, multisig_addr]
99+
84100
# dump unencrypted wallet
85101
result = self.nodes[0].dumpwallet(tmpdir + "/node0/wallet.unencrypted.dump")
86102
assert_equal(result['filename'], os.path.abspath(tmpdir + "/node0/wallet.unencrypted.dump"))
87103

88-
found_addr, found_addr_chg, found_addr_rsv, hd_master_addr_unenc = \
89-
read_dump(tmpdir + "/node0/wallet.unencrypted.dump", addrs, None)
104+
found_addr, found_script_addr, found_addr_chg, found_addr_rsv, hd_master_addr_unenc = \
105+
read_dump(tmpdir + "/node0/wallet.unencrypted.dump", addrs, script_addrs, None)
90106
assert_equal(found_addr, test_addr_count) # all keys must be in the dump
107+
assert_equal(found_script_addr, 2) # all scripts must be in the dump
91108
assert_equal(found_addr_chg, 50) # 50 blocks where mined
92109
assert_equal(found_addr_rsv, 90*2) # 90 keys plus 100% internal keys
93110

@@ -99,9 +116,10 @@ def run_test (self):
99116
self.nodes[0].keypoolrefill()
100117
self.nodes[0].dumpwallet(tmpdir + "/node0/wallet.encrypted.dump")
101118

102-
found_addr, found_addr_chg, found_addr_rsv, _ = \
103-
read_dump(tmpdir + "/node0/wallet.encrypted.dump", addrs, hd_master_addr_unenc)
119+
found_addr, found_script_addr, found_addr_chg, found_addr_rsv, _ = \
120+
read_dump(tmpdir + "/node0/wallet.encrypted.dump", addrs, script_addrs, hd_master_addr_unenc)
104121
assert_equal(found_addr, test_addr_count)
122+
assert_equal(found_script_addr, 2)
105123
assert_equal(found_addr_chg, 90*2 + 50) # old reserve keys are marked as change now
106124
assert_equal(found_addr_rsv, 90*2)
107125

0 commit comments

Comments
 (0)