Skip to content

refactor: extract shared cfg_set publish into a helper - #433

Merged
mikewheeleer merged 1 commit into
Agentpay-Org:mainfrom
Jagadeeshftw:refactor/events-04-helper
Jul 29, 2026
Merged

refactor: extract shared cfg_set publish into a helper#433
mikewheeleer merged 1 commit into
Agentpay-Org:mainfrom
Jagadeeshftw:refactor/events-04-helper

Conversation

@Jagadeeshftw

Copy link
Copy Markdown
Contributor

Summary

Six single-scalar admin config setters (set_allowlist_enabled, set_min_requests_per_call, set_max_requests_per_call, set_max_requests_per_window, set_rate_window_seconds, set_require_service_registration) each duplicated the identical 3-line env.events().publish((symbol_short!("cfg_set"),), (tag, value)) block. Pure refactor — extracts it into a private publish_cfg_event(env, tag, value) helper and routes all six call sites through it. Behavior is byte-for-byte identical: same topic, same payload shape, same call order relative to the storage write.

While refactoring I noticed the cfg_set topic — despite being the most widely shared event topic in the contract — had no direct payload-correctness test for any of the six setters (only an indirect topic-collision check). Added dedicated tests as regression coverage for this refactor.

Tests added

  • One payload-correctness test per setter (6 total): test_cfg_set_payload_set_allowlist_enabled, ..._set_min_requests_per_call, ..._set_max_requests_per_call, ..._set_max_requests_per_window, ..._set_rate_window_seconds, ..._set_require_service_registration
  • test_cfg_set_payload_tags_are_mutually_distinct — the six tag values (the field that disambiguates the shared topic) can never collide

Closes #290

Validation

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

@Jagadeeshftw
Jagadeeshftw force-pushed the refactor/events-04-helper branch from 94100b8 to 625a193 Compare July 28, 2026 21:18
@mikewheeleer

Copy link
Copy Markdown
Contributor

nice one @Jagadeeshftw, checks pass. merging 🚀

@Jagadeeshftw
Jagadeeshftw force-pushed the refactor/events-04-helper branch from 625a193 to 9117066 Compare July 29, 2026 06:04
@mikewheeleer
mikewheeleer merged commit 67f942a 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 events check into a shared helper

2 participants