Skip to content

Commit 6f214d5

Browse files
committed
test: Add test_add_foreign_utxo_build_fee_bump
1 parent b0c1b72 commit 6f214d5

File tree

1 file changed

+53
-1
lines changed

1 file changed

+53
-1
lines changed

tests/add_foreign_utxo.rs

Lines changed: 53 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,9 @@ use bdk_wallet::signer::SignOptions;
55
use bdk_wallet::test_utils::*;
66
use bdk_wallet::tx_builder::AddForeignUtxoError;
77
use bdk_wallet::KeychainKind;
8-
use bitcoin::{psbt, Address, Amount};
8+
use bitcoin::{hashes::Hash, psbt, Address, Amount, FeeRate, OutPoint, TxOut, Weight};
9+
10+
use common::parse_descriptor;
911

1012
mod common;
1113

@@ -290,3 +292,53 @@ fn test_taproot_foreign_utxo() {
290292
"foreign_utxo should be in there"
291293
);
292294
}
295+
296+
// Test that we can fee-bump a tx containing a foreign utxo
297+
#[test]
298+
fn test_add_foreign_utxo_build_fee_bump() {
299+
let (mut wallet, _) = get_funded_wallet_wpkh();
300+
let drain_spk = wallet
301+
.next_unused_address(KeychainKind::External)
302+
.script_pubkey();
303+
304+
let (desc, _) = parse_descriptor(get_test_tr_single_sig());
305+
let spk = desc.at_derivation_index(0).unwrap().script_pubkey();
306+
let witness_utxo = TxOut {
307+
value: Amount::ONE_SAT,
308+
script_pubkey: spk,
309+
};
310+
// Remember to include this as a "floating" txout in the wallet.
311+
let outpoint = OutPoint::new(Hash::hash(b"prev"), 1);
312+
wallet.insert_txout(outpoint, witness_utxo.clone());
313+
let satisfaction_weight = Weight::from_wu(71);
314+
let psbt_input = psbt::Input {
315+
witness_utxo: Some(witness_utxo),
316+
..Default::default()
317+
};
318+
319+
let mut tx_builder = wallet.build_tx();
320+
tx_builder
321+
.add_foreign_utxo(outpoint, psbt_input, satisfaction_weight)
322+
.unwrap()
323+
.only_witness_utxo()
324+
.fee_rate(FeeRate::from_sat_per_vb_unchecked(2))
325+
.drain_to(drain_spk.clone());
326+
let psbt = tx_builder.finish().unwrap();
327+
let tx = psbt.unsigned_tx.clone();
328+
assert!(tx.input.iter().any(|txin| txin.previous_output == outpoint));
329+
let txid1 = tx.compute_txid();
330+
wallet.apply_unconfirmed_txs([(tx, 123456)]);
331+
332+
// Now build fee bump.
333+
let mut tx_builder = wallet
334+
.build_fee_bump(txid1)
335+
.expect("`build_fee_bump` should succeed");
336+
tx_builder
337+
.set_recipients(vec![])
338+
.drain_to(drain_spk)
339+
.only_witness_utxo()
340+
.fee_rate(FeeRate::from_sat_per_vb_unchecked(5));
341+
let psbt = tx_builder.finish().unwrap();
342+
let tx = &psbt.unsigned_tx;
343+
assert!(tx.input.iter().any(|txin| txin.previous_output == outpoint));
344+
}

0 commit comments

Comments
 (0)