Skip to content

events test - #567

Merged
MaryammAli merged 1 commit into
BlockDash-Studios:mainfrom
Nanafancy:Event-Schema-Validation
Aug 23, 2026
Merged

events test#567
MaryammAli merged 1 commit into
BlockDash-Studios:mainfrom
Nanafancy:Event-Schema-Validation

Conversation

@Nanafancy

Copy link
Copy Markdown
Contributor

Here's a summary of what was implemented for Issue #560:


Changes Made

1. storage.rs — New EventDedup storage key

Added EventDedup(BytesN<32>) variant to the DataKey enum to track emitted event deduplication keys in persistent storage.

2. events.rs — Runtime pre-publish validation & event deduplication

New types and functions:

  • EventDedupKey — contracttype for dedup storage keys
  • compute_event_dedup_key(env, etid, ledger_seq, schema_ver, ts) → SHA-256 of the four core replay fields
  • check_event_dedup(env, key)  Ok(true) if fresh, Ok(false) if duplicate
  • record_event_emission(env, key) → records with 6-month TTL
  • check_and_record_event_dedup(env, etid, ledger_seq, schema_ver, ts) → atomic check-and-record
  • validate_emission_preconditions(env, etid, schema_ver, ledger_seq, ts) → full pre-publish gate that validates:
    • Non-zero event type ID
    • Schema version matches current version (prevents schema drift)
    • Event type ID matches a registered schema
    • Schema entry passes all canonical validation rules
    • Event is not a duplicate

3. events_test.rs — 11 new tests (18 total)

Test | What it validates -- | -- test_pre_publish_rejects_zero_event_type_id | Zero ETID rejected test_pre_publish_rejects_schema_version_mismatch | Wrong version rejected test_pre_publish_rejects_unknown_event_type_id | Unknown ETID rejected test_pre_publish_accepts_valid_event | Valid event passes all checks test_event_dedup_allows_first_emission | First emission is fresh test_event_dedup_rejects_duplicate_emission | Same params → duplicate test_event_dedup_different_ledger_is_fresh | Different ledger_seq → fresh test_event_dedup_different_event_type_is_fresh | Different ETID → fresh test_event_dedup_different_timestamp_is_fresh | Different timestamp → fresh test_pre_publish_rejects_duplicate_at_precondition_level | Full end-to-end duplicate rejection test_schema_invalid_namespace_detected_in_validation | Invalid namespace rejected test_replay_fields_present_in_every_schema | Every schema has all EVENT_REPLAY_FIELDS

4. README.md — Documented new features

Added a dedicated "Event Deduplication & Pre-Publish Validation" section documenting the API, behavior, and storage semantics.

Worked · 1 step
closes #560

@MaryammAli MaryammAli left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

LGTM

@MaryammAli
MaryammAli merged commit fba2bd2 into BlockDash-Studios:main Aug 23, 2026
2 checks 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.

Strengthen event schema validation and replay protections

2 participants