@@ -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:: { hashes :: Hash , psbt, Address , Amount , OutPoint , ScriptBuf , Sequence , TxOut } ;
99
1010mod common;
1111
@@ -290,3 +290,55 @@ fn test_taproot_foreign_utxo() {
290290 "foreign_utxo should be in there"
291291 ) ;
292292}
293+
294+ #[ test]
295+ fn test_add_planned_psbt_input ( ) -> anyhow:: Result < ( ) > {
296+ let ( mut wallet, _) = get_funded_wallet_wpkh ( ) ;
297+ let op1 = wallet. list_unspent ( ) . next ( ) . unwrap ( ) . outpoint ;
298+
299+ // We'll use `PsbtParams` to sweep a foreign anchor output.
300+ let op2 = OutPoint :: new ( Hash :: hash ( b"txid" ) , 2 ) ;
301+ let txout = TxOut {
302+ value : Amount :: ZERO ,
303+ script_pubkey : ScriptBuf :: new_p2a ( ) ,
304+ } ;
305+ let psbt_input = psbt:: Input {
306+ witness_utxo : Some ( txout) ,
307+ ..Default :: default ( )
308+ } ;
309+ let input = bdk_tx:: Input :: from_psbt_input (
310+ op2,
311+ Sequence :: ENABLE_LOCKTIME_NO_RBF ,
312+ psbt_input,
313+ /* satisfaction_weight: */ 0 ,
314+ /* status: */ None ,
315+ /* is_coinbase: */ false ,
316+ ) ?;
317+
318+ let send_to = wallet. reveal_next_address ( KeychainKind :: External ) . address ;
319+
320+ // Build tx: 2-in / 2-out
321+ let mut params = bdk_wallet:: PsbtParams :: default ( ) ;
322+ params. add_utxos ( & [ op1] ) ;
323+ params. add_planned_input ( input) ;
324+ params. add_recipients ( [ ( send_to, Amount :: from_sat ( 20_000 ) ) ] ) ;
325+
326+ let ( psbt, _) = wallet. create_psbt ( params) ?;
327+
328+ assert ! (
329+ psbt. unsigned_tx
330+ . input
331+ . iter( )
332+ . any( |input| input. previous_output == op1) ,
333+ "Psbt should contain the wallet spend"
334+ ) ;
335+ assert ! (
336+ psbt. unsigned_tx
337+ . input
338+ . iter( )
339+ . any( |input| input. previous_output == op2) ,
340+ "Psbt should contain the planned input"
341+ ) ;
342+
343+ Ok ( ( ) )
344+ }
0 commit comments