Skip to content

test: add clock-rollover regression tests at u64 boundary#1677

Open
senmalong wants to merge 2 commits into
QuickLendX:mainfrom
senmalong:test/clock-rollover-regression-1585
Open

test: add clock-rollover regression tests at u64 boundary#1677
senmalong wants to merge 2 commits into
QuickLendX:mainfrom
senmalong:test/clock-rollover-regression-1585

Conversation

@senmalong

Copy link
Copy Markdown
Contributor

Summary

Implements the regression test suite requested in issue #1585. Adds quicklendx-contracts/src/test_clock_rollover.rs and wires it into lib.rs with #[cfg(test)] (always-on, no feature flag required).

What is covered

Area Happy-path Sad-path
Invoice::is_overdue not overdue at exact u64::MAX; safe after rollover to 0 overdue when due_date is small and clock is near MAX
Invoice::grace_deadline saturates at u64::MAX from near-MAX due_date
Invoice::grace_deadline saturates when due_date == u64::MAX and any grace period > 0
Bid::default_expiration saturates at u64::MAX
Bid::is_expired not expired at exact u64::MAX boundary expired for small expiry near MAX
invoice creation (contract) accepted at u64::MAX - 1 ledger / u64::MAX due_date rejected when due_date == now == u64::MAX
invoice state (contract) overdue query safe after simulated rollover
bid placement (contract) expiration saturated when placed near u64::MAX
cleanup (contract) no bid removed at exact saturated boundary

18 tests total — 8 pure-logic (no contract round-trip) and 10 integration (full contract calls).

Design decisions

  • All deterministic: timestamps set via env.ledger().set_timestamp() and env.as_contract(). No Date::now() or random values.
  • Test names are assertive: e.g. invoice_not_overdue_when_due_date_equals_u64_max.
  • Always-on: the module is declared with plain #[cfg(test)], not behind legacy-tests or fuzz-tests, so it runs on every CI matrix entry.

Pre-existing failures

The codebase already has 22 compilation errors in unrelated files (verification.rs, lib.rs, test_invoice_search_ranking.rs, types.rs). These are not introduced by this PR and block cargo test for all tests on the current branch; they will need to be fixed separately.

Testing

# Run just the new tests (once pre-existing compile errors are resolved)
cargo test -p quicklendx-contracts test_clock_rollover

# Full suite
cargo test -p quicklendx-contracts

# Lint
cargo clippy --workspace --all-targets -- -D warnings

# WASM build verification
cargo build --target wasm32-unknown-unknown --release

Closes #1585

…#1585)

Cover behaviour at u64::MAX - 1, u64::MAX, and after a simulated rollover
back to 0 for all time-sensitive contract paths:

- Invoice::is_overdue  – not overdue at exact u64::MAX; safe after rollover to 0
- Invoice::grace_deadline – saturating_add never wraps at u64::MAX boundary
- Bid::default_expiration – saturates to u64::MAX when now is near MAX
- Bid::is_expired – strict > semantics preserved at u64::MAX and post-rollover
- store_invoice (contract) – accepted at NEAR_MAX ledger / u64::MAX due_date;
  rejected when due_date == now == u64::MAX
- upload_invoice + place_bid (contract) – expiration_timestamp saturated when
  placed at u64::MAX - 1; cleanup leaves the bid intact at exact boundary

18 deterministic unit and integration tests, no std calls, no Date.now() /
Math.random(). All tests run in default cargo test (not behind a feature flag).

Closes QuickLendX#1585
@drips-wave

drips-wave Bot commented Jun 26, 2026

Copy link
Copy Markdown

@senmalong 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

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 a clock-rollover regression test

1 participant