Skip to content

Commit fc05da7

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 5bc7026 commit fc05da7

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
@@ -443,6 +443,32 @@ mod tests {
443443
assert!(state.valid(&id).is_none());
444444
}
445445

446+
#[test]
447+
fn payment_leases_roundtrip() {
448+
let lease = lease(2, 48, 100, Some(1_000), now_secs() + MIN_LEASE_REMAINING_SECS + 60);
449+
450+
let encoded = lease.encode();
451+
let decoded = PaymentLease::read(&mut &encoded[..]).unwrap();
452+
453+
assert_eq!(decoded, lease);
454+
}
455+
456+
#[test]
457+
fn fixed_and_variable_lease_pools_are_isolated() {
458+
let valid_until = now_secs() + MIN_LEASE_REMAINING_SECS + 60;
459+
let fixed = lease(2, 49, 100, Some(1_000), valid_until);
460+
let variable = lease(3, 50, 50, None, valid_until);
461+
let mut state = LSPS2LeaseState::from_leases(vec![fixed.clone(), variable.clone()]);
462+
463+
let (selected_fixed, _) = state.fixed_amount(1_000, None).unwrap();
464+
assert_eq!(selected_fixed.id, fixed.id);
465+
state.remove(&selected_fixed.id);
466+
assert!(state.fixed_amount(1_000, None).is_none());
467+
468+
let (selected_variable, _) = state.variable_amount(None, None).unwrap();
469+
assert_eq!(selected_variable.id, variable.id);
470+
}
471+
446472
#[test]
447473
fn prunes_leases_close_to_expiry() {
448474
let lease = lease(2, 43, 1, Some(1_000), now_secs() + MIN_LEASE_REMAINING_SECS - 1);

0 commit comments

Comments
 (0)