@@ -8,8 +8,8 @@ use bdk_wallet::psbt::PsbtUtils;
88use bdk_wallet:: test_utils:: * ;
99use bdk_wallet:: KeychainKind ;
1010use bitcoin:: {
11- absolute, transaction, Address , Amount , FeeRate , OutPoint , ScriptBuf , Sequence , Transaction ,
12- TxOut ,
11+ absolute, hashes :: Hash , psbt , transaction, Address , Amount , FeeRate , OutPoint , ScriptBuf ,
12+ Sequence , Transaction , TxOut , Weight ,
1313} ;
1414
1515mod common;
@@ -944,3 +944,51 @@ fn test_legacy_bump_fee_absolute_add_input() {
944944
945945 assert_eq ! ( fee, Amount :: from_sat( 6_000 ) ) ;
946946}
947+
948+ // Test that we can fee-bump a tx containing a foreign (p2a) utxo.
949+ #[ test]
950+ fn test_bump_fee_pay_to_anchor_foreign_utxo ( ) {
951+ let ( mut wallet, _) = get_funded_wallet_wpkh ( ) ;
952+ let drain_spk = wallet
953+ . next_unused_address ( KeychainKind :: External )
954+ . script_pubkey ( ) ;
955+
956+ let witness_utxo = TxOut {
957+ value : Amount :: ONE_SAT ,
958+ script_pubkey : bitcoin:: ScriptBuf :: new_p2a ( ) ,
959+ } ;
960+ // Remember to include this as a "floating" txout in the wallet.
961+ let outpoint = OutPoint :: new ( Hash :: hash ( b"prev" ) , 1 ) ;
962+ wallet. insert_txout ( outpoint, witness_utxo. clone ( ) ) ;
963+ let satisfaction_weight = Weight :: from_wu ( 71 ) ;
964+ let psbt_input = psbt:: Input {
965+ witness_utxo : Some ( witness_utxo) ,
966+ ..Default :: default ( )
967+ } ;
968+
969+ let mut tx_builder = wallet. build_tx ( ) ;
970+ tx_builder
971+ . add_foreign_utxo ( outpoint, psbt_input, satisfaction_weight)
972+ . unwrap ( )
973+ . only_witness_utxo ( )
974+ . fee_rate ( FeeRate :: from_sat_per_vb_unchecked ( 2 ) )
975+ . drain_to ( drain_spk. clone ( ) ) ;
976+ let psbt = tx_builder. finish ( ) . unwrap ( ) ;
977+ let tx = psbt. unsigned_tx . clone ( ) ;
978+ assert ! ( tx. input. iter( ) . any( |txin| txin. previous_output == outpoint) ) ;
979+ let txid1 = tx. compute_txid ( ) ;
980+ wallet. apply_unconfirmed_txs ( [ ( tx, 123456 ) ] ) ;
981+
982+ // Now build fee bump.
983+ let mut tx_builder = wallet
984+ . build_fee_bump ( txid1)
985+ . expect ( "`build_fee_bump` should succeed" ) ;
986+ tx_builder
987+ . set_recipients ( vec ! [ ] )
988+ . drain_to ( drain_spk)
989+ . only_witness_utxo ( )
990+ . fee_rate ( FeeRate :: from_sat_per_vb_unchecked ( 5 ) ) ;
991+ let psbt = tx_builder. finish ( ) . unwrap ( ) ;
992+ let tx = & psbt. unsigned_tx ;
993+ assert ! ( tx. input. iter( ) . any( |txin| txin. previous_output == outpoint) ) ;
994+ }
0 commit comments