@@ -5,7 +5,7 @@ use bdk_wallet::signer::SignOptions;
55use bdk_wallet:: test_utils:: * ;
66use bdk_wallet:: tx_builder:: AddForeignUtxoError ;
77use bdk_wallet:: KeychainKind ;
8- use bitcoin:: { psbt, Address , Amount } ;
8+ use bitcoin:: { psbt, Address , Amount , ScriptBuf } ;
99
1010mod common;
1111
@@ -290,3 +290,60 @@ fn test_taproot_foreign_utxo() {
290290 "foreign_utxo should be in there"
291291 ) ;
292292}
293+
294+ #[ test]
295+ fn test_add_foreign_utxo_bump_fee ( ) {
296+ // Create tx spending a p2a output
297+ let ( mut w, _) = get_funded_wallet_wpkh ( ) ;
298+
299+ let drain_to = w. next_unused_address ( KeychainKind :: External ) ;
300+ // b
301+ // .allow_dust(true)
302+ // .add_recipient(ScriptBuf::new_p2a(), Amount::ZERO);
303+ //
304+ // let mut psbt = b.finish().unwrap();
305+ // for txout in &psbt.unsigned_tx.output {
306+ // let spk = &txout.script_pubkey;
307+ // println!("{}", spk.to_asm_string()); // OP_PUSHNUM_1 OP_PUSHBYTES_2 4e73
308+ // println!("{}", spk.to_hex_string()); // 51024e73
309+ // }
310+
311+ use bitcoin:: hashes:: Hash ;
312+ use bitcoin:: OutPoint ;
313+ use bitcoin:: TxIn ;
314+ use bitcoin:: TxOut ;
315+ let witness_utxo = TxOut {
316+ value : Amount :: ZERO ,
317+ script_pubkey : ScriptBuf :: new_p2a ( ) ,
318+ } ;
319+ let sat_wu = TxIn :: default ( ) . segwit_weight ( ) ;
320+ let op = OutPoint :: new ( Hash :: hash ( b"prev" ) , 4 ) ;
321+ let psbt_input = psbt:: Input {
322+ witness_utxo : Some ( witness_utxo. clone ( ) ) ,
323+ ..Default :: default ( )
324+ } ;
325+ w. insert_txout ( op, witness_utxo) ;
326+
327+ let mut b = w. build_tx ( ) ;
328+ b. add_foreign_utxo ( op, psbt_input, sat_wu)
329+ . unwrap ( )
330+ . only_witness_utxo ( )
331+ . drain_to ( drain_to. script_pubkey ( ) ) ;
332+ let mut psbt = b. finish ( ) . unwrap ( ) ;
333+
334+ let sign_options = SignOptions {
335+ trust_witness_utxo : true ,
336+ ..Default :: default ( )
337+ } ;
338+ let _finalized = w. sign ( & mut psbt, sign_options) . unwrap ( ) ;
339+ // dbg!(_finalized); // false
340+ // dbg!(&psbt);
341+
342+ let tx = psbt. extract_tx ( ) . unwrap ( ) ;
343+ // dbg!(&tx);
344+ let txid1 = tx. compute_txid ( ) ;
345+ insert_tx ( & mut w, tx) ;
346+
347+ // Build fee bump
348+ let _ = w. build_fee_bump ( txid1) . unwrap_err ( ) ;
349+ }
0 commit comments