10
10
from test_framework .util import (assert_equal , assert_raises_rpc_error )
11
11
12
12
13
- def read_dump (file_name , addrs , hd_master_addr_old ):
13
+ def read_dump (file_name , addrs , script_addrs , hd_master_addr_old ):
14
14
"""
15
15
Read the given dump, count the addrs that match, count change and reserve.
16
16
Also check that the old hd_master is inactive
17
17
"""
18
18
with open (file_name , encoding = 'utf8' ) as inputfile :
19
19
found_addr = 0
20
+ found_script_addr = 0
20
21
found_addr_chg = 0
21
22
found_addr_rsv = 0
22
23
hd_master_addr_ret = None
@@ -38,6 +39,9 @@ def read_dump(file_name, addrs, hd_master_addr_old):
38
39
# ensure we have generated a new hd master key
39
40
assert (hd_master_addr_old != addr )
40
41
hd_master_addr_ret = addr
42
+ elif keytype == "script=1" :
43
+ # scripts don't have keypaths
44
+ keypath = None
41
45
else :
42
46
keypath = addr_keypath .rstrip ().split ("hdkeypath=" )[1 ]
43
47
@@ -52,7 +56,14 @@ def read_dump(file_name, addrs, hd_master_addr_old):
52
56
elif keytype == "reserve=1" :
53
57
found_addr_rsv += 1
54
58
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
56
67
57
68
58
69
class WalletDumpTest (BitcoinTestFramework ):
@@ -81,13 +92,19 @@ def run_test (self):
81
92
# Should be a no-op:
82
93
self .nodes [0 ].keypoolrefill ()
83
94
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
+
84
100
# dump unencrypted wallet
85
101
result = self .nodes [0 ].dumpwallet (tmpdir + "/node0/wallet.unencrypted.dump" )
86
102
assert_equal (result ['filename' ], os .path .abspath (tmpdir + "/node0/wallet.unencrypted.dump" ))
87
103
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 )
90
106
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
91
108
assert_equal (found_addr_chg , 50 ) # 50 blocks where mined
92
109
assert_equal (found_addr_rsv , 90 * 2 ) # 90 keys plus 100% internal keys
93
110
@@ -99,9 +116,10 @@ def run_test (self):
99
116
self .nodes [0 ].keypoolrefill ()
100
117
self .nodes [0 ].dumpwallet (tmpdir + "/node0/wallet.encrypted.dump" )
101
118
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 )
104
121
assert_equal (found_addr , test_addr_count )
122
+ assert_equal (found_script_addr , 2 )
105
123
assert_equal (found_addr_chg , 90 * 2 + 50 ) # old reserve keys are marked as change now
106
124
assert_equal (found_addr_rsv , 90 * 2 )
107
125
0 commit comments