4646 assert_greater_than_or_equal ,
4747 assert_raises_rpc_error ,
4848)
49+ from test_framework .wallet import MiniWallet
4950
5051
5152class MempoolPersistTest (BitcoinTestFramework ):
5253 def set_test_params (self ):
5354 self .num_nodes = 3
5455 self .extra_args = [[], ["-persistmempool=0" ], []]
5556
56- def skip_test_if_missing_module (self ):
57- self .skip_if_no_wallet ()
58-
5957 def run_test (self ):
58+ self .mini_wallet = MiniWallet (self .nodes [2 ])
59+ self .mini_wallet .rescan_utxos ()
60+ if self .is_sqlite_compiled ():
61+ self .nodes [2 ].createwallet (
62+ wallet_name = "watch" ,
63+ descriptors = True ,
64+ disable_private_keys = True ,
65+ load_on_startup = False ,
66+ )
67+ wallet_watch = self .nodes [2 ].get_wallet_rpc ("watch" )
68+ assert_equal ([{'success' : True }], wallet_watch .importdescriptors ([{'desc' : self .mini_wallet .get_descriptor (), 'timestamp' : 0 }]))
69+
6070 self .log .debug ("Send 5 transactions from node2 (to its own address)" )
6171 tx_creation_time_lower = int (time .time ())
6272 for _ in range (5 ):
63- last_txid = self .nodes [2 ].sendtoaddress (self .nodes [2 ].getnewaddress (), Decimal ("10" ))
64- node2_balance = self .nodes [2 ].getbalance ()
73+ last_txid = self .mini_wallet .send_self_transfer (from_node = self .nodes [2 ])["txid" ]
74+ if self .is_sqlite_compiled ():
75+ self .nodes [2 ].syncwithvalidationinterfacequeue () # Flush mempool to wallet
76+ node2_balance = wallet_watch .getbalance ()
6577 self .sync_all ()
6678 tx_creation_time_higher = int (time .time ())
6779
@@ -82,16 +94,16 @@ def run_test(self):
8294 assert_equal (total_fee_old , self .nodes [0 ].getmempoolinfo ()['total_fee' ])
8395 assert_equal (total_fee_old , sum (v ['fees' ]['base' ] for k , v in self .nodes [0 ].getrawmempool (verbose = True ).items ()))
8496
85- tx_creation_time = self .nodes [0 ].getmempoolentry (txid = last_txid )['time' ]
97+ last_entry = self .nodes [0 ].getmempoolentry (txid = last_txid )
98+ tx_creation_time = last_entry ['time' ]
8699 assert_greater_than_or_equal (tx_creation_time , tx_creation_time_lower )
87100 assert_greater_than_or_equal (tx_creation_time_higher , tx_creation_time )
88101
89102 # disconnect nodes & make a txn that remains in the unbroadcast set.
90103 self .disconnect_nodes (0 , 1 )
91- assert (len (self .nodes [0 ].getpeerinfo ()) == 0 )
92- assert (len (self .nodes [0 ].p2ps ) == 0 )
93- self .nodes [0 ].sendtoaddress (self .nodes [2 ].getnewaddress (), Decimal ("12" ))
94- self .connect_nodes (0 , 2 )
104+ assert_equal (len (self .nodes [0 ].getpeerinfo ()), 0 )
105+ assert_equal (len (self .nodes [0 ].p2ps ), 0 )
106+ self .mini_wallet .send_self_transfer (from_node = self .nodes [0 ])
95107
96108 self .log .debug ("Stop-start the nodes. Verify that node0 has the transactions in its mempool and node1 does not. Verify that node2 calculates its balance correctly after loading wallet transactions." )
97109 self .stop_nodes ()
@@ -111,17 +123,19 @@ def run_test(self):
111123 fees = self .nodes [0 ].getmempoolentry (txid = last_txid )['fees' ]
112124 assert_equal (fees ['base' ] + Decimal ('0.00001000' ), fees ['modified' ])
113125
114- self .log .debug ('Verify time is loaded correctly' )
115- assert_equal (tx_creation_time , self .nodes [0 ].getmempoolentry (txid = last_txid )[ 'time' ] )
126+ self .log .debug ('Verify all fields are loaded correctly' )
127+ assert_equal (last_entry , self .nodes [0 ].getmempoolentry (txid = last_txid ))
116128
117129 # Verify accounting of mempool transactions after restart is correct
118- self .nodes [2 ].syncwithvalidationinterfacequeue () # Flush mempool to wallet
119- assert_equal (node2_balance , self .nodes [2 ].getbalance ())
130+ if self .is_sqlite_compiled ():
131+ self .nodes [2 ].loadwallet ("watch" )
132+ wallet_watch = self .nodes [2 ].get_wallet_rpc ("watch" )
133+ self .nodes [2 ].syncwithvalidationinterfacequeue () # Flush mempool to wallet
134+ assert_equal (node2_balance , wallet_watch .getbalance ())
120135
121- # start node0 with wallet disabled so wallet transactions don't get resubmitted
122136 self .log .debug ("Stop-start node0 with -persistmempool=0. Verify that it doesn't load its mempool.dat file." )
123137 self .stop_nodes ()
124- self .start_node (0 , extra_args = ["-persistmempool=0" , "-disablewallet" ])
138+ self .start_node (0 , extra_args = ["-persistmempool=0" ])
125139 assert self .nodes [0 ].getmempoolinfo ()["loaded" ]
126140 assert_equal (len (self .nodes [0 ].getrawmempool ()), 0 )
127141
@@ -164,18 +178,18 @@ def test_persist_unbroadcast(self):
164178
165179 # ensure node0 doesn't have any connections
166180 # make a transaction that will remain in the unbroadcast set
167- assert (len (node0 .getpeerinfo ()) == 0 )
168- assert (len (node0 .p2ps ) == 0 )
169- node0 . sendtoaddress ( self .nodes [ 1 ]. getnewaddress (), Decimal ( "12" ) )
181+ assert_equal (len (node0 .getpeerinfo ()), 0 )
182+ assert_equal (len (node0 .p2ps ), 0 )
183+ self .mini_wallet . send_self_transfer ( from_node = node0 )
170184
171185 # shutdown, then startup with wallet disabled
172- self .stop_nodes ()
173- self .start_node (0 , extra_args = ["-disablewallet" ])
186+ self .restart_node (0 , extra_args = ["-disablewallet" ])
174187
175188 # check that txn gets broadcast due to unbroadcast logic
176189 conn = node0 .add_p2p_connection (P2PTxInvStore ())
177- node0 .mockscheduler (16 * 60 ) # 15 min + 1 for buffer
190+ node0 .mockscheduler (16 * 60 ) # 15 min + 1 for buffer
178191 self .wait_until (lambda : len (conn .get_invs ()) == 1 )
179192
180- if __name__ == '__main__' :
193+
194+ if __name__ == "__main__" :
181195 MempoolPersistTest ().main ()
0 commit comments