@@ -73,6 +73,7 @@ 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+ test_change_script_match (rbf_node , dest_address )
7677 # These tests wipe out a number of utxos that are expected in other tests
7778 test_small_output_with_feerate_succeeds (rbf_node , dest_address )
7879 test_no_more_inputs_fails (rbf_node , dest_address )
@@ -311,6 +312,23 @@ def test_locked_wallet_fails(rbf_node, dest_address):
311312 rbf_node .bumpfee , rbfid )
312313 rbf_node .walletpassphrase (WALLET_PASSPHRASE , WALLET_PASSPHRASE_TIMEOUT )
313314
315+ def test_change_script_match (rbf_node , dest_address ):
316+ """Test that the same change addresses is used for the replacement transaction when possible."""
317+ def get_change_address (tx ):
318+ tx_details = rbf_node .getrawtransaction (tx , 1 )
319+ txout_addresses = [txout ['scriptPubKey' ]['addresses' ][0 ] for txout in tx_details ["vout" ]]
320+ return [address for address in txout_addresses if rbf_node .getaddressinfo (address )["ischange" ]]
321+
322+ # Check that there is only one change output
323+ rbfid = spend_one_input (rbf_node , dest_address )
324+ change_addresses = get_change_address (rbfid )
325+ assert_equal (len (change_addresses ), 1 )
326+
327+ # Now find that address in each subsequent tx, and no other change
328+ bumped_total_tx = rbf_node .bumpfee (rbfid , {"totalFee" : 2000 })
329+ assert_equal (change_addresses , get_change_address (bumped_total_tx ['txid' ]))
330+ bumped_rate_tx = rbf_node .bumpfee (bumped_total_tx ["txid" ])
331+ assert_equal (change_addresses , get_change_address (bumped_rate_tx ['txid' ]))
314332
315333def spend_one_input (node , dest_address , change_size = Decimal ("0.00049000" )):
316334 tx_input = dict (
0 commit comments