Skip to content

Commit 621fd3d

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 4190e2f commit 621fd3d

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
@@ -567,6 +567,32 @@ mod tests {
567567
assert!(state.valid(&id).is_none());
568568
}
569569

570+
#[test]
571+
fn payment_leases_roundtrip() {
572+
let lease = lease(2, 48, 100, Some(1_000), now_secs() + MIN_LEASE_REMAINING_SECS + 60);
573+
574+
let encoded = lease.encode();
575+
let decoded = PaymentLease::read(&mut &encoded[..]).unwrap();
576+
577+
assert_eq!(decoded, lease);
578+
}
579+
580+
#[test]
581+
fn fixed_and_variable_lease_pools_are_isolated() {
582+
let valid_until = now_secs() + MIN_LEASE_REMAINING_SECS + 60;
583+
let fixed = lease(2, 49, 100, Some(1_000), valid_until);
584+
let variable = lease(3, 50, 50, None, valid_until);
585+
let mut state = LSPS2LeaseState::from_leases(vec![fixed.clone(), variable.clone()]);
586+
587+
let (selected_fixed, _) = state.fixed_amount(1_000, None).unwrap();
588+
assert_eq!(selected_fixed.id, fixed.id);
589+
state.remove(&selected_fixed.id);
590+
assert!(state.fixed_amount(1_000, None).is_none());
591+
592+
let (selected_variable, _) = state.variable_amount(None, None).unwrap();
593+
assert_eq!(selected_variable.id, variable.id);
594+
}
595+
570596
#[test]
571597
fn prunes_leases_close_to_expiry() {
572598
let lease = lease(2, 43, 1, Some(1_000), now_secs() + MIN_LEASE_REMAINING_SECS - 1);

0 commit comments

Comments
 (0)