Skip to content

test: add assert_event helper for contract event field assertions (#559) - #1066

Open
EneGab wants to merge 1 commit into
accesslayerorg:mainfrom
EneGab:feat/559-assert-event-test-helper
Open

EneGab wants to merge 1 commit into
accesslayerorg:mainfrom
EneGab:feat/559-assert-event-test-helper

Conversation

@EneGab

@EneGab EneGab commented Oct 17, 2026

Copy link
Copy Markdown
Contributor

Summary

  • Closes Add helper for asserting contract event fields in test assertions #559 by introducing a shared test helper assert_event(env, contract_id, topic, expected_fields) to eliminate repetitive boilerplate across event test assertions.
  • Added assert_event to creator-keys/tests/contract_test_env/mod.rs:
    • Filters events in env.events().all() by both emitting contract address (contract_id) and canonical event topic at index 0 (topic).
    • Deserializes event payloads into generic contract types implementing TryFromVal<Env, Val> + PartialEq + core::fmt::Debug.
    • Produces clear, readable panic messages showing the queried topic, expected fields, and actual emitted fields on mismatch, as well as an explicit failure message when no matching event was found.
  • Added dedicated unit tests for the helper in creator-keys/tests/assert_event.rs verifying exact match, topic filtering, contract ID filtering, field value mismatch messages, and behavior when no events are emitted.
  • Refactored existing event-emitting tests to adopt assert_event:
    • creator-keys/tests/contract_initialization_event.rs (test_initialization_event_emitted_on_first_set_fee_config) for ContractInitializedEvent.
    • creator-keys/tests/creator_registered_event_fields.rs (test_creator_registered_event_all_four_fields_present_in_one_registration) for CreatorRegisteredEvent.

Testing

  • cargo fmt --all -- --check
  • cargo clippy --workspace --all-targets -- -D warnings
  • cargo test --workspace

Checklist

  • Linked issue or backlog item (Add helper for asserting contract event fields in test assertions #559)
  • Added or updated creator-keys unit/integration tests for every changed contract behavior, including failure paths for new or reachable ContractError variants
  • Ran cargo fmt --all -- --check, cargo clippy --workspace --all-targets -- -D warnings, and cargo test --workspace, or explained exactly why a command was not run
  • Reviewed persistent storage changes against docs/storage-key-invariants.md; any storage layout change includes a migration/backward-compatibility note (N/A - no storage layout modifications)
  • Confirmed event names, topic order, payload field order, and field meanings remain compatible with docs/contract-event-conventions.md, or documented the breaking change and versioning plan (N/A - event schemas unchanged)
  • Updated docs for any changed public contract interface, read-only method, event schema, storage behavior, fee logic, or deployment workflow (N/A - test helper only, no contract interface changes)
  • Scope stays limited to one contract concern and does not include unrelated formatting, lockfile, generated artifact, or dependency changes

…cesslayerorg#559)

Add a shared test assertion helper `assert_event` to reduce boilerplate
when verifying emitted contract events in integration tests.

- Implement `assert_event(env, contract_id, topic, expected_fields)` in
  `creator-keys/tests/contract_test_env/mod.rs` to filter events by both
  contract address and primary topic (index 0).
- Deserialize event payloads into generic types and compare them against
  expected fields, providing clear panic messages showing the topic,
  expected fields, and actual emitted values on mismatch (or reporting
  when no matching event was found).
- Refactor existing event test cases in `contract_initialization_event.rs`
  and `creator_registered_event_fields.rs` to replace manual log extraction
  with `assert_event`.
- Add unit tests for the helper in `creator-keys/tests/assert_event.rs`
  verifying exact match, topic filtering, contract filtering, field
  mismatch messages, and empty log behavior.
@drips-wave

drips-wave Bot commented Oct 17, 2026

Copy link
Copy Markdown

@EneGab 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

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.

Add helper for asserting contract event fields in test assertions

1 participant