Skip to content

Remove SimulateItemBase, resolve types from events - #1084

Merged
DZakh merged 6 commits into
mainfrom
claude/remove-simulate-item-base-LRX7D
Apr 6, 2026
Merged

Remove SimulateItemBase, resolve types from events#1084
DZakh merged 6 commits into
mainfrom
claude/remove-simulate-item-base-LRX7D

Conversation

@DZakh

@DZakh DZakh commented Apr 3, 2026

Copy link
Copy Markdown
Member

Summary

  • Remove SimulateItemBase and SimulateContractEvent helper types from packages/envio/index.d.ts
  • Inline all fields directly into EvmSimulateItem and FuelSimulateItem with a distributive mapped type
  • Extract block, transaction, and params types from the generated contract event types in IndexerConfigTypes instead of using untyped Record<string, unknown>

Test plan

  • Codegen succeeds (envio codegen in test_codegen scenario)
  • TypeScript type check passes (tsc --noEmit)
  • All simulate-related tests pass (vitest run)

https://claude.ai/code/session_01V5cdAoTfWpUj1vG21vVfwa

Summary by CodeRabbit

  • Refactor
    • Tightened simulation item typing and added per-event simulate-params schemas to control parsing and defaults.
  • Bug Fixes
    • EVM simulate items now tolerate missing/partial params by coercing defaults; Fuel simulate items require explicit params.
  • Tests
    • Added tests verifying simulate processing with missing and partial params and the resulting populated fields.

…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
@coderabbitai

coderabbitai Bot commented Apr 3, 2026

Copy link
Copy Markdown
Contributor
📝 Walkthrough

Walkthrough

Tightens and inlines simulate-item TypeScript types for EVM and Fuel, requires contracts in config generics, adjusts params/block/transaction/srcAddress/logIndex optionality, and adds runtime simulate-params schema generation + parsing changes with corresponding test and mock updates.

Changes

Cohort / File(s) Summary
Type declarations
packages/envio/index.d.ts
Removed SimulateContractEvent and SimulateItemBase; inlined {contract,event} unions into EvmSimulateItem and FuelSimulateItem. contracts is now required via `Config["evm"
Event config / schema builder
packages/envio/src/EventConfigBuilder.res, packages/envio/src/Internal.res
Added ABI-to-simulate-schema helpers (abiTypeToSimulateSchema, abiTypeToDefaultValue, buildSimulateParamsSchema) and wired simulateParamsSchema: buildSimulateParamsSchema(params) into EVM event configs; extended internal eventConfig type with simulateParamsSchema.
Simulate items parsing
packages/envio/src/SimulateItems.res
Changed parse to always produce a JSON params object (empty when absent) and validate/convert it using eventConfig.simulateParamsSchema instead of the raw-event schema.
Tests and mocks
scenarios/test_codegen/test/EventHandler.test.ts, scenarios/test_codegen/test/helpers/Mock.res, scenarios/fuel_test/test/HyperFuelSource_test.res
Added two Vitest cases validating simulate-item runtime behavior for Gravatar.NewGravatar with missing and partial params; updated mocks and fuel test event-config literals to include simulateParamsSchema fields required by new parsing. Tests assert processing succeeds and defaults are populated when params omitted or partially provided.

Estimated code review effort

🎯 3 (Moderate) | ⏱️ ~20 minutes

Possibly related PRs

Suggested reviewers

  • JasoonS
  • JonoPrest

Poem

🐇 I hopped through types and stitched a seam,
Contracts now needed — neat as a dream,
Params fill with defaults when fields are thin,
I nibble bugs and let the tests begin! 🥕

🚥 Pre-merge checks | ✅ 3
✅ Passed checks (3 passed)
Check name Status Explanation
Description Check ✅ Passed Check skipped - CodeRabbit’s high-level summary is enabled.
Title check ✅ Passed The PR title 'Remove SimulateItemBase, resolve types from events' accurately summarizes the primary changes: removing helper types and extracting type information from event definitions.
Docstring Coverage ✅ Passed No functions found in the changed files to evaluate docstring coverage. Skipping docstring coverage check.

✏️ Tip: You can configure your own custom pre-merge checks in the settings.

✨ Finishing Touches
📝 Generate docstrings
  • Create stacked PR
  • Commit on current branch
🧪 Generate unit tests (beta)
  • Create PR with unit tests
  • Commit unit tests in branch claude/remove-simulate-item-base-LRX7D

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.

❤️ Share

Comment @coderabbitai help to get the list of available commands and usage tips.

DZakh and others added 3 commits April 3, 2026 19:11
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

@coderabbitai coderabbitai Bot left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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

📥 Commits

Reviewing files that changed from the base of the PR and between 4f4493c and 5f11d58.

📒 Files selected for processing (2)
  • packages/envio/index.d.ts
  • scenarios/test_codegen/test/EventHandler.test.ts

Comment thread packages/envio/index.d.ts Outdated
claude and others added 2 commits April 6, 2026 08:34
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

@coderabbitai coderabbitai Bot left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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

📥 Commits

Reviewing files that changed from the base of the PR and between 5f11d58 and cea5446.

📒 Files selected for processing (7)
  • packages/envio/index.d.ts
  • packages/envio/src/EventConfigBuilder.res
  • packages/envio/src/Internal.res
  • packages/envio/src/SimulateItems.res
  • scenarios/fuel_test/test/HyperFuelSource_test.res
  • scenarios/test_codegen/test/EventHandler.test.ts
  • scenarios/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

Comment on lines +96 to +103
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}`)

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

⚠️ Potential issue | 🟠 Major

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.

Suggested change
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.

@DZakh
DZakh merged commit 40e28bc into main Apr 6, 2026
8 checks passed
@DZakh
DZakh deleted the claude/remove-simulate-item-base-LRX7D branch April 6, 2026 08:53
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.

2 participants