Skip to content

Commit 5157243

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 ab58cf4 commit 5157243

1 file changed

Lines changed: 27 additions & 0 deletions

File tree

src/liquidity/client/lsps2/state.rs

Lines changed: 27 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -663,6 +663,33 @@ mod tests {
663663
);
664664
}
665665

666+
#[test]
667+
fn payment_leases_roundtrip() {
668+
let lease =
669+
lease(2, 48, 100, Some(1_000), now_secs() + MIN_CACHED_LEASE_REMAINING_SECS + 60);
670+
671+
let encoded = lease.encode();
672+
let decoded = PaymentLease::read(&mut &encoded[..]).unwrap();
673+
674+
assert_eq!(decoded, lease);
675+
}
676+
677+
#[test]
678+
fn fixed_and_variable_lease_pools_are_isolated() {
679+
let valid_until = now_secs() + MIN_CACHED_LEASE_REMAINING_SECS + 60;
680+
let fixed = lease(2, 49, 100, Some(1_000), valid_until);
681+
let variable = lease(3, 50, 50, None, valid_until);
682+
let available_lsps = [fixed.id.lsp_node_id, variable.id.lsp_node_id];
683+
let mut state = LSPS2LeaseState::from_leases(vec![fixed.clone(), variable.clone()]);
684+
685+
let (selected_fixed, _) = state.fixed_amount(1_000, None, 1, &available_lsps).unwrap();
686+
assert_eq!(selected_fixed.id, fixed.id);
687+
assert!(state.fixed_amount(1_000, None, 1, &available_lsps).is_none());
688+
689+
let (selected_variable, _) = state.variable_amount(None, None, 1, &available_lsps).unwrap();
690+
assert_eq!(selected_variable.id, variable.id);
691+
}
692+
666693
#[test]
667694
fn prunes_leases_close_to_expiry() {
668695
let lease = lease(2, 43, 1, Some(1_000), now_secs() + MIN_CACHED_LEASE_REMAINING_SECS - 1);

0 commit comments

Comments
 (0)