Skip to content

Commit 27c34ef

Browse files
committed
lsps2: Test payment lease state
Pin the direct lease serialization format and ensure fixed-amount and variable-amount caches remain isolated. These focused checks complement the end-to-end BOLT11 and BOLT12 coverage. Co-Authored-By: HAL 9000
1 parent 5712376 commit 27c34ef

1 file changed

Lines changed: 26 additions & 0 deletions

File tree

src/liquidity/client/lsps2/state.rs

Lines changed: 26 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -470,6 +470,32 @@ mod tests {
470470
assert!(state.valid(&id).is_none());
471471
}
472472

473+
#[test]
474+
fn payment_leases_roundtrip() {
475+
let lease = lease(2, 48, 100, Some(1_000), now_secs() + MIN_LEASE_REMAINING_SECS + 60);
476+
477+
let encoded = lease.encode();
478+
let decoded = PaymentLease::read(&mut &encoded[..]).unwrap();
479+
480+
assert_eq!(decoded, lease);
481+
}
482+
483+
#[test]
484+
fn fixed_and_variable_lease_pools_are_isolated() {
485+
let valid_until = now_secs() + MIN_LEASE_REMAINING_SECS + 60;
486+
let fixed = lease(2, 49, 100, Some(1_000), valid_until);
487+
let variable = lease(3, 50, 50, None, valid_until);
488+
let mut state = LSPS2LeaseState::from_leases(vec![fixed.clone(), variable.clone()]);
489+
490+
let (selected_fixed, _) = state.fixed_amount(1_000, None).unwrap();
491+
assert_eq!(selected_fixed.id, fixed.id);
492+
state.remove(&selected_fixed.id);
493+
assert!(state.fixed_amount(1_000, None).is_none());
494+
495+
let (selected_variable, _) = state.variable_amount(None).unwrap();
496+
assert_eq!(selected_variable.id, variable.id);
497+
}
498+
473499
#[test]
474500
fn prunes_leases_close_to_expiry() {
475501
let lease = lease(2, 43, 1, Some(1_000), now_secs() + MIN_LEASE_REMAINING_SECS - 1);

0 commit comments

Comments
 (0)