Skip to content

Commit 95522c1

Browse files
committed
test: add test_legacy_bump_fee_drain_wallet()
1 parent 7813ebe commit 95522c1

File tree

1 file changed

+56
-0
lines changed

1 file changed

+56
-0
lines changed

wallet/tests/wallet.rs

Lines changed: 56 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2329,6 +2329,62 @@ fn test_bump_fee_drain_wallet() {
23292329
assert_eq!(sent_received.0, Amount::from_sat(75_000));
23302330
}
23312331

2332+
#[test]
2333+
fn test_legacy_bump_fee_drain_wallet() {
2334+
let (mut wallet, _) = get_funded_wallet_single(get_test_pkh());
2335+
// receive an extra tx so that our wallet has two utxos.
2336+
let tx = Transaction {
2337+
version: transaction::Version::ONE,
2338+
lock_time: absolute::LockTime::ZERO,
2339+
input: vec![],
2340+
output: vec![TxOut {
2341+
value: Amount::from_sat(25_000),
2342+
script_pubkey: wallet
2343+
.next_unused_address(KeychainKind::External)
2344+
.script_pubkey(),
2345+
}],
2346+
};
2347+
let txid = tx.compute_txid();
2348+
insert_tx(&mut wallet, tx.clone());
2349+
let anchor = ConfirmationBlockTime {
2350+
block_id: wallet.latest_checkpoint().block_id(),
2351+
confirmation_time: 42_000,
2352+
};
2353+
insert_anchor(&mut wallet, txid, anchor);
2354+
2355+
let addr = Address::from_str("2N1Ffz3WaNzbeLFBb51xyFMHYSEUXcbiSoX")
2356+
.unwrap()
2357+
.assume_checked();
2358+
2359+
let mut builder = wallet.build_tx();
2360+
builder
2361+
.drain_to(addr.script_pubkey())
2362+
.add_utxo(OutPoint {
2363+
txid: tx.compute_txid(),
2364+
vout: 0,
2365+
})
2366+
.unwrap()
2367+
.manually_selected_only();
2368+
let psbt = builder.finish().unwrap();
2369+
let tx = psbt.extract_tx().expect("failed to extract tx");
2370+
let original_sent_received = wallet.sent_and_received(&tx);
2371+
2372+
let txid = tx.compute_txid();
2373+
insert_tx(&mut wallet, tx);
2374+
assert_eq!(original_sent_received.0, Amount::from_sat(25_000));
2375+
2376+
// for the new feerate, it should be enough to reduce the output, but since we specify
2377+
// `drain_wallet` we expect to spend everything
2378+
let mut builder = wallet.build_fee_bump(txid).unwrap();
2379+
builder
2380+
.drain_wallet()
2381+
.fee_rate(FeeRate::from_sat_per_vb_unchecked(5));
2382+
let psbt = builder.finish().unwrap();
2383+
let sent_received = wallet.sent_and_received(&psbt.extract_tx().expect("failed to extract tx"));
2384+
2385+
assert_eq!(sent_received.0, Amount::from_sat(75_000));
2386+
}
2387+
23322388
#[test]
23332389
#[should_panic(expected = "InsufficientFunds")]
23342390
fn test_bump_fee_remove_output_manually_selected_only() {

0 commit comments

Comments
 (0)