Skip to content

feat(cntr): add validator crate — closes #1024, #1028, #1031, #1036#1040

Merged
yusuftomilola merged 1 commit into
DistinctCodes:mainfrom
authenticeasy-sys:feat/ct-07-11-14-19-cntr-validators
May 30, 2026
Merged

feat(cntr): add validator crate — closes #1024, #1028, #1031, #1036#1040
yusuftomilola merged 1 commit into
DistinctCodes:mainfrom
authenticeasy-sys:feat/ct-07-11-14-19-cntr-validators

Conversation

@authenticeasy-sys
Copy link
Copy Markdown
Contributor

Summary

Creates the contracts/cntr crate with four new modules resolving CT-07, CT-11, CT-14, and CT-19.

Changes

contracts/cntr/src/credit_topup.rscloses #1024

  • validate_topup(current_balance, topup_amount, max_balance) -> Result<i128, &'static str>
  • Rejects zero/negative top-ups, guards against overflow, enforces max balance
  • 7 unit tests including exact boundary, one-above-max, overflow guard

contracts/cntr/src/multi_booking.rscloses #1028

  • get_booking_limit(tier) -> u32: Bronze=2, Silver=5, Gold=10, Platinum=u32::MAX, unknown→Bronze
  • can_make_booking(tier, current_active_bookings) -> bool
  • 8 unit tests covering all tiers, unknown tier, at-limit and below-limit cases

contracts/cntr/src/payment_validator.rscloses #1031

  • validate_payment_amount(received, expected, tolerance) -> Result<(), &'static str>
  • Validates expected > 0, checks received >= expected - tolerance
  • 7 unit tests: exact, within tolerance, one-below-tolerance, overpayment, zero/negative expected

contracts/cntr/src/role_checker.rs + contracts/cntr/tests/access_control_tests.rscloses #1036

  • RoleRegistry: in-memory role store with grant_role, revoke_role, has_role, get_roles
  • 12 integration tests: grant, idempotent grant, multi-role, revoke, revoke-nonexistent (no panic), unknown address, empty registry, independence across addresses

contracts/Cargo.toml

  • Added cntr to workspace members so CI picks it up

Tested

All tests verified locally via cargo test -p cntr.

- contracts/cntr/src/credit_topup.rs: validate_topup with overflow guard (closes DistinctCodes#1024)
- contracts/cntr/src/multi_booking.rs: get_booking_limit + can_make_booking per tier (closes DistinctCodes#1028)
- contracts/cntr/src/payment_validator.rs: validate_payment_amount with tolerance (closes DistinctCodes#1031)
- contracts/cntr/src/role_checker.rs: RoleRegistry for access control (peer module for DistinctCodes#1036)
- contracts/cntr/tests/access_control_tests.rs: 12 access control tests (closes DistinctCodes#1036)
- contracts/Cargo.toml: add cntr to workspace members
@vercel
Copy link
Copy Markdown

vercel Bot commented May 29, 2026

@authenticeasy-sys 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

@authenticeasy-sys 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

Copy link
Copy Markdown
Collaborator

@yusuftomilola yusuftomilola left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thank you for your contribution

@yusuftomilola yusuftomilola merged commit 4f1b182 into DistinctCodes:main May 30, 2026
5 of 7 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

2 participants