Skip to content

test: add unit tests for event dedup guard by txHash and eventIndex - #747

Closed
stableprogrammer wants to merge 2 commits into
accesslayerorg:mainfrom
stableprogrammer:test/event-dedup-guard-734
Closed

test: add unit tests for event dedup guard by txHash and eventIndex#747
stableprogrammer wants to merge 2 commits into
accesslayerorg:mainfrom
stableprogrammer:test/event-dedup-guard-734

Conversation

@stableprogrammer

Copy link
Copy Markdown
Contributor

Closes #734

Problem

The event ingestion pipeline can receive the same on-chain event more than once when the Horizon cursor resets or a worker restarts mid-batch. The existing dedupeChainEvents batch filter did not expose a per-event guard with an explicit { skipped: true } return value, making the deduplication behaviour untestable at the acceptance-criteria level.

Solution

Added guardChainEvent(event, seen) to indexer-dedupe.utils.ts — a lightweight per-event guard that checks the (txHash, eventIndex) composite key against a caller-managed Set<string> and returns { skipped: true } for already-seen events or { skipped: false } for new ones, recording the key in seen on admission.

Tests added

src/modules/indexer/event-dedup-guard.unit.test.ts30 unit tests covering all five acceptance criteria from #734:

AC What is verified
AC-1 New (txHash, eventIndex) pair → { skipped: false }, handler called once, record written to DB
AC-2 Duplicate pair → { skipped: true } on every subsequent call, handler never called again
AC-3 Same txHash with different eventIndex → two distinct events, both written
AC-4 No side effects (balance update, price snapshot) fire for a skipped duplicate
AC-5 DB record count is unchanged after a duplicate is processed

Additional coverage: mixed batches with interleaved unique and duplicate events, first-occurrence ordering is preserved, empty batch, single-event batch, case-sensitive txHash, eventIndex 0 falsy-value correctness, large eventIndex values.

…ccesslayerorg#734)

17 tests covering: new pair processed once, duplicate skipped with no
handler call, same txHash different eventIndex treated as distinct,
no side effects on skip, DB count unchanged after duplicate, edge cases.
…cesslayerorg#734)

Add guardChainEvent() to indexer-dedupe.utils.ts — a per-event guard that
checks a (txHash, eventIndex) composite key against a caller-maintained
seen Set and returns { skipped: true } for duplicates, { skipped: false }
for new events.

30 unit tests in event-dedup-guard.unit.test.ts covering all 5 acceptance
criteria from accesslayerorg#734:
  AC-1  New pair returns { skipped: false } and is written to DB once
  AC-2  Duplicate pair returns { skipped: true } on every subsequent call
  AC-3  Same txHash + different eventIndex treated as two distinct events
  AC-4  No side effects (balance update, price snapshot) fire on a skip
  AC-5  DB record count unchanged after a duplicate is processed
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 unit tests for the event deduplication guard skipping already-processed events by transaction hash and event index

2 participants