@@ -73,6 +73,9 @@ def run_test(self):
7373 test_unconfirmed_not_spendable (rbf_node , rbf_node_address )
7474 test_bumpfee_metadata (rbf_node , dest_address )
7575 test_locked_wallet_fails (rbf_node , dest_address )
76+ # These tests wipe out a number of utxos that are expected in other tests
77+ test_small_output_with_feerate_succeeds (rbf_node , dest_address )
78+ test_no_more_inputs_fails (rbf_node , dest_address )
7679 self .log .info ("Success" )
7780
7881
@@ -173,6 +176,40 @@ def test_small_output_fails(rbf_node, dest_address):
173176 rbfid = spend_one_input (rbf_node , dest_address )
174177 assert_raises_rpc_error (- 4 , "Change output is too small" , rbf_node .bumpfee , rbfid , {"totalFee" : 50001 })
175178
179+ def test_small_output_with_feerate_succeeds (rbf_node , dest_address ):
180+
181+ # Make sure additional inputs exist
182+ rbf_node .generatetoaddress (101 , rbf_node .getnewaddress ())
183+ rbfid = spend_one_input (rbf_node , dest_address )
184+ original_input_list = rbf_node .getrawtransaction (rbfid , 1 )["vin" ]
185+ assert_equal (len (original_input_list ), 1 )
186+ original_txin = original_input_list [0 ]
187+ # Keep bumping until we out-spend change output
188+ tx_fee = 0
189+ while tx_fee < Decimal ("0.0005" ):
190+ new_input_list = rbf_node .getrawtransaction (rbfid , 1 )["vin" ]
191+ new_item = list (new_input_list )[0 ]
192+ assert_equal (len (original_input_list ), 1 )
193+ assert_equal (original_txin ["txid" ], new_item ["txid" ])
194+ assert_equal (original_txin ["vout" ], new_item ["vout" ])
195+ rbfid_new_details = rbf_node .bumpfee (rbfid )
196+ rbfid_new = rbfid_new_details ["txid" ]
197+ raw_pool = rbf_node .getrawmempool ()
198+ assert rbfid not in raw_pool
199+ assert rbfid_new in raw_pool
200+ rbfid = rbfid_new
201+ tx_fee = rbfid_new_details ["origfee" ]
202+
203+ # input(s) have been added
204+ final_input_list = rbf_node .getrawtransaction (rbfid , 1 )["vin" ]
205+ assert_greater_than (len (final_input_list ), 1 )
206+ # Original input is in final set
207+ assert [txin for txin in final_input_list
208+ if txin ["txid" ] == original_txin ["txid" ]
209+ and txin ["vout" ] == original_txin ["vout" ]]
210+
211+ rbf_node .generatetoaddress (1 , rbf_node .getnewaddress ())
212+ assert_equal (rbf_node .gettransaction (rbfid )["confirmations" ], 1 )
176213
177214def test_dust_to_fee (rbf_node , dest_address ):
178215 # check that if output is reduced to dust, it will be converted to fee
@@ -272,19 +309,20 @@ def test_locked_wallet_fails(rbf_node, dest_address):
272309 rbf_node .walletlock ()
273310 assert_raises_rpc_error (- 13 , "Please enter the wallet passphrase with walletpassphrase first." ,
274311 rbf_node .bumpfee , rbfid )
312+ rbf_node .walletpassphrase (WALLET_PASSPHRASE , WALLET_PASSPHRASE_TIMEOUT )
275313
276314
277- def spend_one_input (node , dest_address ):
315+ def spend_one_input (node , dest_address , change_size = Decimal ( "0.00049000" ) ):
278316 tx_input = dict (
279317 sequence = BIP125_SEQUENCE_NUMBER , ** next (u for u in node .listunspent () if u ["amount" ] == Decimal ("0.00100000" )))
280- rawtx = node .createrawtransaction (
281- [tx_input ], {dest_address : Decimal ("0.00050000" ),
282- node .getrawchangeaddress (): Decimal ("0.00049000" )})
318+ destinations = {dest_address : Decimal ("0.00050000" )}
319+ if change_size > 0 :
320+ destinations [node .getrawchangeaddress ()] = change_size
321+ rawtx = node .createrawtransaction ([tx_input ], destinations )
283322 signedtx = node .signrawtransactionwithwallet (rawtx )
284323 txid = node .sendrawtransaction (signedtx ["hex" ])
285324 return txid
286325
287-
288326def submit_block_with_tx (node , tx ):
289327 ctx = CTransaction ()
290328 ctx .deserialize (io .BytesIO (hex_str_to_bytes (tx )))
@@ -301,6 +339,12 @@ def submit_block_with_tx(node, tx):
301339 node .submitblock (block .serialize (True ).hex ())
302340 return block
303341
342+ def test_no_more_inputs_fails (rbf_node , dest_address ):
343+ # feerate rbf requires confirmed outputs when change output doesn't exist or is insufficient
344+ rbf_node .generatetoaddress (1 , dest_address )
345+ # spend all funds, no change output
346+ rbfid = rbf_node .sendtoaddress (rbf_node .getnewaddress (), rbf_node .getbalance (), "" , "" , True )
347+ assert_raises_rpc_error (- 4 , "Unable to create transaction: Insufficient funds" , rbf_node .bumpfee , rbfid )
304348
305349if __name__ == "__main__" :
306350 BumpFeeTest ().main ()
0 commit comments