Skip to content

Fix get freshness lag calculation#1659

Merged
Baskarayelu merged 2 commits into
QuickLendX:mainfrom
samlogy1:fix-get-freshness-lag-calculation
Jun 27, 2026
Merged

Fix get freshness lag calculation#1659
Baskarayelu merged 2 commits into
QuickLendX:mainfrom
samlogy1:fix-get-freshness-lag-calculation

Conversation

@samlogy1

Copy link
Copy Markdown
Contributor

closes #1541

📝 Description

Adds a test suite for get_freshness lag calculations (Issue #1541). Covers lag at zero, lag at positive, and lag during pause. All tests use plain #[cfg(test)] — no feature gate — so they run on every CI matrix entry.

🎯 Type of Change

  • Other: Test coverage — get_freshness lag calculation lock-in

🔧 Changes Made

Files Modified

  • quicklendx-contracts/src/lib.rs — registered new test module

New Files Added

  • quicklendx-contracts/src/test_freshness_lag.rs — 13 tests for lag at zero, positive, and during pause

Key Changes

  • Zero lag when indexed timestamp matches current ledger time
  • Positive lag equals exact elapsed seconds (current − indexed)
  • get_freshness remains callable while paused and returns correct lag
  • Lag accumulates correctly during pause and is not reset by unpause
  • Drift boundary: 120 s = fresh, 121 s = stale
  • Sad path: future indexed timestamp returns negative lag (clock skew), not stale

🧪 Testing

  • Unit tests pass
  • No breaking changes introduced
  • Edge cases tested

Test Coverage

13 deterministic tests — no Date.now() or random values. Ledger timestamp is fixed in every test via env.ledger().set_timestamp().

📋 Contract-Specific Checks

  • Soroban contract builds successfully
  • WASM compilation works
  • Contract functions tested
  • Access control verified

Contract Testing Details

Pause tests call initialize_admin then client.pause(&admin) to exercise the real pause path. No std:: calls introduced. #![no_std] discipline preserved.

🔍 Code Quality

  • Clippy warnings addressed
  • No unused imports or variables
  • Complex logic is commented

🔗 Related Issues

Closes #1541

🧪 How to Test

  1. Run the new tests:
  2. Run Clippy:
  3. Verify WASM build:

⚠️ Breaking Changes

None. Only new test code added — no production logic or APIs modified.

@drips-wave

drips-wave Bot commented Jun 26, 2026

Copy link
Copy Markdown

@samlogy1 Great news! 🎉 Based on an automated assessment of this PR, the linked Wave issue(s) no longer count against your application limits.

You can now already apply to more issues while waiting for a review of this PR. Keep up the great work! 🚀

Learn more about application limits

@Baskarayelu

Copy link
Copy Markdown
Contributor

Fix get freshness lag calculation — great addition. merging 👍

@Baskarayelu Baskarayelu merged commit 5aacb2a into QuickLendX:main Jun 27, 2026
1 check failed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Add tests for get_freshness lag calculations

2 participants