refactor: extract shared service-usable check into a helper - #434
Merged
mikewheeleer merged 2 commits intoJul 29, 2026
Conversation
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
force-pushed
the
refactor/fees-03-helper
branch
from
July 28, 2026 21:19
6b99e9a to
bcf4da6
Compare
Contributor
|
nice one @Jagadeeshftw, checks pass. merging 🚀 |
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
record_usageandset_service_priceeach 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 privateensure_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_gatetest_record_usage_and_set_service_price_share_registration_gateCloses #295
Validation
cargo fmt --all -- --checkcargo clippy --all-targets -- -D warningscargo 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 onmain)