Skip to content

Commit 420625c

Browse files
committed
test: add test_legacy_bump_fee_add_input()
1 parent 95522c1 commit 420625c

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
@@ -2515,6 +2515,78 @@ fn test_bump_fee_add_input() {
25152515
assert_fee_rate!(psbt, fee.unwrap_or(Amount::ZERO), FeeRate::from_sat_per_vb_unchecked(50), @add_signature);
25162516
}
25172517

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

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

0 commit comments

Comments
 (0)