Fix wildcard handlerWithLoader regression - #673
Conversation
WalkthroughThis update corrects a typo and changes event filter handling to use an explicit option type in the event handler template. It adds two new event entries and corresponding Changes
Sequence Diagram(s)sequenceDiagram
participant Event as Event
participant Loader as Loader
participant Handler as Handler
participant DB as mockDb
Note over Event,Loader: FilterTestEvent.handlerWithLoader flow
Event->>Loader: Call loader(event)
Loader-->>Handler: Return loader result (undefined)
Handler->>Handler: If event.addr == "0x000" throw error
Handler-->>DB: Handler completes or throws
Note over Event,Loader: WildcardHandlerWithLoader flow
Event->>Loader: Call loader(event)
Loader-->>Handler: Return loader result (undefined)
Handler-->>DB: Handler completes (no-op)
Estimated code review effort🎯 3 (Moderate) | ⏱️ ~18 minutes Poem
📜 Recent review detailsConfiguration used: CodeRabbit UI 📒 Files selected for processing (4)
🚧 Files skipped from review as they are similar to previous changes (4)
⏰ Context from checks skipped due to timeout of 90000ms. You can increase the timeout in your CodeRabbit configuration to a maximum of 15 minutes (900000ms). (1)
✨ Finishing Touches
🧪 Generate unit tests
Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out. 🪧 TipsChatThere are 3 ways to chat with CodeRabbit:
SupportNeed help? Create a ticket on our support page for assistance with any issues or questions. CodeRabbit Commands (Invoked using PR comments)
Other keywords and placeholders
CodeRabbit Configuration File (
|
There was a problem hiding this comment.
Actionable comments posted: 0
🧹 Nitpick comments (1)
codegenerator/cli/templates/dynamic/codegen/src/Types.res.hbs (1)
364-366: Nit: fix variable typo loaderRetrun → loaderReturnMinor typo in local variable name; aligns better with property name and avoids confusion.
- promise->Promise.then(loaderRetrun => { - (args->Obj.magic)["loaderReturn"] = loaderRetrun + promise->Promise.then(loaderReturn => { + (args->Obj.magic)["loaderReturn"] = loaderReturn
📜 Review details
Configuration used: CodeRabbit UI
Review profile: CHILL
Plan: Pro
📒 Files selected for processing (4)
codegenerator/cli/templates/dynamic/codegen/src/Types.res.hbs(1 hunks)scenarios/test_codegen/config.yaml(1 hunks)scenarios/test_codegen/src/EventHandlers.ts(1 hunks)scenarios/test_codegen/test/EventHandler_test.ts(13 hunks)
🧰 Additional context used
📓 Path-based instructions (6)
scenarios/test_codegen/**/{schema.graphql,config.yaml}
📄 CodeRabbit Inference Engine (scenarios/test_codegen/.cursor/rules/hyperindex.mdc)
After any change to schema.graphql or config.yaml, run
pnpm codegen
Files:
scenarios/test_codegen/config.yaml
scenarios/test_codegen/**/*.{ts,yaml}
📄 CodeRabbit Inference Engine (scenarios/test_codegen/.cursor/rules/hyperindex.mdc)
When matching addresses in configuration objects, ensure case consistency by using lowercase keys in config objects to match
address.toLowerCase()lookups
Files:
scenarios/test_codegen/config.yamlscenarios/test_codegen/src/EventHandlers.tsscenarios/test_codegen/test/EventHandler_test.ts
scenarios/test_codegen/**/*.yaml
📄 CodeRabbit Inference Engine (scenarios/test_codegen/.cursor/rules/hyperindex.mdc)
scenarios/test_codegen/**/*.yaml: If using event.transaction.hash or other transaction-level data, explicitly define it under field_selection in config.yaml
Use the provided schema file (# yaml-language-server: $schema=./node_modules/envio/evm.schema.json) to validate config.yaml
When creating token/config files, address keys must be lowercase for consistent matching
When creating token/config files, all required token metadata (name, symbol, decimals) must be included
Files:
scenarios/test_codegen/config.yaml
codegenerator/cli/templates/{dynamic/**/*.hbs,static/**}
📄 CodeRabbit Inference Engine (.cursor/rules/navigation.mdc)
Templates live under codegenerator/cli/templates: dynamic/ for Handlebars (.hbs), static/ for raw Rescript files copied verbatim.
Files:
codegenerator/cli/templates/dynamic/codegen/src/Types.res.hbs
scenarios/test_codegen/**/*.ts
📄 CodeRabbit Inference Engine (scenarios/test_codegen/.cursor/rules/hyperindex.mdc)
scenarios/test_codegen/**/*.ts: After any change to TypeScript files, runpnpm tsc --noEmitto ensure it compiles successfully
When updating existing entities, always use the spread operator because returned objects are read-only and immutable
Always cast timestamps to BigInt:BigInt(event.block.timestamp); never use raw timestamps from events
Usestring | undefinedfor optional string fields, notstring | null
Always normalize amounts when adding tokens with different decimal places; never add raw amounts from different tokens without normalization
When creating new entities, ensure all required fields are present in the entity object
When creating new entities, ensure relationships useentity_idfields, not direct objects
When creating new entities, ensure optional fields useundefinednotnull
When creating token/config files, helper functions must handle case-insensitive lookups
After code changes, runpnpm tsc --noEmitto catch type errors
Check for missing required fields in entity types after code changes
Verify relationship field names match generated types after code changes
Files:
scenarios/test_codegen/src/EventHandlers.tsscenarios/test_codegen/test/EventHandler_test.ts
scenarios/test_codegen/**/*.{ts,graphql}
📄 CodeRabbit Inference Engine (scenarios/test_codegen/.cursor/rules/hyperindex.mdc)
scenarios/test_codegen/**/*.{ts,graphql}: In Envio, useentity_idfields (e.g.,token_id: string) instead of direct object references for relationships
The generated types expecttoken_idnottokenfor relationships
Files:
scenarios/test_codegen/src/EventHandlers.tsscenarios/test_codegen/test/EventHandler_test.ts
🧠 Learnings (22)
📚 Learning: 2025-08-04T07:36:16.824Z
Learnt from: CR
PR: enviodev/hyperindex#0
File: scenarios/test_codegen/.cursor/rules/hyperindex.mdc:0-0
Timestamp: 2025-08-04T07:36:16.824Z
Learning: Applies to scenarios/test_codegen/**/*.yaml : If using event.transaction.hash or other transaction-level data, explicitly define it under field_selection in config.yaml
Applied to files:
scenarios/test_codegen/config.yaml
📚 Learning: 2025-08-04T07:36:16.824Z
Learnt from: CR
PR: enviodev/hyperindex#0
File: scenarios/test_codegen/.cursor/rules/hyperindex.mdc:0-0
Timestamp: 2025-08-04T07:36:16.824Z
Learning: Applies to scenarios/test_codegen/**/*.graphql : Do not add the entity decorator to GraphQL schema types
Applied to files:
scenarios/test_codegen/config.yaml
📚 Learning: 2025-08-04T07:36:16.824Z
Learnt from: CR
PR: enviodev/hyperindex#0
File: scenarios/test_codegen/.cursor/rules/hyperindex.mdc:0-0
Timestamp: 2025-08-04T07:36:16.824Z
Learning: Applies to scenarios/test_codegen/**/*.yaml : When creating token/config files, all required token metadata (name, symbol, decimals) must be included
Applied to files:
scenarios/test_codegen/config.yaml
📚 Learning: 2025-08-04T07:36:16.824Z
Learnt from: CR
PR: enviodev/hyperindex#0
File: scenarios/test_codegen/.cursor/rules/hyperindex.mdc:0-0
Timestamp: 2025-08-04T07:36:16.824Z
Learning: Applies to scenarios/test_codegen/**/*.ts : Check for missing required fields in entity types after code changes
Applied to files:
scenarios/test_codegen/config.yamlcodegenerator/cli/templates/dynamic/codegen/src/Types.res.hbsscenarios/test_codegen/src/EventHandlers.tsscenarios/test_codegen/test/EventHandler_test.ts
📚 Learning: 2025-08-04T07:36:16.824Z
Learnt from: CR
PR: enviodev/hyperindex#0
File: scenarios/test_codegen/.cursor/rules/hyperindex.mdc:0-0
Timestamp: 2025-08-04T07:36:16.824Z
Learning: Applies to scenarios/test_codegen/**/*.graphql : Use `entity_id` fields for relationships instead of entity arrays in GraphQL schemas
Applied to files:
scenarios/test_codegen/config.yaml
📚 Learning: 2025-08-04T07:36:16.824Z
Learnt from: CR
PR: enviodev/hyperindex#0
File: scenarios/test_codegen/.cursor/rules/hyperindex.mdc:0-0
Timestamp: 2025-08-04T07:36:16.824Z
Learning: Applies to scenarios/test_codegen/**/*.yaml : When creating token/config files, address keys must be lowercase for consistent matching
Applied to files:
scenarios/test_codegen/config.yaml
📚 Learning: 2025-08-04T07:36:16.824Z
Learnt from: CR
PR: enviodev/hyperindex#0
File: scenarios/test_codegen/.cursor/rules/hyperindex.mdc:0-0
Timestamp: 2025-08-04T07:36:16.824Z
Learning: Applies to scenarios/test_codegen/**/*.{ts,yaml} : When matching addresses in configuration objects, ensure case consistency by using lowercase keys in config objects to match `address.toLowerCase()` lookups
Applied to files:
scenarios/test_codegen/config.yaml
📚 Learning: 2025-08-04T07:35:49.055Z
Learnt from: CR
PR: enviodev/hyperindex#0
File: codegenerator/cli/templates/static/shared/.cursor/rules/hyperindex.mdc:0-0
Timestamp: 2025-08-04T07:35:49.055Z
Learning: Applies to codegenerator/cli/templates/static/shared/**/*.ts : When creating new entities, ensure all required fields are present, timestamps are cast to BigInt, relationships use `entity_id` fields, updates use spread operator, and optional fields use `undefined` not `null`
Applied to files:
codegenerator/cli/templates/dynamic/codegen/src/Types.res.hbsscenarios/test_codegen/test/EventHandler_test.ts
📚 Learning: 2025-08-04T07:35:20.300Z
Learnt from: CR
PR: enviodev/hyperindex#0
File: .cursor/rules/navigation.mdc:0-0
Timestamp: 2025-08-04T07:35:20.300Z
Learning: Applies to codegenerator/cli/templates/{dynamic/**/*.hbs,static/**} : Templates live under codegenerator/cli/templates: dynamic/ for Handlebars (.hbs), static/ for raw Rescript files copied verbatim.
Applied to files:
codegenerator/cli/templates/dynamic/codegen/src/Types.res.hbs
📚 Learning: 2025-08-04T07:35:49.055Z
Learnt from: CR
PR: enviodev/hyperindex#0
File: codegenerator/cli/templates/static/shared/.cursor/rules/hyperindex.mdc:0-0
Timestamp: 2025-08-04T07:35:49.055Z
Learning: Applies to codegenerator/cli/templates/static/shared/**/*.ts : When updating existing entities, always use the spread operator because returned objects are read-only and immutable
Applied to files:
codegenerator/cli/templates/dynamic/codegen/src/Types.res.hbs
📚 Learning: 2025-08-04T07:35:49.055Z
Learnt from: CR
PR: enviodev/hyperindex#0
File: codegenerator/cli/templates/static/shared/.cursor/rules/hyperindex.mdc:0-0
Timestamp: 2025-08-04T07:35:49.055Z
Learning: Applies to codegenerator/cli/templates/static/shared/**/*.ts : Use `string | undefined` for optional string fields, not `string | null`
Applied to files:
codegenerator/cli/templates/dynamic/codegen/src/Types.res.hbs
📚 Learning: 2025-08-04T07:36:16.824Z
Learnt from: CR
PR: enviodev/hyperindex#0
File: scenarios/test_codegen/.cursor/rules/hyperindex.mdc:0-0
Timestamp: 2025-08-04T07:36:16.824Z
Learning: Applies to scenarios/test_codegen/**/*.ts : When creating new entities, ensure optional fields use `undefined` not `null`
Applied to files:
codegenerator/cli/templates/dynamic/codegen/src/Types.res.hbsscenarios/test_codegen/src/EventHandlers.tsscenarios/test_codegen/test/EventHandler_test.ts
📚 Learning: 2025-08-04T07:36:16.824Z
Learnt from: CR
PR: enviodev/hyperindex#0
File: scenarios/test_codegen/.cursor/rules/hyperindex.mdc:0-0
Timestamp: 2025-08-04T07:36:16.824Z
Learning: Applies to scenarios/test_codegen/**/*.ts : Use `string | undefined` for optional string fields, not `string | null`
Applied to files:
codegenerator/cli/templates/dynamic/codegen/src/Types.res.hbsscenarios/test_codegen/src/EventHandlers.ts
📚 Learning: 2025-08-04T07:35:49.055Z
Learnt from: CR
PR: enviodev/hyperindex#0
File: codegenerator/cli/templates/static/shared/.cursor/rules/hyperindex.mdc:0-0
Timestamp: 2025-08-04T07:35:49.055Z
Learning: Applies to codegenerator/cli/templates/static/shared/**/*.ts : Always cast timestamps to BigInt: `BigInt(event.block.timestamp)`; never use raw timestamps from events
Applied to files:
codegenerator/cli/templates/dynamic/codegen/src/Types.res.hbs
📚 Learning: 2025-08-04T07:35:49.055Z
Learnt from: CR
PR: enviodev/hyperindex#0
File: codegenerator/cli/templates/static/shared/.cursor/rules/hyperindex.mdc:0-0
Timestamp: 2025-08-04T07:35:49.055Z
Learning: Applies to codegenerator/cli/templates/static/shared/{schema.graphql,**/*.ts} : After schema changes, run `pnpm codegen`; after TypeScript changes, run `pnpm tsc --noEmit` to catch type errors; check for missing required fields in entity types and verify relationship field names match generated types
Applied to files:
codegenerator/cli/templates/dynamic/codegen/src/Types.res.hbs
📚 Learning: 2025-08-04T07:36:16.824Z
Learnt from: CR
PR: enviodev/hyperindex#0
File: scenarios/test_codegen/.cursor/rules/hyperindex.mdc:0-0
Timestamp: 2025-08-04T07:36:16.824Z
Learning: Applies to scenarios/test_codegen/**/*.ts : Always cast timestamps to BigInt: `BigInt(event.block.timestamp)`; never use raw timestamps from events
Applied to files:
scenarios/test_codegen/src/EventHandlers.tsscenarios/test_codegen/test/EventHandler_test.ts
📚 Learning: 2025-08-04T07:36:16.824Z
Learnt from: CR
PR: enviodev/hyperindex#0
File: scenarios/test_codegen/.cursor/rules/hyperindex.mdc:0-0
Timestamp: 2025-08-04T07:36:16.824Z
Learning: Applies to scenarios/test_codegen/**/*.ts : When updating existing entities, always use the spread operator because returned objects are read-only and immutable
Applied to files:
scenarios/test_codegen/src/EventHandlers.tsscenarios/test_codegen/test/EventHandler_test.ts
📚 Learning: 2025-08-04T07:36:16.824Z
Learnt from: CR
PR: enviodev/hyperindex#0
File: scenarios/test_codegen/.cursor/rules/hyperindex.mdc:0-0
Timestamp: 2025-08-04T07:36:16.824Z
Learning: Applies to scenarios/test_codegen/**/*.ts : Verify relationship field names match generated types after code changes
Applied to files:
scenarios/test_codegen/src/EventHandlers.tsscenarios/test_codegen/test/EventHandler_test.ts
📚 Learning: 2025-08-04T07:36:16.824Z
Learnt from: CR
PR: enviodev/hyperindex#0
File: scenarios/test_codegen/.cursor/rules/hyperindex.mdc:0-0
Timestamp: 2025-08-04T07:36:16.824Z
Learning: Applies to scenarios/test_codegen/**/*.ts : When creating new entities, ensure relationships use `entity_id` fields, not direct objects
Applied to files:
scenarios/test_codegen/test/EventHandler_test.ts
📚 Learning: 2025-08-04T07:36:16.824Z
Learnt from: CR
PR: enviodev/hyperindex#0
File: scenarios/test_codegen/.cursor/rules/hyperindex.mdc:0-0
Timestamp: 2025-08-04T07:36:16.824Z
Learning: Applies to scenarios/test_codegen/**/*.{ts,graphql} : In Envio, use `entity_id` fields (e.g., `token_id: string`) instead of direct object references for relationships
Applied to files:
scenarios/test_codegen/test/EventHandler_test.ts
📚 Learning: 2025-08-04T07:36:16.824Z
Learnt from: CR
PR: enviodev/hyperindex#0
File: scenarios/test_codegen/.cursor/rules/hyperindex.mdc:0-0
Timestamp: 2025-08-04T07:36:16.824Z
Learning: Applies to scenarios/test_codegen/**/*.ts : When creating new entities, ensure all required fields are present in the entity object
Applied to files:
scenarios/test_codegen/test/EventHandler_test.ts
📚 Learning: 2025-05-27T17:07:12.878Z
Learnt from: JonoPrest
PR: enviodev/hyperindex#555
File: scenarios/test_codegen/test/lib_tests/EntityHistory_test.res:631-659
Timestamp: 2025-05-27T17:07:12.878Z
Learning: In isolated tests for EntityHistory rollbacks with controlled mock data setup, the ordering of getRollbackDiff results is deterministic and doesn't require sorting before comparison with deepStrictEqual.
Applied to files:
scenarios/test_codegen/test/EventHandler_test.ts
⏰ Context from checks skipped due to timeout of 90000ms. You can increase the timeout in your CodeRabbit configuration to a maximum of 15 minutes (900000ms). (1)
- GitHub Check: build_and_test
🔇 Additional comments (6)
scenarios/test_codegen/config.yaml (1)
57-58: Verify ABI declarations and regenerate typesThe handlers for
FilterTestEventandWildcardHandlerWithLoaderare present in scenarios/test_codegen/src/EventHandlers.ts (lines 676, 688). I couldn’t locate gravatar-abi.json in the repo to confirm the events are declared in your ABI.
- Ensure your Gravatar ABI includes both new events.
- After updating your ABI or config.yaml, run
pnpm codegento regenerate bindings.codegenerator/cli/templates/dynamic/codegen/src/Types.res.hbs (1)
378-386: Option-wrapping eventFilters is correct and fixes wildcard-only registrationSwitching to eventFilters: ?eventConfig.eventFilters ensures absence is explicit (None), avoiding truthy/empty pitfalls and fixing wildcard-only cases. Good change.
scenarios/test_codegen/src/EventHandlers.ts (2)
676-686: Filter-based handlerWithLoader wiring looks correctHandler throws when addr matches filter; this intentionally asserts that test framework currently ignores filters. Filter shape aligns with generated types.
After codegen, run pnpm tsc --noEmit to ensure the generated types accept this eventFilters shape.
688-692: Wildcard handlerWithLoader registration LGTMMinimal loader/handler with wildcard: true validates the regression fix. No issues.
scenarios/test_codegen/test/EventHandler_test.ts (2)
18-18: Refactor to mockDb.processEvents is consistent; verify ordering and return semanticsSwitching to processEvents([event...]) is consistent across tests and matches the API that returns a new MockDb. Batch processing case (Line 265) maintains event order.
If any tests become flaky, double-check that:
- each call uses the returned DB for subsequent reads/writes, and
- batched events are ordered as expected.
Also applies to: 48-48, 78-78, 106-106, 139-139, 164-164, 182-182, 200-200, 219-219, 237-237, 265-265, 287-290, 310-310, 339-339
354-375: New tests for filter-ignored behavior and wildcard initialization are precise
- Asserting rejection for filtered handler confirms current limitation in the test framework.
- Wildcard handler init test guards against the Caml_option.some regression.
| Some({ | ||
| wildcard: ?eventConfig.wildcard, | ||
| eventFilters: eventConfig.eventFilters, | ||
| eventFilters: ?eventConfig.eventFilters, |
There was a problem hiding this comment.
Surely this was a compile time error?
There was a problem hiding this comment.
For some reason, it wasn't.
Summary by CodeRabbit
New Features
Bug Fixes
Tests