@@ -29,50 +29,54 @@ def read_dump(file_name, addrs, script_addrs, hd_master_addr_old):
2929 # only read non comment lines
3030 if line [0 ] != "#" and len (line ) > 10 :
3131 # split out some data
32- key_label , comment = line .split ("#" )
33- # key = key_label.split(" ")[0]
34- keytype = key_label .split (" " )[2 ]
35- if len (comment ) > 1 :
36- addr_keypath = comment .split (" addr=" )[1 ]
37- addr = addr_keypath .split (" " )[0 ]
32+ key_date_label , comment = line .split ("#" )
33+ key_date_label = key_date_label .split (" " )
34+ # key = key_date_label[0]
35+ date = key_date_label [1 ]
36+ keytype = key_date_label [2 ]
37+ if not len (comment ) or date .startswith ('1970' ):
38+ continue
39+
40+ addr_keypath = comment .split (" addr=" )[1 ]
41+ addr = addr_keypath .split (" " )[0 ]
42+ keypath = None
43+ if keytype == "inactivehdseed=1" :
44+ # ensure the old master is still available
45+ assert (hd_master_addr_old == addr )
46+ elif keytype == "hdseed=1" :
47+ # ensure we have generated a new hd master key
48+ assert (hd_master_addr_old != addr )
49+ hd_master_addr_ret = addr
50+ elif keytype == "script=1" :
51+ # scripts don't have keypaths
3852 keypath = None
39- if keytype == "inactivehdseed=1" :
40- # ensure the old master is still available
41- assert (hd_master_addr_old == addr )
42- elif keytype == "hdseed=1" :
43- # ensure we have generated a new hd master key
44- assert (hd_master_addr_old != addr )
45- hd_master_addr_ret = addr
46- elif keytype == "script=1" :
47- # scripts don't have keypaths
48- keypath = None
49- else :
50- keypath = addr_keypath .rstrip ().split ("hdkeypath=" )[1 ]
51-
52- # count key types
53- for addrObj in addrs :
54- if addrObj ['address' ] == addr .split ("," )[0 ] and addrObj ['hdkeypath' ] == keypath and keytype == "label=" :
55- # a labeled entry in the wallet should contain both a native address
56- # and the p2sh-p2wpkh address that was added at wallet setup
57- if len (addr .split ("," )) == 2 :
58- addr_list = addr .split ("," )
59- # the entry should be of the first key in the wallet
60- assert_equal (addrs [0 ]['address' ], addr_list [0 ])
61- witness_addr_ret = addr_list [1 ]
62- found_addr += 1
63- break
64- elif keytype == "change=1" :
65- found_addr_chg += 1
66- break
67- elif keytype == "reserve=1" :
68- found_addr_rsv += 1
69- break
70-
71- # count scripts
72- for script_addr in script_addrs :
73- if script_addr == addr .rstrip () and keytype == "script=1" :
74- found_script_addr += 1
75- break
53+ else :
54+ keypath = addr_keypath .rstrip ().split ("hdkeypath=" )[1 ]
55+
56+ # count key types
57+ for addrObj in addrs :
58+ if addrObj ['address' ] == addr .split ("," )[0 ] and addrObj ['hdkeypath' ] == keypath and keytype == "label=" :
59+ # a labeled entry in the wallet should contain both a native address
60+ # and the p2sh-p2wpkh address that was added at wallet setup
61+ if len (addr .split ("," )) == 2 :
62+ addr_list = addr .split ("," )
63+ # the entry should be of the first key in the wallet
64+ assert_equal (addrs [0 ]['address' ], addr_list [0 ])
65+ witness_addr_ret = addr_list [1 ]
66+ found_addr += 1
67+ break
68+ elif keytype == "change=1" :
69+ found_addr_chg += 1
70+ break
71+ elif keytype == "reserve=1" :
72+ found_addr_rsv += 1
73+ break
74+
75+ # count scripts
76+ for script_addr in script_addrs :
77+ if script_addr == addr .rstrip () and keytype == "script=1" :
78+ found_script_addr += 1
79+ break
7680
7781 return found_addr , found_script_addr , found_addr_chg , found_addr_rsv , hd_master_addr_ret , witness_addr_ret
7882
@@ -116,9 +120,9 @@ def run_test(self):
116120 read_dump (wallet_unenc_dump , addrs , script_addrs , None )
117121 assert_equal (found_addr , test_addr_count ) # all keys must be in the dump
118122 assert_equal (found_script_addr , 2 ) # all scripts must be in the dump
119- assert_equal (found_addr_chg , 50 ) # 50 blocks where mined
120- assert_equal (found_addr_rsv , 90 * 2 ) # 90 keys plus 100% internal keys
121- assert_equal (witness_addr_ret , witness_addr ) # p2sh-p2wsh address added to the first key
123+ assert_equal (found_addr_chg , 0 ) # 0 blocks where mined
124+ assert_equal (found_addr_rsv , 90 * 2 ) # 90 keys plus 100% internal keys
125+ assert_equal (witness_addr_ret , witness_addr ) # p2sh-p2wsh address added to the first key
122126
123127 #encrypt wallet, restart, unlock and dump
124128 self .nodes [0 ].node_encrypt_wallet ('test' )
@@ -132,8 +136,8 @@ def run_test(self):
132136 read_dump (wallet_enc_dump , addrs , script_addrs , hd_master_addr_unenc )
133137 assert_equal (found_addr , test_addr_count )
134138 assert_equal (found_script_addr , 2 )
135- assert_equal (found_addr_chg , 90 * 2 + 50 ) # old reserve keys are marked as change now
136- assert_equal (found_addr_rsv , 90 * 2 )
139+ assert_equal (found_addr_chg , 90 * 2 ) # old reserve keys are marked as change now
140+ assert_equal (found_addr_rsv , 90 * 2 )
137141 assert_equal (witness_addr_ret , witness_addr )
138142
139143 # Overwriting should fail
0 commit comments