@@ -20,6 +20,7 @@ def read_dump(file_name, addrs, script_addrs, hd_master_addr_old):
20
20
found_script_addr = 0
21
21
found_addr_chg = 0
22
22
found_addr_rsv = 0
23
+ witness_addr_ret = None
23
24
hd_master_addr_ret = None
24
25
for line in inputfile :
25
26
# only read non comment lines
@@ -47,7 +48,14 @@ def read_dump(file_name, addrs, script_addrs, hd_master_addr_old):
47
48
48
49
# count key types
49
50
for addrObj in addrs :
50
- if addrObj ['address' ] == addr and addrObj ['hdkeypath' ] == keypath and keytype == "label=" :
51
+ if addrObj ['address' ] == addr .split ("," )[0 ] and addrObj ['hdkeypath' ] == keypath and keytype == "label=" :
52
+ # a labled entry in the wallet should contain both a native address
53
+ # and the p2sh-p2wpkh address that was added at wallet setup
54
+ if len (addr .split ("," )) == 2 :
55
+ addr_list = addr .split ("," )
56
+ # the entry should be of the first key in the wallet
57
+ assert_equal (addrs [0 ]['address' ], addr_list [0 ])
58
+ witness_addr_ret = addr_list [1 ]
51
59
found_addr += 1
52
60
break
53
61
elif keytype == "change=1" :
@@ -63,7 +71,7 @@ def read_dump(file_name, addrs, script_addrs, hd_master_addr_old):
63
71
found_script_addr += 1
64
72
break
65
73
66
- return found_addr , found_script_addr , found_addr_chg , found_addr_rsv , hd_master_addr_ret
74
+ return found_addr , found_script_addr , found_addr_chg , found_addr_rsv , hd_master_addr_ret , witness_addr_ret
67
75
68
76
69
77
class WalletDumpTest (BitcoinTestFramework ):
@@ -83,6 +91,8 @@ def run_test (self):
83
91
tmpdir = self .options .tmpdir
84
92
85
93
# generate 20 addresses to compare against the dump
94
+ # but since we add a p2sh-p2wpkh address for the first pubkey in the
95
+ # wallet, we will expect 21 addresses in the dump
86
96
test_addr_count = 20
87
97
addrs = []
88
98
for i in range (0 ,test_addr_count ):
@@ -101,12 +111,13 @@ def run_test (self):
101
111
result = self .nodes [0 ].dumpwallet (tmpdir + "/node0/wallet.unencrypted.dump" )
102
112
assert_equal (result ['filename' ], os .path .abspath (tmpdir + "/node0/wallet.unencrypted.dump" ))
103
113
104
- found_addr , found_script_addr , found_addr_chg , found_addr_rsv , hd_master_addr_unenc = \
114
+ found_addr , found_script_addr , found_addr_chg , found_addr_rsv , hd_master_addr_unenc , witness_addr_ret = \
105
115
read_dump (tmpdir + "/node0/wallet.unencrypted.dump" , addrs , script_addrs , None )
106
116
assert_equal (found_addr , test_addr_count ) # all keys must be in the dump
107
117
assert_equal (found_script_addr , 2 ) # all scripts must be in the dump
108
118
assert_equal (found_addr_chg , 50 ) # 50 blocks where mined
109
119
assert_equal (found_addr_rsv , 90 * 2 ) # 90 keys plus 100% internal keys
120
+ assert_equal (witness_addr_ret , witness_addr ) # p2sh-p2wsh address added to the first key
110
121
111
122
#encrypt wallet, restart, unlock and dump
112
123
self .nodes [0 ].node_encrypt_wallet ('test' )
@@ -116,12 +127,13 @@ def run_test (self):
116
127
self .nodes [0 ].keypoolrefill ()
117
128
self .nodes [0 ].dumpwallet (tmpdir + "/node0/wallet.encrypted.dump" )
118
129
119
- found_addr , found_script_addr , found_addr_chg , found_addr_rsv , _ = \
130
+ found_addr , found_script_addr , found_addr_chg , found_addr_rsv , _ , witness_addr_ret = \
120
131
read_dump (tmpdir + "/node0/wallet.encrypted.dump" , addrs , script_addrs , hd_master_addr_unenc )
121
132
assert_equal (found_addr , test_addr_count )
122
133
assert_equal (found_script_addr , 2 )
123
134
assert_equal (found_addr_chg , 90 * 2 + 50 ) # old reserve keys are marked as change now
124
135
assert_equal (found_addr_rsv , 90 * 2 )
136
+ assert_equal (witness_addr_ret , witness_addr )
125
137
126
138
# Overwriting should fail
127
139
assert_raises_rpc_error (- 8 , "already exists" , self .nodes [0 ].dumpwallet , tmpdir + "/node0/wallet.unencrypted.dump" )
0 commit comments