test: cover register_service_with_metadata atomicity and svc_reg event#142
Merged
mikewheeleer merged 1 commit intoJun 29, 2026
Conversation
Contributor
|
clean work — merging this 🙌 |
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.
closes #90
test: cover
register_service_with_metadataatomicity andsvc_regeventSummary
Adds the
register_service_with_metadataentrypoint — an admin-gated, pause-respecting combined call that atomically registers a service and writes its metadata — along with comprehensive test coverage for atomicity, event emission, idempotency, and both security gates.Also fixes a copy-paste bug in
clear_service_metadatawhich was writingDataKey::UsageAlertThresholdinstead of removingDataKey::ServiceMetadata.Changes
contracts/escrow/src/lib.rsregister_service_with_metadata(env, service_id, description, owner)(new, ~line 1152)ensure_not_pausedthenrequire_adminServiceRegistered(service_id) = trueandServiceMetadata(service_id)in one atomic callsvc_reg(service_id, owner)eventclear_service_metadata(bug fix, ~line 1348)set(&DataKey::UsageAlertThreshold, &threshold)— a copy-paste errorremove(&DataKey::ServiceMetadata(service_id))and publishes themeta_clreventcontracts/escrow/src/test.rsSeven new tests:
test_register_with_metadata_atomicityis_service_registered == trueANDget_service_metadatareturns exact description + ownertest_register_with_metadata_emits_svc_reg_eventsvc_reg(service_id, owner)event decoded fromenv.events().all()test_register_with_metadata_overwritetest_register_with_metadata_empty_description_acceptedStringis acceptedtest_register_with_metadata_requires_adminUnauthorizedtest_register_with_metadata_rejected_while_pausedContractPaused(#4)test_register_with_metadata_equivalent_to_separate_callsregister_service+set_service_metadatatwo-stepUpdated module header doc comment with coverage notes.
Security Notes
require_admin()ensures only the stored admin can register+metadata in one call.ensure_not_paused()rejects the call while the contract is paused, with the same error code (Emit structured events on admin, price, and registration state changes #4) as every other state-changing entrypoint.ServiceRegisteredandServiceMetadataslots are written in the same invocation — there is no intermediate state where a service is registered but has no metadata, or vice versa.Verification
(Note: the workspace crate has pre-existing compilation errors unrelated to these changes — see issue tracker for
read_usage,AgentServiceIndex, and dispute-related missing definitions.)