refactor(contract): extract daily-reset check into shared helper with boundary tests#184
Conversation
…d boundary tests Closes Stellar-Ecosystem#50 get_policy, check_spending_allowed, record_payment, and update_policy each inlined the same 'now >= last_reset_ledger + DAY_LEDGERS' check independently with no shared abstraction and no test coverage. Changes: - Added is_new_day(now: u64, last_reset_ledger: u64) -> bool free function above the contract impl block - Replaced all four inline occurrences with is_new_day(now, ...) - Added #[cfg(test)] module with 5 boundary tests: - one ledger before threshold (no reset) - exactly at threshold (reset) - one ledger past threshold (reset) - same ledger as reset (no reset) - multiple days past threshold (reset)
|
Warning Review limit reached
More reviews will be available in 1 minute and 17 seconds. Learn how PR review limits work. To continue reviewing without waiting, enable usage-based billing in the billing tab. ⌛ How to resolve this issue?After more reviews become available, a review can be triggered using the To avoid repeated limits, reduce automatic review volume by pausing incremental auto-reviews earlier, using label-based review opt-in, excluding WIP or generated PR titles, or requesting reviews manually when the PR is ready. If your team needs uninterrupted high-volume reviews, an organization admin can enable usage-based credits. 🚦 How do rate limits work?CodeRabbit enforces per-developer PR review limits for each organization. Most developers receive the normal plan refill rate. For paid Pro and Pro+ PR reviews, CodeRabbit uses adaptive limits for sustained high-volume activity. When a developer's recent PR review activity reaches the 95th percentile or higher among CodeRabbit users, the refill rate gradually slows as usage increases. The highest same-day bursts are limited more strictly. Please see our Fair Usage Limits Policy for further information. ℹ️ Review info⚙️ Run configurationConfiguration used: defaults Review profile: CHILL Plan: Pro Plus Run ID: 📒 Files selected for processing (1)
✨ Finishing Touches🧪 Generate unit tests (beta)
Comment |
Fixes #50
Problem
The daily-spend reset condition (
now >= last_reset_ledger + DAY_LEDGERS) was inlined independently in four places —get_policy,check_spending_allowed,record_payment, andupdate_policy— with no shared abstraction and zero test coverage. Any future change to the reset threshold or semantics (e.g. moving to wall-clock time, adding a grace period) would require updating all four sites with no safety net.Solution
Extracted helper:
Replaced all four inline occurrences with
is_new_day(now, policy.last_reset_ledger)/is_new_day(now, p.last_reset_ledger).Added
#[cfg(test)]module with 5 boundary tests:nowlast_reset + DAY_LEDGERS - 1false(no reset)last_reset + DAY_LEDGERStrue(reset)last_reset + DAY_LEDGERS + 1true(reset)last_resetfalse(no reset)last_reset + DAY_LEDGERS * 3true(reset)🤖 Generated with Claude Code