Skip to content

Commit

Permalink
test: Document test_bump_fee_add_input_change_dust
Browse files Browse the repository at this point in the history
Add a rationale for the feerate in the test
  • Loading branch information
danielabrozzoni committed Jul 21, 2022
1 parent 4b805ff commit 2de264e
Showing 1 changed file with 15 additions and 1 deletion.
16 changes: 15 additions & 1 deletion src/wallet/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -3714,6 +3714,7 @@ pub(crate) mod test {
.del_utxo(&txin.previous_output)
.unwrap();
}
let original_tx_weight = tx.weight();
original_details.transaction = Some(tx);
wallet
.database
Expand All @@ -3722,7 +3723,20 @@ pub(crate) mod test {
.unwrap();

let mut builder = wallet.build_fee_bump(txid).unwrap();
builder.fee_rate(FeeRate::from_sat_per_vb(142.0));
// We set a fee high enough that during rbf we are forced to add
// a new input and also that we have to remove the change
// that we had previously

// We calculate the new weight as:
// original weight
// + extra input weight: 160 WU = (32 (prevout) + 4 (vout) + 4 (nsequence)) * 4
// + input satisfaction weight: 114 WU = 108 (witness) + 2 (witness len) + (1 (script len)) * 4
// - change output weight: 124 WU = (8 (value) + 1 (script len) + 22 (script)) * 4
let new_tx_weight = original_tx_weight + 160 + 111 - 124;
// two inputs (50k, 25k) and one output (45k) - epsilon
// We use epsilon here to avoid asking for a slightly too high feerate
let fee_abs = 50_000 + 25_000 - 45_000 - 10;
builder.fee_rate(FeeRate::from_wu(fee_abs, new_tx_weight));
let (psbt, details) = builder.finish().unwrap();

assert_eq!(
Expand Down

0 comments on commit 2de264e

Please sign in to comment.