@@ -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,33 +207,37 @@ 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 ):
210
221
self .log .info ('Test that it cannot bump fee if non-owned inputs are included' )
211
222
# here, the rbftx has a peer_node coin and then adds a rbf_node input
212
223
# Note that this test depends upon the RPC code checking input ownership prior to change outputs
213
224
# (since it can't use fundrawtransaction, it lacks a proper change output)
214
- utxos = [node .listunspent ()[- 1 ] for node in (rbf_node , peer_node )]
225
+ fee = Decimal ("0.001" )
226
+ utxos = [node .listunspent (query_options = {'minimumAmount' : fee })[- 1 ] for node in (rbf_node , peer_node )]
215
227
inputs = [{
216
228
"txid" : utxo ["txid" ],
217
229
"vout" : utxo ["vout" ],
218
230
"address" : utxo ["address" ],
219
231
"sequence" : BIP125_SEQUENCE_NUMBER
220
232
} for utxo in utxos ]
221
- output_val = sum (utxo ["amount" ] for utxo in utxos ) - Decimal ( "0.001" )
233
+ output_val = sum (utxo ["amount" ] for utxo in utxos ) - fee
222
234
rawtx = rbf_node .createrawtransaction (inputs , {dest_address : output_val })
223
235
signedtx = rbf_node .signrawtransactionwithwallet (rawtx )
224
236
signedtx = peer_node .signrawtransactionwithwallet (signedtx ["hex" ])
225
237
rbfid = rbf_node .sendrawtransaction (signedtx ["hex" ])
226
238
assert_raises_rpc_error (- 4 , "Transaction contains inputs that don't belong to this wallet" ,
227
239
rbf_node .bumpfee , rbfid )
240
+ self .clear_mempool ()
228
241
229
242
230
243
def test_bumpfee_with_descendant_fails (self , rbf_node , rbf_node_address , dest_address ):
@@ -235,6 +248,7 @@ def test_bumpfee_with_descendant_fails(self, rbf_node, rbf_node_address, dest_ad
235
248
tx = rbf_node .signrawtransactionwithwallet (tx )
236
249
rbf_node .sendrawtransaction (tx ["hex" ])
237
250
assert_raises_rpc_error (- 8 , "Transaction has descendants in the wallet" , rbf_node .bumpfee , parent_id )
251
+ self .clear_mempool ()
238
252
239
253
240
254
def test_small_output_with_feerate_succeeds (self , rbf_node , dest_address ):
@@ -276,6 +290,7 @@ def test_small_output_with_feerate_succeeds(self, rbf_node, dest_address):
276
290
277
291
rbf_node .generatetoaddress (1 , rbf_node .getnewaddress ())
278
292
assert_equal (rbf_node .gettransaction (rbfid )["confirmations" ], 1 )
293
+ self .clear_mempool ()
279
294
280
295
281
296
def test_dust_to_fee (self , rbf_node , dest_address ):
@@ -298,6 +313,7 @@ def test_dust_to_fee(self, rbf_node, dest_address):
298
313
assert_equal (len (fulltx ["vout" ]), 2 )
299
314
assert_equal (len (full_bumped_tx ["vout" ]), 1 ) # change output is eliminated
300
315
assert_equal (full_bumped_tx ["vout" ][0 ]['value' ], Decimal ("0.00050000" ))
316
+ self .clear_mempool ()
301
317
302
318
303
319
def test_settxfee (self , rbf_node , dest_address ):
@@ -320,6 +336,8 @@ def test_settxfee(self, rbf_node, dest_address):
320
336
assert_raises_rpc_error (- 8 , "txfee cannot be more than wallet max tx fee" , rbf_node .settxfee , Decimal ('0.00003' ))
321
337
self .restart_node (1 , self .extra_args [1 ])
322
338
rbf_node .walletpassphrase (WALLET_PASSPHRASE , WALLET_PASSPHRASE_TIMEOUT )
339
+ self .connect_nodes (1 , 0 )
340
+ self .clear_mempool ()
323
341
324
342
325
343
def test_maxtxfee_fails (self , rbf_node , dest_address ):
@@ -333,6 +351,8 @@ def test_maxtxfee_fails(self, rbf_node, dest_address):
333
351
assert_raises_rpc_error (- 4 , "Unable to create transaction. Fee exceeds maximum configured by -maxtxfee" , rbf_node .bumpfee , rbfid )
334
352
self .restart_node (1 , self .extra_args [1 ])
335
353
rbf_node .walletpassphrase (WALLET_PASSPHRASE , WALLET_PASSPHRASE_TIMEOUT )
354
+ self .connect_nodes (1 , 0 )
355
+ self .clear_mempool ()
336
356
337
357
338
358
def test_watchonly_psbt (self , peer_node , rbf_node , dest_address ):
@@ -415,6 +435,7 @@ def test_watchonly_psbt(self, peer_node, rbf_node, dest_address):
415
435
416
436
rbf_node .unloadwallet ("watcher" )
417
437
rbf_node .unloadwallet ("signer" )
438
+ self .clear_mempool ()
418
439
419
440
420
441
def test_rebumping (self , rbf_node , dest_address ):
@@ -423,6 +444,7 @@ def test_rebumping(self, rbf_node, dest_address):
423
444
bumped = rbf_node .bumpfee (rbfid , {"fee_rate" : ECONOMICAL })
424
445
assert_raises_rpc_error (- 4 , "already bumped" , rbf_node .bumpfee , rbfid , {"fee_rate" : NORMAL })
425
446
rbf_node .bumpfee (bumped ["txid" ], {"fee_rate" : NORMAL })
447
+ self .clear_mempool ()
426
448
427
449
428
450
def test_rebumping_not_replaceable (self , rbf_node , dest_address ):
@@ -431,6 +453,7 @@ def test_rebumping_not_replaceable(self, rbf_node, dest_address):
431
453
bumped = rbf_node .bumpfee (rbfid , {"fee_rate" : ECONOMICAL , "replaceable" : False })
432
454
assert_raises_rpc_error (- 4 , "Transaction is not BIP 125 replaceable" , rbf_node .bumpfee , bumped ["txid" ],
433
455
{"fee_rate" : NORMAL })
456
+ self .clear_mempool ()
434
457
435
458
436
459
def test_unconfirmed_not_spendable (self , rbf_node , rbf_node_address ):
@@ -470,6 +493,7 @@ def test_unconfirmed_not_spendable(self, rbf_node, rbf_node_address):
470
493
assert_equal (
471
494
sum (1 for t in rbf_node .listunspent (minconf = 0 , include_unsafe = False )
472
495
if t ["txid" ] == rbfid and t ["address" ] == rbf_node_address and t ["spendable" ]), 1 )
496
+ self .clear_mempool ()
473
497
474
498
475
499
def test_bumpfee_metadata (self , rbf_node , dest_address ):
@@ -481,6 +505,7 @@ def test_bumpfee_metadata(self, rbf_node, dest_address):
481
505
bumped_wtx = rbf_node .gettransaction (bumped_tx ["txid" ])
482
506
assert_equal (bumped_wtx ["comment" ], "comment value" )
483
507
assert_equal (bumped_wtx ["to" ], "to value" )
508
+ self .clear_mempool ()
484
509
485
510
486
511
def test_locked_wallet_fails (self , rbf_node , dest_address ):
@@ -490,6 +515,7 @@ def test_locked_wallet_fails(self, rbf_node, dest_address):
490
515
assert_raises_rpc_error (- 13 , "Please enter the wallet passphrase with walletpassphrase first." ,
491
516
rbf_node .bumpfee , rbfid )
492
517
rbf_node .walletpassphrase (WALLET_PASSPHRASE , WALLET_PASSPHRASE_TIMEOUT )
518
+ self .clear_mempool ()
493
519
494
520
495
521
def test_change_script_match (self , rbf_node , dest_address ):
@@ -510,6 +536,7 @@ def get_change_address(tx):
510
536
assert_equal (change_addresses , get_change_address (bumped_total_tx ['txid' ]))
511
537
bumped_rate_tx = rbf_node .bumpfee (bumped_total_tx ["txid" ])
512
538
assert_equal (change_addresses , get_change_address (bumped_rate_tx ['txid' ]))
539
+ self .clear_mempool ()
513
540
514
541
515
542
def spend_one_input (node , dest_address , change_size = Decimal ("0.00049000" )):
@@ -548,6 +575,7 @@ def test_no_more_inputs_fails(self, rbf_node, dest_address):
548
575
# spend all funds, no change output
549
576
rbfid = rbf_node .sendtoaddress (rbf_node .getnewaddress (), rbf_node .getbalance (), "" , "" , True )
550
577
assert_raises_rpc_error (- 4 , "Unable to create transaction. Insufficient funds" , rbf_node .bumpfee , rbfid )
578
+ self .clear_mempool ()
551
579
552
580
553
581
if __name__ == "__main__" :
0 commit comments