Skip to content

Commit 992a08f

Browse files
committed
test: Add test_bump_fee_pay_to_anchor_foreign_utxo
deps: Bump `bitcoin` to 0.32.7 to make use of `ScriptBuf::new_p2a`.
1 parent b0c1b72 commit 992a08f

File tree

2 files changed

+51
-3
lines changed

2 files changed

+51
-3
lines changed

Cargo.toml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -18,7 +18,7 @@ rustdoc-args = ["--cfg", "docsrs"]
1818

1919
[dependencies]
2020
bdk_chain = { version = "0.23.1", features = ["miniscript", "serde"], default-features = false }
21-
bitcoin = { version = "0.32.6", features = ["serde", "base64"], default-features = false }
21+
bitcoin = { version = "0.32.7", features = ["serde", "base64"], default-features = false }
2222
miniscript = { version = "12.3.1", features = ["serde"], default-features = false }
2323
rand_core = { version = "0.6.0" }
2424
serde_json = { version = "1" }

tests/build_fee_bump.rs

Lines changed: 50 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -8,8 +8,8 @@ use bdk_wallet::psbt::PsbtUtils;
88
use bdk_wallet::test_utils::*;
99
use bdk_wallet::KeychainKind;
1010
use 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

1515
mod 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

Comments
 (0)