Skip to content

test(indexer): add user.processor spec and reconcile-users CLI - #1696

Merged
Otaiki1 merged 2 commits into
crackedstudio:masterfrom
Mossad-esc:fix/1593-user-processor-tests
Sep 30, 2026
Merged

Otaiki1 merged 2 commits into
crackedstudio:masterfrom
Mossad-esc:fix/1593-user-processor-tests

Conversation

@Mossad-esc

Copy link
Copy Markdown

Summary

Closes #1593

user.processor.ts (235 lines) had no spec while the raffle and ticket
processors both did. User aggregates underpin the leaderboard and creator
profiles — double-counting from a replayed event or an uncompensated reorg
corrupts them permanently.

Changes

indexer/src/processors/user.processor.spec.ts (new, 25 tests)

Scenario Handler(s)
First event for a new address — row upserted, counters incremented all
Subsequent events — totalRafflesEntered only bumped on first ticket per raffle handleTicketPurchased
Replayed duplicate (same txHash) → no-op, no double-count handleTicketPurchased, handleRaffleFinalized
Compensating rollback (lastTxHash cleared) → event re-applied handleTicketPurchased
Event that survived the reorg → skipped handleTicketPurchased
null winner → early return handleRaffleFinalized
Empty prize string coerced to '0' handleRaffleFinalized
Own-transaction lifecycle: connect / commit / release / rollback on error all
Address stored byte-for-byte as supplied; cache invalidated with exact address normalisation

indexer/src/cli/reconcile-users.command.ts (new)

Recomputes all five aggregate columns from tickets + raffles and diffs
against stored users rows.

pnpm run users:reconcile              # report drift, exit 2 if any
pnpm run users:reconcile -- --dry-run # same, no writes
pnpm run users:reconcile -- --address GABC...
pnpm run users:reconcile -- --fix     # rewrite drifted rows (nulls lastTxHash)

indexer/package.json

Added users:reconcile script.

Test results

25/25 passing. The 12 lint errors in CI are pre-existing parserOptions.project
failures on integration files excluded from tsconfig — zero issues in the two
new files.

Closes crackedstudio#1593.

- Add indexer/src/processors/user.processor.spec.ts (25 tests)
  Covers all four handler methods with the scenarios called out in the
  issue: first event for a new address, subsequent events, replayed
  duplicate (same txHash → no-op), compensating rollback (lastTxHash
  cleared → event re-applied), address normalisation, own-transaction
  lifecycle (connect / commit / release / rollback), and cache
  invalidation assertions.

- Add indexer/src/cli/reconcile-users.command.ts
  Standalone CLI that recomputes user aggregates (totalTicketsBought,
  totalRafflesEntered, totalRafflesWon, totalPrizeXlm, firstSeenLedger)
  from the tickets + raffles tables and compares them against the
  stored user rows. Supports --dry-run (report only, exit 2 on drift),
  --fix (rewrite drifted rows, nulls lastTxHash with maintenance-window
  caveat documented), and --address <G...> (single-address scope).

- Add users:reconcile script to indexer/package.json
@Mossad-esc
Mossad-esc requested a review from Otaiki1 as a code owner September 25, 2026 22:03
@github-actions github-actions Bot added the area:indexer Focus directory: indexer label Sep 30, 2026
@Otaiki1
Otaiki1 merged commit 09d58ef into crackedstudio:master Sep 30, 2026
1 of 2 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

area:indexer Focus directory: indexer

Projects

None yet

Development

Successfully merging this pull request may close these issues.

[indexer] The user processor has no tests

2 participants