Skip to content

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

Merged
Chucks1093 merged 2 commits into
accesslayerorg:mainfrom
stableprogrammer:test/event-dedup-guard-734
Aug 23, 2026
Merged

test: add unit tests for event dedup guard by txHash and eventIndex#748
Chucks1093 merged 2 commits into
accesslayerorg:mainfrom
stableprogrammer:test/event-dedup-guard-734

Conversation

@stableprogrammer

@stableprogrammer stableprogrammer commented Aug 23, 2026

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 had no per-event guard with an explicit { skipped: true } return value, so the deduplication behaviour could not be tested at the acceptance-criteria level.

Solution

Added guardChainEvent(event, seen) to indexer-dedupe.utils.ts — a 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:

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 invoked 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 preserved after dedup, 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
@stableprogrammer
stableprogrammer force-pushed the test/event-dedup-guard-734 branch from 531b8f2 to 80403e5 Compare August 23, 2026 19:07
@Chucks1093
Chucks1093 merged commit dea4063 into accesslayerorg:main Aug 23, 2026
1 check passed
@Chucks1093

Copy link
Copy Markdown
Member

Nice work stableprogrammer

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