Remove SimulateItemBase, resolve types from events - #1084
Conversation
…nt types Instead of using untyped Record<string, unknown> for block, transaction, and params fields on simulate items, extract concrete types from the generated contract event types in IndexerConfigTypes. This gives proper type-checking and autocomplete for simulate items in tests. https://claude.ai/code/session_01V5cdAoTfWpUj1vG21vVfwa
📝 WalkthroughWalkthroughTightens and inlines simulate-item TypeScript types for EVM and Fuel, requires Changes
Estimated code review effort🎯 3 (Moderate) | ⏱️ ~20 minutes Possibly related PRs
Suggested reviewers
Poem
🚥 Pre-merge checks | ✅ 3✅ Passed checks (3 passed)
✏️ Tip: You can configure your own custom pre-merge checks in the settings. ✨ Finishing Touches📝 Generate docstrings
🧪 Generate unit tests (beta)
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. Comment |
paramsRawEventSchema uses s.field (required), not s.fieldOr, so S.convertOrThrow rejects partial params at runtime. https://claude.ai/code/session_01V5cdAoTfWpUj1vG21vVfwa
- Missing params: process rejects (worker crash on undefined.field) - Partial params: process succeeds but handler silently fails, no entity created (rescript-schema passes partial through) https://claude.ai/code/session_01V5cdAoTfWpUj1vG21vVfwa
There was a problem hiding this comment.
Actionable comments posted: 1
🤖 Prompt for all review comments with AI agents
Verify each finding against the current code and only fix it if needed.
Inline comments:
In `@packages/envio/index.d.ts`:
- Around line 559-560: The params property is currently optional for all events
but must be required when the event actually has parameters; update the
declaration for the params property so it's optional only when
Contracts[C][E]["params"] is undefined/void and required otherwise. Replace the
existing "params?: Contracts[C][E][\"params\"];" with a conditional property
that makes params optional if Contracts[C][E][\"params\"] extends undefined (or
never/void) and required otherwise, using a TypeScript conditional type
referencing Contracts[C][E][\"params\"] so events like NewGravatar that have
params will require them at compile time.
🪄 Autofix (Beta)
Fix all unresolved CodeRabbit comments on this PR:
- Push a commit to this branch (recommended)
- Create a new PR with the fixes
ℹ️ Review info
⚙️ Run configuration
Configuration used: defaults
Review profile: CHILL
Plan: Pro
Run ID: f72bb8b6-50aa-4262-a2da-1dc281b6fc56
📒 Files selected for processing (2)
packages/envio/index.d.tsscenarios/test_codegen/test/EventHandler.test.ts
Add simulateParamsSchema to eventConfig that uses S.schema + s.matches with S.null->S.Option.getOr to fill missing param fields with defaults: - address → zero address - bool → false - string/bytes → "" - uint/int → 0n - arrays → [] - tuples → tuple of defaults When params is omitted entirely, all fields get defaults (empty object passed through schema). When partial params are provided, only missing fields get defaults. Update TS type to Partial<> on EVM simulate item params. https://claude.ai/code/session_01V5cdAoTfWpUj1vG21vVfwa
There was a problem hiding this comment.
Actionable comments posted: 1
🤖 Prompt for all review comments with AI agents
Verify each finding against the current code and only fix it if needed.
Inline comments:
In `@packages/envio/src/EventConfigBuilder.res`:
- Around line 96-103: The simulate-schema branch for addresses drops real
address validation: update abiTypeToSimulateSchema so the "address" case uses
Address.schema->S.toUnknown (instead of S.string->S.toUnknown) so simulated
address params are parsed/canonicalized the same way as in abiTypeToSchema; keep
the rest of the match arms unchanged.
🪄 Autofix (Beta)
Fix all unresolved CodeRabbit comments on this PR:
- Push a commit to this branch (recommended)
- Create a new PR with the fixes
ℹ️ Review info
⚙️ Run configuration
Configuration used: defaults
Review profile: CHILL
Plan: Pro
Run ID: 9558146e-886f-41db-9d71-e0a9c8e3c5b9
📒 Files selected for processing (7)
packages/envio/index.d.tspackages/envio/src/EventConfigBuilder.respackages/envio/src/Internal.respackages/envio/src/SimulateItems.resscenarios/fuel_test/test/HyperFuelSource_test.resscenarios/test_codegen/test/EventHandler.test.tsscenarios/test_codegen/test/helpers/Mock.res
✅ Files skipped from review due to trivial changes (2)
- scenarios/fuel_test/test/HyperFuelSource_test.res
- scenarios/test_codegen/test/EventHandler.test.ts
| switch abiType { | ||
| | "address" => S.string->S.toUnknown | ||
| | "bool" => S.bool->S.toUnknown | ||
| | "string" | "bytes" => S.string->S.toUnknown | ||
| | t if t->Js.String2.startsWith("uint") => S.bigint->S.toUnknown | ||
| | t if t->Js.String2.startsWith("int") => S.bigint->S.toUnknown | ||
| | t if t->Js.String2.startsWith("bytes") => S.string->S.toUnknown | ||
| | other => Js.Exn.raiseError(`Unsupported ABI type: ${other}`) |
There was a problem hiding this comment.
Don't drop address validation in simulate params.
abiTypeToSimulateSchema("address") now accepts any string, while real event params still flow through Address.schema in abiTypeToSchema. That lets simulate inputs bypass address validation/canonicalization and makes provided address params behave differently from real events. Use Address.schema here so address params, including nested arrays/tuples, are parsed the same way.
Suggested fix
- | "address" => S.string->S.toUnknown
+ | "address" => Address.schema->S.toUnknown📝 Committable suggestion
‼️ IMPORTANT
Carefully review the code before committing. Ensure that it accurately replaces the highlighted code, contains no missing lines, and has no issues with indentation. Thoroughly test & benchmark the code to ensure it meets the requirements.
| switch abiType { | |
| | "address" => S.string->S.toUnknown | |
| | "bool" => S.bool->S.toUnknown | |
| | "string" | "bytes" => S.string->S.toUnknown | |
| | t if t->Js.String2.startsWith("uint") => S.bigint->S.toUnknown | |
| | t if t->Js.String2.startsWith("int") => S.bigint->S.toUnknown | |
| | t if t->Js.String2.startsWith("bytes") => S.string->S.toUnknown | |
| | other => Js.Exn.raiseError(`Unsupported ABI type: ${other}`) | |
| switch abiType { | |
| | "address" => Address.schema->S.toUnknown | |
| | "bool" => S.bool->S.toUnknown | |
| | "string" | "bytes" => S.string->S.toUnknown | |
| | t if t->Js.String2.startsWith("uint") => S.bigint->S.toUnknown | |
| | t if t->Js.String2.startsWith("int") => S.bigint->S.toUnknown | |
| | t if t->Js.String2.startsWith("bytes") => S.string->S.toUnknown | |
| | other => Js.Exn.raiseError(`Unsupported ABI type: ${other}`) |
🤖 Prompt for AI Agents
Verify each finding against the current code and only fix it if needed.
In `@packages/envio/src/EventConfigBuilder.res` around lines 96 - 103, The
simulate-schema branch for addresses drops real address validation: update
abiTypeToSimulateSchema so the "address" case uses Address.schema->S.toUnknown
(instead of S.string->S.toUnknown) so simulated address params are
parsed/canonicalized the same way as in abiTypeToSchema; keep the rest of the
match arms unchanged.
Summary
SimulateItemBaseandSimulateContractEventhelper types frompackages/envio/index.d.tsEvmSimulateItemandFuelSimulateItemwith a distributive mapped typeblock,transaction, andparamstypes from the generated contract event types inIndexerConfigTypesinstead of using untypedRecord<string, unknown>Test plan
envio codegenin test_codegen scenario)tsc --noEmit)vitest run)https://claude.ai/code/session_01V5cdAoTfWpUj1vG21vVfwa
Summary by CodeRabbit