Skip to content

feat(contracts): add cntr crate — grace period handler & payment validator#1041

Open
devbackend513-ux wants to merge 1 commit into
DistinctCodes:mainfrom
devbackend513-ux:feat/cntr-grace-period-payment-validator
Open

feat(contracts): add cntr crate — grace period handler & payment validator#1041
devbackend513-ux wants to merge 1 commit into
DistinctCodes:mainfrom
devbackend513-ux:feat/cntr-grace-period-payment-validator

Conversation

@devbackend513-ux
Copy link
Copy Markdown

Summary

Implements the contracts/cntr crate resolving both issues.

[CT-08] Subscription Grace Period Handler (closes #1025)

  • contracts/cntr/src/grace_period.rs
  • SubscriptionStatus enum deriving Debug, PartialEq with variants Active, InGracePeriod, Expired
  • get_subscription_status(expiry_ts, current_ts, grace_seconds) -> SubscriptionStatus
    • Active when current_ts < expiry_ts
    • InGracePeriod when expiry_ts <= current_ts < expiry_ts + grace_seconds
    • Expired when current_ts >= expiry_ts + grace_seconds
  • Default grace period constant: DEFAULT_GRACE_SECONDS = 259_200 (3 days)
  • 6 unit tests covering all 3 states and exact boundary values

[CT-18] Payment Verification Test Suite (closes #1035)

  • contracts/cntr/src/payment_validator.rs
  • validate_payment(paid_amount, expected_amount, tolerance) -> Result<(), PaymentError>
  • PaymentError enum: NegativePayment, ZeroPayment, Underpayment
  • contracts/cntr/tests/payment_verification_tests.rs — 11 integration tests:
    • exact amount, overpayment, within tolerance, one stroop below tolerance
    • underpayment well below, zero payment, negative payment
    • zero expected amount, tolerance of zero (pass + fail), large i128 value

Files Changed

contracts/Cargo.toml                              — added cntr to workspace members
contracts/cntr/Cargo.toml                         — new crate manifest
contracts/cntr/src/lib.rs                         — module declarations
contracts/cntr/src/grace_period.rs                — CT-08 implementation + tests
contracts/cntr/src/payment_validator.rs           — CT-18 implementation
contracts/cntr/tests/payment_verification_tests.rs — CT-18 test suite (11 tests)

Testing

All tests pass with cargo test -p cntr. CI workflow (.github/workflows/CI.yaml) runs cargo test --all which will validate this crate.

… validator

- Add contracts/cntr/src/grace_period.rs: SubscriptionStatus enum (Active,
  InGracePeriod, Expired) and get_subscription_status() with 6 unit tests
  covering all 3 states and exact boundary conditions (closes DistinctCodes#1025)
- Add contracts/cntr/src/payment_validator.rs: validate_payment() with
  PaymentError enum handling negative, zero, and underpayment cases
- Add contracts/cntr/tests/payment_verification_tests.rs: 11 integration
  tests covering exact amount, overpayment, tolerance boundaries, zero/
  negative payments, zero expected amount, zero tolerance, and i128 max
  (closes DistinctCodes#1035)
- Register cntr in contracts/Cargo.toml workspace members
@vercel
Copy link
Copy Markdown

vercel Bot commented May 29, 2026

@devbackend513-ux is attempting to deploy a commit to the naijabuz's projects Team on Vercel.

A member of the Team first needs to authorize it.

@drips-wave
Copy link
Copy Markdown

drips-wave Bot commented May 29, 2026

@devbackend513-ux 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

1 participant