Skip to content

Commit dbd5a7b

Browse files
committed
test: add test_legacy_bump_fee_add_input()
1 parent 50933c0 commit dbd5a7b

File tree

1 file changed

+72
-0
lines changed

1 file changed

+72
-0
lines changed

wallet/tests/wallet.rs

+72
Original file line numberDiff line numberDiff line change
@@ -2494,6 +2494,78 @@ fn test_bump_fee_add_input() {
24942494
assert_fee_rate!(psbt, fee.unwrap_or(Amount::ZERO), FeeRate::from_sat_per_vb_unchecked(50), @add_signature);
24952495
}
24962496

2497+
#[test]
2498+
fn test_legacy_bump_fee_add_input() {
2499+
let (mut wallet, _) = get_funded_wallet(get_test_pkh(), None);
2500+
let init_tx = Transaction {
2501+
version: transaction::Version::ONE,
2502+
lock_time: absolute::LockTime::ZERO,
2503+
input: vec![],
2504+
output: vec![TxOut {
2505+
script_pubkey: wallet
2506+
.next_unused_address(KeychainKind::External)
2507+
.script_pubkey(),
2508+
value: Amount::from_sat(25_000),
2509+
}],
2510+
};
2511+
let txid = init_tx.compute_txid();
2512+
let pos: ChainPosition<ConfirmationBlockTime> =
2513+
wallet.transactions().last().unwrap().chain_position;
2514+
insert_tx(&mut wallet, init_tx);
2515+
match pos {
2516+
ChainPosition::Confirmed { anchor, .. } => insert_anchor(&mut wallet, txid, anchor),
2517+
other => panic!("all wallet txs must be confirmed: {:?}", other),
2518+
}
2519+
2520+
let addr = Address::from_str("2N1Ffz3WaNzbeLFBb51xyFMHYSEUXcbiSoX")
2521+
.unwrap()
2522+
.assume_checked();
2523+
let mut builder = wallet.build_tx().coin_selection(LargestFirstCoinSelection);
2524+
builder.add_recipient(addr.script_pubkey(), Amount::from_sat(45_000));
2525+
let psbt = builder.finish().unwrap();
2526+
let tx = psbt.extract_tx().expect("failed to extract tx");
2527+
let original_details = wallet.sent_and_received(&tx);
2528+
let txid = tx.compute_txid();
2529+
insert_tx(&mut wallet, tx);
2530+
2531+
let mut builder = wallet.build_fee_bump(txid).unwrap();
2532+
builder.fee_rate(FeeRate::from_sat_per_vb_unchecked(50));
2533+
let psbt = builder.finish().unwrap();
2534+
let sent_received =
2535+
wallet.sent_and_received(&psbt.clone().extract_tx().expect("failed to extract tx"));
2536+
let fee = check_fee!(wallet, psbt);
2537+
assert_eq!(
2538+
sent_received.0,
2539+
original_details.0 + Amount::from_sat(25_000)
2540+
);
2541+
assert_eq!(
2542+
fee.unwrap_or(Amount::ZERO) + sent_received.1,
2543+
Amount::from_sat(30_000)
2544+
);
2545+
2546+
let tx = &psbt.unsigned_tx;
2547+
assert_eq!(tx.input.len(), 2);
2548+
assert_eq!(tx.output.len(), 2);
2549+
assert_eq!(
2550+
tx.output
2551+
.iter()
2552+
.find(|txout| txout.script_pubkey == addr.script_pubkey())
2553+
.unwrap()
2554+
.value,
2555+
Amount::from_sat(45_000)
2556+
);
2557+
assert_eq!(
2558+
tx.output
2559+
.iter()
2560+
.find(|txout| txout.script_pubkey != addr.script_pubkey())
2561+
.unwrap()
2562+
.value,
2563+
sent_received.1
2564+
);
2565+
2566+
assert_fee_rate!(psbt, fee.unwrap_or(Amount::ZERO), FeeRate::from_sat_per_vb_unchecked(50), @add_signature);
2567+
}
2568+
24972569
#[test]
24982570
fn test_bump_fee_absolute_add_input() {
24992571
let (mut wallet, _) = get_funded_wallet_wpkh();

0 commit comments

Comments
 (0)