Skip to content

refactor: extract shared service-usable check into a helper - #434

Merged
mikewheeleer merged 2 commits into
Agentpay-Org:mainfrom
Jagadeeshftw:refactor/fees-03-helper
Jul 29, 2026
Merged

refactor: extract shared service-usable check into a helper#434
mikewheeleer merged 2 commits into
Agentpay-Org:mainfrom
Jagadeeshftw:refactor/fees-03-helper

Conversation

@Jagadeeshftw

Copy link
Copy Markdown
Contributor

Summary

record_usage and set_service_price each duplicated the identical 6-line check — strict-registration gate followed by the disabled-service gate — byte-for-byte, including the same two error codes (ServiceNotRegistered #7, ServiceDisabled #12). Pure refactor — extracts it into a private ensure_service_usable(env, service_id) helper and calls it from both entrypoints. Behavior is unchanged: same checks, same order, same error codes.

Tests added

Existing coverage already exercised both sides independently (e.g. test_set_price_strict_rejects_unregistered_service, test_set_price_rejects_disabled_service, test_record_usage_disabled_fires_when_service_disabled), and all of it still passes unchanged. Added two new tests that check the two entrypoints in the same test, proving the shared helper keeps them in lockstep:

  • test_record_usage_and_set_service_price_share_disabled_gate
  • test_record_usage_and_set_service_price_share_registration_gate

Closes #295

Validation

  • cargo fmt --all -- --check
  • cargo clippy --all-targets -- -D warnings
  • cargo test -p escrow — 354 passed (2 new), 1 pre-existing failure unrelated to this change (test_transfer_service_ownership_genuine_transfer_emits_event, fails identically on main)

env.events().all() reflects only the most recent contract invocation, not
a running total across separate calls (consistent with every other event
test in this file). The test compared post-transfer event count against a
pre-transfer count captured after a *different* call (set_service_metadata),
expecting accumulation that never happens, so it failed on every run
regardless of contract behavior. Fixed to assert directly on this call's
own event count.
@Jagadeeshftw
Jagadeeshftw force-pushed the refactor/fees-03-helper branch from 6b99e9a to bcf4da6 Compare July 28, 2026 21:19
@mikewheeleer

Copy link
Copy Markdown
Contributor

nice one @Jagadeeshftw, checks pass. merging 🚀

@mikewheeleer
mikewheeleer merged commit 6f980e5 into Agentpay-Org:main Jul 29, 2026
1 check 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

Development

Successfully merging this pull request may close these issues.

Extract the repeated fees check into a shared helper

2 participants