@@ -50,6 +50,11 @@ def set_test_params(self):
50
50
def skip_test_if_missing_module (self ):
51
51
self .skip_if_no_wallet ()
52
52
53
+ def clear_mempool (self ):
54
+ # Clear mempool between subtests. The subtests may only depend on chainstate (utxos)
55
+ self .nodes [1 ].generate (1 )
56
+ self .sync_all ()
57
+
53
58
def run_test (self ):
54
59
# Encrypt wallet for test_locked_wallet_fails test
55
60
self .nodes [1 ].encryptwallet (WALLET_PASSPHRASE )
@@ -71,7 +76,7 @@ def run_test(self):
71
76
72
77
self .log .info ("Running tests" )
73
78
dest_address = peer_node .getnewaddress ()
74
- test_invalid_parameters (rbf_node , dest_address )
79
+ self . test_invalid_parameters (rbf_node , dest_address )
75
80
test_simple_bumpfee_succeeds (self , "default" , rbf_node , peer_node , dest_address )
76
81
test_simple_bumpfee_succeeds (self , "fee_rate" , rbf_node , peer_node , dest_address )
77
82
test_feerate_args (self , rbf_node , peer_node , dest_address )
@@ -93,28 +98,30 @@ def run_test(self):
93
98
test_small_output_with_feerate_succeeds (self , rbf_node , dest_address )
94
99
test_no_more_inputs_fails (self , rbf_node , dest_address )
95
100
96
- def test_invalid_parameters (node , dest_address ):
97
- txid = spend_one_input (node , dest_address )
98
- # invalid estimate mode
99
- assert_raises_rpc_error (- 8 , "Invalid estimate_mode parameter" , node .bumpfee , txid , {
100
- "estimate_mode" : "moo" ,
101
- })
102
- assert_raises_rpc_error (- 3 , "Expected type string" , node .bumpfee , txid , {
103
- "estimate_mode" : 38 ,
104
- })
105
- assert_raises_rpc_error (- 3 , "Expected type string" , node .bumpfee , txid , {
106
- "estimate_mode" : {
107
- "foo" : "bar" ,
108
- },
109
- })
110
- assert_raises_rpc_error (- 8 , "Invalid estimate_mode parameter" , node .bumpfee , txid , {
111
- "estimate_mode" : Decimal ("3.141592" ),
112
- })
113
- # confTarget and conf_target
114
- assert_raises_rpc_error (- 8 , "confTarget and conf_target options should not both be set" , node .bumpfee , txid , {
115
- "confTarget" : 123 ,
116
- "conf_target" : 456 ,
117
- })
101
+ def test_invalid_parameters (self , node , dest_address ):
102
+ txid = spend_one_input (node , dest_address )
103
+ # invalid estimate mode
104
+ assert_raises_rpc_error (- 8 , "Invalid estimate_mode parameter" , node .bumpfee , txid , {
105
+ "estimate_mode" : "moo" ,
106
+ })
107
+ assert_raises_rpc_error (- 3 , "Expected type string" , node .bumpfee , txid , {
108
+ "estimate_mode" : 38 ,
109
+ })
110
+ assert_raises_rpc_error (- 3 , "Expected type string" , node .bumpfee , txid , {
111
+ "estimate_mode" : {
112
+ "foo" : "bar" ,
113
+ },
114
+ })
115
+ assert_raises_rpc_error (- 8 , "Invalid estimate_mode parameter" , node .bumpfee , txid , {
116
+ "estimate_mode" : Decimal ("3.141592" ),
117
+ })
118
+ # confTarget and conf_target
119
+ assert_raises_rpc_error (- 8 , "confTarget and conf_target options should not both be set" , node .bumpfee , txid , {
120
+ "confTarget" : 123 ,
121
+ "conf_target" : 456 ,
122
+ })
123
+ self .clear_mempool ()
124
+
118
125
119
126
def test_simple_bumpfee_succeeds (self , mode , rbf_node , peer_node , dest_address ):
120
127
self .log .info ('Test simple bumpfee: {}' .format (mode ))
@@ -148,6 +155,7 @@ def test_simple_bumpfee_succeeds(self, mode, rbf_node, peer_node, dest_address):
148
155
bumpedwtx = rbf_node .gettransaction (bumped_tx ["txid" ])
149
156
assert_equal (oldwtx ["replaced_by_txid" ], bumped_tx ["txid" ])
150
157
assert_equal (bumpedwtx ["replaces_txid" ], rbfid )
158
+ self .clear_mempool ()
151
159
152
160
153
161
def test_feerate_args (self , rbf_node , peer_node , dest_address ):
@@ -167,6 +175,7 @@ def test_feerate_args(self, rbf_node, peer_node, dest_address):
167
175
assert_raises_rpc_error (- 3 , "Amount out of range" , rbf_node .bumpfee , rbfid , {"fee_rate" : - 1 })
168
176
169
177
assert_raises_rpc_error (- 4 , "is too high (cannot be higher than" , rbf_node .bumpfee , rbfid , {"fee_rate" : TOO_HIGH })
178
+ self .clear_mempool ()
170
179
171
180
172
181
def test_segwit_bumpfee_succeeds (self , rbf_node , dest_address ):
@@ -198,12 +207,14 @@ def test_segwit_bumpfee_succeeds(self, rbf_node, dest_address):
198
207
bumped_tx = rbf_node .bumpfee (rbfid )
199
208
assert bumped_tx ["txid" ] in rbf_node .getrawmempool ()
200
209
assert rbfid not in rbf_node .getrawmempool ()
210
+ self .clear_mempool ()
201
211
202
212
203
213
def test_nonrbf_bumpfee_fails (self , peer_node , dest_address ):
204
214
self .log .info ('Test that we cannot replace a non RBF transaction' )
205
215
not_rbfid = peer_node .sendtoaddress (dest_address , Decimal ("0.00090000" ))
206
216
assert_raises_rpc_error (- 4 , "not BIP 125 replaceable" , peer_node .bumpfee , not_rbfid )
217
+ self .clear_mempool ()
207
218
208
219
209
220
def test_notmine_bumpfee_fails (self , rbf_node , peer_node , dest_address ):
@@ -226,6 +237,7 @@ def test_notmine_bumpfee_fails(self, rbf_node, peer_node, dest_address):
226
237
rbfid = rbf_node .sendrawtransaction (signedtx ["hex" ])
227
238
assert_raises_rpc_error (- 4 , "Transaction contains inputs that don't belong to this wallet" ,
228
239
rbf_node .bumpfee , rbfid )
240
+ self .clear_mempool ()
229
241
230
242
231
243
def test_bumpfee_with_descendant_fails (self , rbf_node , rbf_node_address , dest_address ):
@@ -236,6 +248,7 @@ def test_bumpfee_with_descendant_fails(self, rbf_node, rbf_node_address, dest_ad
236
248
tx = rbf_node .signrawtransactionwithwallet (tx )
237
249
rbf_node .sendrawtransaction (tx ["hex" ])
238
250
assert_raises_rpc_error (- 8 , "Transaction has descendants in the wallet" , rbf_node .bumpfee , parent_id )
251
+ self .clear_mempool ()
239
252
240
253
241
254
def test_small_output_with_feerate_succeeds (self , rbf_node , dest_address ):
@@ -277,6 +290,7 @@ def test_small_output_with_feerate_succeeds(self, rbf_node, dest_address):
277
290
278
291
rbf_node .generatetoaddress (1 , rbf_node .getnewaddress ())
279
292
assert_equal (rbf_node .gettransaction (rbfid )["confirmations" ], 1 )
293
+ self .clear_mempool ()
280
294
281
295
282
296
def test_dust_to_fee (self , rbf_node , dest_address ):
@@ -299,6 +313,7 @@ def test_dust_to_fee(self, rbf_node, dest_address):
299
313
assert_equal (len (fulltx ["vout" ]), 2 )
300
314
assert_equal (len (full_bumped_tx ["vout" ]), 1 ) # change output is eliminated
301
315
assert_equal (full_bumped_tx ["vout" ][0 ]['value' ], Decimal ("0.00050000" ))
316
+ self .clear_mempool ()
302
317
303
318
304
319
def test_settxfee (self , rbf_node , dest_address ):
@@ -321,6 +336,8 @@ def test_settxfee(self, rbf_node, dest_address):
321
336
assert_raises_rpc_error (- 8 , "txfee cannot be more than wallet max tx fee" , rbf_node .settxfee , Decimal ('0.00003' ))
322
337
self .restart_node (1 , self .extra_args [1 ])
323
338
rbf_node .walletpassphrase (WALLET_PASSPHRASE , WALLET_PASSPHRASE_TIMEOUT )
339
+ self .connect_nodes (1 , 0 )
340
+ self .clear_mempool ()
324
341
325
342
326
343
def test_maxtxfee_fails (self , rbf_node , dest_address ):
@@ -334,6 +351,8 @@ def test_maxtxfee_fails(self, rbf_node, dest_address):
334
351
assert_raises_rpc_error (- 4 , "Unable to create transaction. Fee exceeds maximum configured by -maxtxfee" , rbf_node .bumpfee , rbfid )
335
352
self .restart_node (1 , self .extra_args [1 ])
336
353
rbf_node .walletpassphrase (WALLET_PASSPHRASE , WALLET_PASSPHRASE_TIMEOUT )
354
+ self .connect_nodes (1 , 0 )
355
+ self .clear_mempool ()
337
356
338
357
339
358
def test_watchonly_psbt (self , peer_node , rbf_node , dest_address ):
@@ -416,6 +435,7 @@ def test_watchonly_psbt(self, peer_node, rbf_node, dest_address):
416
435
417
436
rbf_node .unloadwallet ("watcher" )
418
437
rbf_node .unloadwallet ("signer" )
438
+ self .clear_mempool ()
419
439
420
440
421
441
def test_rebumping (self , rbf_node , dest_address ):
@@ -424,6 +444,7 @@ def test_rebumping(self, rbf_node, dest_address):
424
444
bumped = rbf_node .bumpfee (rbfid , {"fee_rate" : ECONOMICAL })
425
445
assert_raises_rpc_error (- 4 , "already bumped" , rbf_node .bumpfee , rbfid , {"fee_rate" : NORMAL })
426
446
rbf_node .bumpfee (bumped ["txid" ], {"fee_rate" : NORMAL })
447
+ self .clear_mempool ()
427
448
428
449
429
450
def test_rebumping_not_replaceable (self , rbf_node , dest_address ):
@@ -432,6 +453,7 @@ def test_rebumping_not_replaceable(self, rbf_node, dest_address):
432
453
bumped = rbf_node .bumpfee (rbfid , {"fee_rate" : ECONOMICAL , "replaceable" : False })
433
454
assert_raises_rpc_error (- 4 , "Transaction is not BIP 125 replaceable" , rbf_node .bumpfee , bumped ["txid" ],
434
455
{"fee_rate" : NORMAL })
456
+ self .clear_mempool ()
435
457
436
458
437
459
def test_unconfirmed_not_spendable (self , rbf_node , rbf_node_address ):
@@ -471,6 +493,7 @@ def test_unconfirmed_not_spendable(self, rbf_node, rbf_node_address):
471
493
assert_equal (
472
494
sum (1 for t in rbf_node .listunspent (minconf = 0 , include_unsafe = False )
473
495
if t ["txid" ] == rbfid and t ["address" ] == rbf_node_address and t ["spendable" ]), 1 )
496
+ self .clear_mempool ()
474
497
475
498
476
499
def test_bumpfee_metadata (self , rbf_node , dest_address ):
@@ -482,6 +505,7 @@ def test_bumpfee_metadata(self, rbf_node, dest_address):
482
505
bumped_wtx = rbf_node .gettransaction (bumped_tx ["txid" ])
483
506
assert_equal (bumped_wtx ["comment" ], "comment value" )
484
507
assert_equal (bumped_wtx ["to" ], "to value" )
508
+ self .clear_mempool ()
485
509
486
510
487
511
def test_locked_wallet_fails (self , rbf_node , dest_address ):
@@ -491,6 +515,7 @@ def test_locked_wallet_fails(self, rbf_node, dest_address):
491
515
assert_raises_rpc_error (- 13 , "Please enter the wallet passphrase with walletpassphrase first." ,
492
516
rbf_node .bumpfee , rbfid )
493
517
rbf_node .walletpassphrase (WALLET_PASSPHRASE , WALLET_PASSPHRASE_TIMEOUT )
518
+ self .clear_mempool ()
494
519
495
520
496
521
def test_change_script_match (self , rbf_node , dest_address ):
@@ -511,6 +536,7 @@ def get_change_address(tx):
511
536
assert_equal (change_addresses , get_change_address (bumped_total_tx ['txid' ]))
512
537
bumped_rate_tx = rbf_node .bumpfee (bumped_total_tx ["txid" ])
513
538
assert_equal (change_addresses , get_change_address (bumped_rate_tx ['txid' ]))
539
+ self .clear_mempool ()
514
540
515
541
516
542
def spend_one_input (node , dest_address , change_size = Decimal ("0.00049000" )):
@@ -549,6 +575,7 @@ def test_no_more_inputs_fails(self, rbf_node, dest_address):
549
575
# spend all funds, no change output
550
576
rbfid = rbf_node .sendtoaddress (rbf_node .getnewaddress (), rbf_node .getbalance (), "" , "" , True )
551
577
assert_raises_rpc_error (- 4 , "Unable to create transaction. Insufficient funds" , rbf_node .bumpfee , rbfid )
578
+ self .clear_mempool ()
552
579
553
580
554
581
if __name__ == "__main__" :
0 commit comments