Skip to content

Commit d796c51

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 38ceae7 commit d796c51

1 file changed

Lines changed: 25 additions & 0 deletions

File tree

src/liquidity/client/lsps2/state.rs

Lines changed: 25 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -636,6 +636,31 @@ mod tests {
636636
);
637637
}
638638

639+
#[test]
640+
fn payment_leases_roundtrip() {
641+
let lease = lease(2, 48, 100, Some(1_000), now_secs() + MIN_LEASE_REMAINING_SECS + 60);
642+
643+
let encoded = lease.encode();
644+
let decoded = PaymentLease::read(&mut &encoded[..]).unwrap();
645+
646+
assert_eq!(decoded, lease);
647+
}
648+
649+
#[test]
650+
fn fixed_and_variable_lease_pools_are_isolated() {
651+
let valid_until = now_secs() + MIN_LEASE_REMAINING_SECS + 60;
652+
let fixed = lease(2, 49, 100, Some(1_000), valid_until);
653+
let variable = lease(3, 50, 50, None, valid_until);
654+
let mut state = LSPS2LeaseState::from_leases(vec![fixed.clone(), variable.clone()]);
655+
656+
let (selected_fixed, _) = state.fixed_amount(1_000, None).unwrap();
657+
assert_eq!(selected_fixed.id, fixed.id);
658+
assert!(state.fixed_amount(1_000, None).is_none());
659+
660+
let (selected_variable, _) = state.variable_amount(None, None).unwrap();
661+
assert_eq!(selected_variable.id, variable.id);
662+
}
663+
639664
#[test]
640665
fn prunes_leases_close_to_expiry() {
641666
let lease = lease(2, 43, 1, Some(1_000), now_secs() + MIN_CACHED_LEASE_REMAINING_SECS - 1);

0 commit comments

Comments
 (0)