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
@@ -90,7 +102,7 @@ def run_test(self):
90
102
self .disconnect_nodes (0 , 1 )
91
103
assert (len (self .nodes [0 ].getpeerinfo ()) == 0 )
92
104
assert (len (self .nodes [0 ].p2ps ) == 0 )
93
- self .nodes [ 0 ]. sendtoaddress ( self .nodes [2 ]. getnewaddress (), Decimal ( "12" ) )
105
+ self .mini_wallet . send_self_transfer ( from_node = self .nodes [0 ] )
94
106
self .connect_nodes (0 , 2 )
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." )
@@ -115,13 +127,15 @@ def run_test(self):
115
127
assert_equal (tx_creation_time , self .nodes [0 ].getmempoolentry (txid = last_txid )['time' ])
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
@@ -166,11 +180,10 @@ def test_persist_unbroadcast(self):
166
180
# make a transaction that will remain in the unbroadcast set
167
181
assert (len (node0 .getpeerinfo ()) == 0 )
168
182
assert (len (node0 .p2ps ) == 0 )
169
- node0 . sendtoaddress ( self .nodes [ 1 ]. getnewaddress (), Decimal ( "12" ) )
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 ())
0 commit comments