feat(contracts): add cntr crate — grace period handler & payment validator#1041
Open
devbackend513-ux wants to merge 1 commit into
Open
Conversation
… 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
|
@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. |
|
@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! 🚀 |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Summary
Implements the
contracts/cntrcrate resolving both issues.[CT-08] Subscription Grace Period Handler (closes #1025)
contracts/cntr/src/grace_period.rsSubscriptionStatusenum derivingDebug, PartialEqwith variantsActive,InGracePeriod,Expiredget_subscription_status(expiry_ts, current_ts, grace_seconds) -> SubscriptionStatusActivewhencurrent_ts < expiry_tsInGracePeriodwhenexpiry_ts <= current_ts < expiry_ts + grace_secondsExpiredwhencurrent_ts >= expiry_ts + grace_secondsDEFAULT_GRACE_SECONDS = 259_200(3 days)[CT-18] Payment Verification Test Suite (closes #1035)
contracts/cntr/src/payment_validator.rsvalidate_payment(paid_amount, expected_amount, tolerance) -> Result<(), PaymentError>PaymentErrorenum:NegativePayment,ZeroPayment,Underpaymentcontracts/cntr/tests/payment_verification_tests.rs— 11 integration tests:Files Changed
Testing
All tests pass with
cargo test -p cntr. CI workflow (.github/workflows/CI.yaml) runscargo test --allwhich will validate this crate.