Skip to content

test(web): add deterministic Drand countdown boundary tests - #186

Open
ogundeleoluwaferanmi35 wants to merge 1 commit into
Sub-Rosa-Issue:mainfrom
ogundeleoluwaferanmi35:feat/drand-countdown-tests
Open

test(web): add deterministic Drand countdown boundary tests#186
ogundeleoluwaferanmi35 wants to merge 1 commit into
Sub-Rosa-Issue:mainfrom
ogundeleoluwaferanmi35:feat/drand-countdown-tests

Conversation

@ogundeleoluwaferanmi35

Copy link
Copy Markdown

Summary

Extract the Drand countdown calculation into a pure `computeCountdown` helper and add deterministic boundary tests with fixed timestamps.

What changed

  • `useDrandCountdown.ts` — Extracted `computeCountdown(targetRound, nowSecs, genesis, period)` as an exported pure function. Refactored both `localCountdown` (offline quicknet fallback) and the live chain info path inside `useDrandCountdown` to reuse it. Removed the now-unnecessary `timeOfRound` helper.
  • `useDrandCountdown.test.ts` — New Node-based test file with no browser, no live Drand call, and no real timers:
    • `computeCountdown`: one second before R, exactly at R, after R, published round (secondsRemaining: 0), future round (correct targetTime + remaining seconds)
    • `formatCountdown`: zero, negative, single seconds, minutes, exactly one minute, exactly one hour, hours with minutes + seconds, large values (24h 30m 45s)
  • `package.json` — Added the new test file to the `test` script.

Key design decisions

  • The pure helper accepts all time inputs explicitly (`nowSecs`, `genesis`, `period`) so tests can pin the wall clock without mocking `Date.now()`.
  • The existing UI, polling cadence, and `formatCountdown` signature are unchanged.

Acceptance criteria checklist

  • Tests cover one second before R, exactly at R, and after R
  • Published rounds report `secondsRemaining: 0`
  • Future rounds report the correct target time and remaining seconds
  • `formatCountdown` has boundary cases for seconds, minutes, and hours
  • The new test is included in `pnpm web:test`; `web typecheck` passes

Test output

```
ℹ tests 64
ℹ pass 64
ℹ fail 0
ℹ duration_ms 6719.737373
```

Typecheck

`pnpm --filter @sub-rosa/web typecheck` passes cleanly.

Closes #174

Extract a pure computeCountdown helper that accepts target round, current
time, genesis, and period, making the countdown calculation deterministic
and testable. Reuse it in both localCountdown (offline quicknet fallback)
and the live chain info path inside useDrandCountdown.

Tests cover one second before R, exactly at R, after R, published rounds,
future rounds, and formatCountdown boundary cases (seconds/minutes/hours).

Closes Sub-Rosa-Issue#174
@drips-wave

drips-wave Bot commented Jul 30, 2026

Copy link
Copy Markdown

@ogundeleoluwaferanmi35 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.

web: add deterministic Drand countdown boundary tests

1 participant