2424class KeypoolRestoreTest (BitcoinTestFramework ):
2525 def set_test_params (self ):
2626 self .setup_clean_chain = True
27- self .num_nodes = 2
28- self .extra_args = [[], ['-keypool=100' ]]
27+ self .num_nodes = 4
28+ self .extra_args = [[], ['-keypool=100' ], [ '-keypool=100' ], [ '-keypool=100' ] ]
2929
3030 def skip_test_if_missing_module (self ):
3131 self .skip_if_no_wallet ()
@@ -40,32 +40,47 @@ def run_test(self):
4040 shutil .copyfile (wallet_path , wallet_backup_path )
4141 self .start_node (1 , self .extra_args [1 ])
4242 connect_nodes_bi (self .nodes , 0 , 1 )
43+ connect_nodes_bi (self .nodes , 0 , 2 )
44+ connect_nodes_bi (self .nodes , 0 , 3 )
4345
44- self .log .info ("Generate keys for wallet" )
45- for _ in range (90 ):
46- addr_oldpool = self .nodes [1 ].getnewaddress ()
47- for _ in range (20 ):
48- addr_extpool = self .nodes [1 ].getnewaddress ()
46+ for i , output_type in enumerate (["legacy" , "p2sh-segwit" , "bech32" ]):
4947
50- self .log .info ("Send funds to wallet" )
51- self . nodes [ 0 ]. sendtoaddress ( addr_oldpool , 10 )
52- self . nodes [ 0 ]. generate ( 1 )
53- self .nodes [0 ]. sendtoaddress ( addr_extpool , 5 )
54- self . nodes [ 0 ]. generate ( 1 )
55- sync_blocks ( self .nodes )
48+ self .log .info ("Generate keys for wallet with address type: {}" . format ( output_type ) )
49+ idx = i + 1
50+ for _ in range ( 90 ):
51+ addr_oldpool = self .nodes [idx ]. getnewaddress ( address_type = output_type )
52+ for _ in range ( 20 ):
53+ addr_extpool = self .nodes [ idx ]. getnewaddress ( address_type = output_type )
5654
57- self .log .info ("Restart node with wallet backup" )
58- self .stop_node (1 )
59- shutil .copyfile (wallet_backup_path , wallet_path )
60- self .start_node (1 , self .extra_args [1 ])
61- connect_nodes_bi (self .nodes , 0 , 1 )
62- self .sync_all ()
55+ # Make sure we're creating the outputs we expect
56+ address_details = self .nodes [idx ].validateaddress (addr_extpool )
57+ if i == 0 :
58+ assert (not address_details ["isscript" ] and not address_details ["iswitness" ])
59+ elif i == 1 :
60+ assert (address_details ["isscript" ] and not address_details ["iswitness" ])
61+ else :
62+ assert (not address_details ["isscript" ] and address_details ["iswitness" ])
63+
64+
65+ self .log .info ("Send funds to wallet" )
66+ self .nodes [0 ].sendtoaddress (addr_oldpool , 10 )
67+ self .nodes [0 ].generate (1 )
68+ self .nodes [0 ].sendtoaddress (addr_extpool , 5 )
69+ self .nodes [0 ].generate (1 )
70+ sync_blocks (self .nodes )
71+
72+ self .log .info ("Restart node with wallet backup" )
73+ self .stop_node (idx )
74+ shutil .copyfile (wallet_backup_path , wallet_path )
75+ self .start_node (idx , self .extra_args [idx ])
76+ connect_nodes_bi (self .nodes , 0 , idx )
77+ self .sync_all ()
6378
64- self .log .info ("Verify keypool is restored and balance is correct" )
65- assert_equal (self .nodes [1 ].getbalance (), 15 )
66- assert_equal (self .nodes [1 ].listtransactions ()[0 ]['category' ], "receive" )
67- # Check that we have marked all keys up to the used keypool key as used
68- assert_equal (self .nodes [1 ].getaddressinfo (self .nodes [1 ].getnewaddress ())['hdkeypath' ], "m/0'/0'/110'" )
79+ self .log .info ("Verify keypool is restored and balance is correct" )
80+ assert_equal (self .nodes [idx ].getbalance (), 15 )
81+ assert_equal (self .nodes [idx ].listtransactions ()[0 ]['category' ], "receive" )
82+ # Check that we have marked all keys up to the used keypool key as used
83+ assert_equal (self .nodes [idx ].getaddressinfo (self .nodes [idx ].getnewaddress ())['hdkeypath' ], "m/0'/0'/110'" )
6984
7085
7186if __name__ == '__main__' :
0 commit comments