46
46
assert_greater_than_or_equal ,
47
47
assert_raises_rpc_error ,
48
48
)
49
+ from test_framework .wallet import MiniWallet
49
50
50
51
51
52
class MempoolPersistTest (BitcoinTestFramework ):
52
53
def set_test_params (self ):
53
54
self .num_nodes = 3
54
55
self .extra_args = [[], ["-persistmempool=0" ], []]
55
56
56
- def skip_test_if_missing_module (self ):
57
- self .skip_if_no_wallet ()
58
-
59
57
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
+
60
70
self .log .debug ("Send 5 transactions from node2 (to its own address)" )
61
71
tx_creation_time_lower = int (time .time ())
62
72
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 ()
65
77
self .sync_all ()
66
78
tx_creation_time_higher = int (time .time ())
67
79
@@ -82,16 +94,16 @@ def run_test(self):
82
94
assert_equal (total_fee_old , self .nodes [0 ].getmempoolinfo ()['total_fee' ])
83
95
assert_equal (total_fee_old , sum (v ['fees' ]['base' ] for k , v in self .nodes [0 ].getrawmempool (verbose = True ).items ()))
84
96
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' ]
86
99
assert_greater_than_or_equal (tx_creation_time , tx_creation_time_lower )
87
100
assert_greater_than_or_equal (tx_creation_time_higher , tx_creation_time )
88
101
89
102
# disconnect nodes & make a txn that remains in the unbroadcast set.
90
103
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 ])
95
107
96
108
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." )
97
109
self .stop_nodes ()
@@ -111,17 +123,19 @@ def run_test(self):
111
123
fees = self .nodes [0 ].getmempoolentry (txid = last_txid )['fees' ]
112
124
assert_equal (fees ['base' ] + Decimal ('0.00001000' ), fees ['modified' ])
113
125
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 ))
116
128
117
129
# 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 ())
120
135
121
- # start node0 with wallet disabled so wallet transactions don't get resubmitted
122
136
self .log .debug ("Stop-start node0 with -persistmempool=0. Verify that it doesn't load its mempool.dat file." )
123
137
self .stop_nodes ()
124
- self .start_node (0 , extra_args = ["-persistmempool=0" , "-disablewallet" ])
138
+ self .start_node (0 , extra_args = ["-persistmempool=0" ])
125
139
assert self .nodes [0 ].getmempoolinfo ()["loaded" ]
126
140
assert_equal (len (self .nodes [0 ].getrawmempool ()), 0 )
127
141
@@ -164,18 +178,18 @@ def test_persist_unbroadcast(self):
164
178
165
179
# ensure node0 doesn't have any connections
166
180
# 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 )
170
184
171
185
# 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" ])
174
187
175
188
# check that txn gets broadcast due to unbroadcast logic
176
189
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
178
191
self .wait_until (lambda : len (conn .get_invs ()) == 1 )
179
192
180
- if __name__ == '__main__' :
193
+
194
+ if __name__ == "__main__" :
181
195
MempoolPersistTest ().main ()
0 commit comments