Skip to content

Commit a1518d1

Browse files
test: BDK won't add unconf inputs when fee bumping
Fixes #144 Also removes a leftover dbg!() in a test
1 parent 751ce6d commit a1518d1

File tree

1 file changed

+46
-1
lines changed

1 file changed

+46
-1
lines changed

src/wallet/mod.rs

Lines changed: 46 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2237,7 +2237,6 @@ pub(crate) mod test {
22372237
.drain_to(drain_addr.script_pubkey())
22382238
.drain_wallet();
22392239
let (psbt, details) = builder.finish().unwrap();
2240-
dbg!(&psbt);
22412240
let outputs = psbt.unsigned_tx.output;
22422241

22432242
assert_eq!(outputs.len(), 2);
@@ -3834,6 +3833,52 @@ pub(crate) mod test {
38343833
assert_eq!(details.fee.unwrap_or(0), 250);
38353834
}
38363835

3836+
#[test]
3837+
#[should_panic(expected = "InsufficientFunds")]
3838+
fn test_bump_fee_unconfirmed_inputs_only() {
3839+
// We try to bump the fee, but:
3840+
// - We can't reduce the change, as we have no change
3841+
// - All our UTXOs are unconfirmed
3842+
// So, we fail with "InsufficientFunds", as per RBF rule 2:
3843+
// The replacement transaction may only include an unconfirmed input
3844+
// if that input was included in one of the original transactions.
3845+
let (wallet, descriptors, _) = get_funded_wallet(get_test_wpkh());
3846+
let addr = Address::from_str("2N1Ffz3WaNzbeLFBb51xyFMHYSEUXcbiSoX").unwrap();
3847+
let mut builder = wallet.build_tx();
3848+
builder
3849+
.drain_wallet()
3850+
.drain_to(addr.script_pubkey())
3851+
.enable_rbf();
3852+
let (psbt, mut original_details) = builder.finish().unwrap();
3853+
// Now we receive one transaction with 0 confirmations. We won't be able to use that for
3854+
// fee bumping, as it's still unconfirmed!
3855+
crate::populate_test_db!(
3856+
wallet.database.borrow_mut(),
3857+
testutils! (@tx ( (@external descriptors, 0) => 6969 ) (@confirmations 0)),
3858+
Some(100),
3859+
);
3860+
let mut tx = psbt.extract_tx();
3861+
let txid = tx.txid();
3862+
for txin in &mut tx.input {
3863+
txin.witness.push([0x00; 108]); // fake signature
3864+
wallet
3865+
.database
3866+
.borrow_mut()
3867+
.del_utxo(&txin.previous_output)
3868+
.unwrap();
3869+
}
3870+
original_details.transaction = Some(tx);
3871+
wallet
3872+
.database
3873+
.borrow_mut()
3874+
.set_tx(&original_details)
3875+
.unwrap();
3876+
3877+
let mut builder = wallet.build_fee_bump(txid).unwrap();
3878+
builder.fee_rate(FeeRate::from_sat_per_vb(25.0));
3879+
builder.finish().unwrap();
3880+
}
3881+
38373882
#[test]
38383883
fn test_sign_single_xprv() {
38393884
let (wallet, _, _) = get_funded_wallet("wpkh(tprv8ZgxMBicQKsPd3EupYiPRhaMooHKUHJxNsTfYuScep13go8QFfHdtkG9nRkFGb7busX4isf6X9dURGCoKgitaApQ6MupRhZMcELAxTBRJgS/*)");

0 commit comments

Comments
 (0)