Skip to content

Commit 4c963d9

Browse files
committed
test: add test_legacy_bump_fee_add_input()
1 parent 6c2e5a5 commit 4c963d9

File tree

1 file changed

+126
-0
lines changed

1 file changed

+126
-0
lines changed

wallet/tests/wallet.rs

Lines changed: 126 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2511,6 +2511,78 @@ fn test_bump_fee_add_input() {
25112511
assert_fee_rate!(psbt, fee.unwrap_or(Amount::ZERO), FeeRate::from_sat_per_vb_unchecked(50), @add_signature);
25122512
}
25132513

2514+
#[test]
2515+
fn test_legacy_bump_fee_add_input() {
2516+
let (mut wallet, _) = get_funded_wallet_single(get_test_pkh());
2517+
let init_tx = Transaction {
2518+
version: transaction::Version::ONE,
2519+
lock_time: absolute::LockTime::ZERO,
2520+
input: vec![],
2521+
output: vec![TxOut {
2522+
script_pubkey: wallet
2523+
.next_unused_address(KeychainKind::External)
2524+
.script_pubkey(),
2525+
value: Amount::from_sat(25_000),
2526+
}],
2527+
};
2528+
let txid = init_tx.compute_txid();
2529+
let pos: ChainPosition<ConfirmationBlockTime> =
2530+
wallet.transactions().last().unwrap().chain_position;
2531+
insert_tx(&mut wallet, init_tx);
2532+
match pos {
2533+
ChainPosition::Confirmed { anchor, .. } => insert_anchor(&mut wallet, txid, anchor),
2534+
other => panic!("all wallet txs must be confirmed: {:?}", other),
2535+
}
2536+
2537+
let addr = Address::from_str("2N1Ffz3WaNzbeLFBb51xyFMHYSEUXcbiSoX")
2538+
.unwrap()
2539+
.assume_checked();
2540+
let mut builder = wallet.build_tx().coin_selection(LargestFirstCoinSelection);
2541+
builder.add_recipient(addr.script_pubkey(), Amount::from_sat(45_000));
2542+
let psbt = builder.finish().unwrap();
2543+
let tx = psbt.extract_tx().expect("failed to extract tx");
2544+
let original_details = wallet.sent_and_received(&tx);
2545+
let txid = tx.compute_txid();
2546+
insert_tx(&mut wallet, tx);
2547+
2548+
let mut builder = wallet.build_fee_bump(txid).unwrap();
2549+
builder.fee_rate(FeeRate::from_sat_per_vb_unchecked(50));
2550+
let psbt = builder.finish().unwrap();
2551+
let sent_received =
2552+
wallet.sent_and_received(&psbt.clone().extract_tx().expect("failed to extract tx"));
2553+
let fee = check_fee!(wallet, psbt);
2554+
assert_eq!(
2555+
sent_received.0,
2556+
original_details.0 + Amount::from_sat(25_000)
2557+
);
2558+
assert_eq!(
2559+
fee.unwrap_or(Amount::ZERO) + sent_received.1,
2560+
Amount::from_sat(30_000)
2561+
);
2562+
2563+
let tx = &psbt.unsigned_tx;
2564+
assert_eq!(tx.input.len(), 2);
2565+
assert_eq!(tx.output.len(), 2);
2566+
assert_eq!(
2567+
tx.output
2568+
.iter()
2569+
.find(|txout| txout.script_pubkey == addr.script_pubkey())
2570+
.unwrap()
2571+
.value,
2572+
Amount::from_sat(45_000)
2573+
);
2574+
assert_eq!(
2575+
tx.output
2576+
.iter()
2577+
.find(|txout| txout.script_pubkey != addr.script_pubkey())
2578+
.unwrap()
2579+
.value,
2580+
sent_received.1
2581+
);
2582+
2583+
assert_fee_rate_legacy!(psbt, fee.unwrap_or(Amount::ZERO), FeeRate::from_sat_per_vb_unchecked(50), @add_signature);
2584+
}
2585+
25142586
#[test]
25152587
fn test_bump_fee_absolute_add_input() {
25162588
let (mut wallet, _) = get_funded_wallet_wpkh();
@@ -2565,6 +2637,60 @@ fn test_bump_fee_absolute_add_input() {
25652637
assert_eq!(fee.unwrap_or(Amount::ZERO), Amount::from_sat(6_000));
25662638
}
25672639

2640+
#[test]
2641+
fn test_legacy_bump_fee_absolute_add_input() {
2642+
let (mut wallet, _) = get_funded_wallet_single(get_test_pkh());
2643+
receive_output_in_latest_block(&mut wallet, 25_000);
2644+
let addr = Address::from_str("2N1Ffz3WaNzbeLFBb51xyFMHYSEUXcbiSoX")
2645+
.unwrap()
2646+
.assume_checked();
2647+
let mut builder = wallet.build_tx().coin_selection(LargestFirstCoinSelection);
2648+
builder.add_recipient(addr.script_pubkey(), Amount::from_sat(45_000));
2649+
let psbt = builder.finish().unwrap();
2650+
let tx = psbt.extract_tx().expect("failed to extract tx");
2651+
let (original_sent, _original_received) = wallet.sent_and_received(&tx);
2652+
let txid = tx.compute_txid();
2653+
insert_tx(&mut wallet, tx);
2654+
2655+
let mut builder = wallet.build_fee_bump(txid).unwrap();
2656+
builder.fee_absolute(Amount::from_sat(6_000));
2657+
let psbt = builder.finish().unwrap();
2658+
let (sent, received) =
2659+
wallet.sent_and_received(&psbt.clone().extract_tx().expect("failed to extract tx"));
2660+
let fee = check_fee!(wallet, psbt);
2661+
2662+
assert_eq!(
2663+
sent,
2664+
original_sent + Amount::from_sat(25_000)
2665+
);
2666+
assert_eq!(
2667+
fee.unwrap_or(Amount::ZERO) + received,
2668+
Amount::from_sat(30_000)
2669+
);
2670+
2671+
let tx = &psbt.unsigned_tx;
2672+
assert_eq!(tx.input.len(), 2);
2673+
assert_eq!(tx.output.len(), 2);
2674+
assert_eq!(
2675+
tx.output
2676+
.iter()
2677+
.find(|txout| txout.script_pubkey == addr.script_pubkey())
2678+
.unwrap()
2679+
.value,
2680+
Amount::from_sat(45_000)
2681+
);
2682+
assert_eq!(
2683+
tx.output
2684+
.iter()
2685+
.find(|txout| txout.script_pubkey != addr.script_pubkey())
2686+
.unwrap()
2687+
.value,
2688+
received
2689+
);
2690+
2691+
assert_eq!(fee.unwrap_or(Amount::ZERO), Amount::from_sat(6_000));
2692+
}
2693+
25682694
#[test]
25692695
fn test_bump_fee_no_change_add_input_and_change() {
25702696
let (mut wallet, _) = get_funded_wallet_wpkh();

0 commit comments

Comments
 (0)