test: add unit tests for event dedup guard by txHash and eventIndex - #747
Closed
stableprogrammer wants to merge 2 commits into
Closed
test: add unit tests for event dedup guard by txHash and eventIndex#747stableprogrammer wants to merge 2 commits into
stableprogrammer wants to merge 2 commits into
Conversation
…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
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
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
dedupeChainEventsbatch 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)toindexer-dedupe.utils.ts— a lightweight per-event guard that checks the(txHash, eventIndex)composite key against a caller-managedSet<string>and returns{ skipped: true }for already-seen events or{ skipped: false }for new ones, recording the key inseenon admission.Tests added
src/modules/indexer/event-dedup-guard.unit.test.ts— 30 unit tests covering all five acceptance criteria from #734:(txHash, eventIndex)pair →{ skipped: false }, handler called once, record written to DB{ skipped: true }on every subsequent call, handler never called againtxHashwith differenteventIndex→ two distinct events, both writtenAdditional coverage: mixed batches with interleaved unique and duplicate events, first-occurrence ordering is preserved, empty batch, single-event batch, case-sensitive
txHash,eventIndex 0falsy-value correctness, largeeventIndexvalues.