Skip to content

remove ledger dep in sample witnesses, update sims#73

Open
andrew-fleming wants to merge 1 commit intoOpenZeppelin:mainfrom
andrew-fleming:remove-ledger-dep-in-wit
Open

remove ledger dep in sample witnesses, update sims#73
andrew-fleming wants to merge 1 commit intoOpenZeppelin:mainfrom
andrew-fleming:remove-ledger-dep-in-wit

Conversation

@andrew-fleming
Copy link
Contributor

@andrew-fleming andrew-fleming commented Mar 17, 2026

Summary by CodeRabbit

  • Refactor
    • Enhanced witness system architecture to support generic ledger types, increasing flexibility across different implementations.
    • Updated witness factories and test utilities to align with improved type system changes.
    • Strengthened type constraints while maintaining system stability.

@andrew-fleming andrew-fleming requested review from a team as code owners March 17, 2026 14:11
@coderabbitai
Copy link

coderabbitai bot commented Mar 17, 2026

Walkthrough

The pull request generalizes witness interfaces and factory functions by introducing a ledger type parameter L, replacing hardcoded Ledger type dependencies. All witness context parameters now use the generic L parameter. Integration test files were updated to provide concrete ledger types to the parameterized factories.

Changes

Cohort / File(s) Summary
Witness Interface Generalization
packages/simulator/test/fixtures/sample-contracts/witnesses/SampleZOwnableWitnesses.ts, packages/simulator/test/fixtures/sample-contracts/witnesses/WitnessWitnesses.ts
Added generic type parameter L to ISampleZOwnableWitnesses and IWitnessWitnesses interfaces. Updated all method signatures to use WitnessContext<L, P> instead of WitnessContext<Ledger, P>. Made corresponding factory functions generic with <L> type parameter.
Integration Test Updates
packages/simulator/test/integration/SampleZOwnableSimulator.ts, packages/simulator/test/integration/WitnessSimulator.ts
Introduced local type aliases for ledger types derived from ledger instances. Updated witness factory calls to pass concrete ledger types as generic parameters, e.g., WitnessWitnesses<WitnessLedger>(). Minor comment formatting adjustments.

Estimated code review effort

🎯 3 (Moderate) | ⏱️ ~20 minutes

Suggested reviewers

  • 0xisk
  • emnul

Poem

🐰 A hop and a skip through the types we go,
Ledgers generic, no longer in thrall,
Parameters flow where they need to flow,
Witnesses dance, embracing them all! 🎭

🚥 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 title directly describes the main change: removing the Ledger dependency from sample witnesses and updating simulators to use generic type parameters instead.
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 unit tests (beta)
  • Create PR with unit tests
📝 Coding Plan
  • Generate coding plan for human review comments

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

Tip

CodeRabbit can use oxc to improve the quality of JavaScript and TypeScript code reviews.

Add a configuration file to your project to customize how CodeRabbit runs oxc.

Copy link

@coderabbitai coderabbitai bot left a comment

Choose a reason for hiding this comment

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

🧹 Nitpick comments (2)
packages/simulator/test/integration/WitnessSimulator.ts (1)

6-9: Carry the concrete witness type through the simulator generics.

Line 34 binds the factory to WitnessLedger, but lines 23 and 44 still use the uninstantiated ReturnType<typeof WitnessWitnesses>. This widens the witness type again outside the factory call, so this file does not preserve the ledger-specific witness typing end-to-end.

Extract a concrete Witnesses type alias from IWitnessWitnesses<WitnessLedger, WitnessPrivateState> and use it to replace both occurrences of ReturnType<typeof WitnessWitnesses> in the createSimulator call (line 23) and BaseSimulatorOptions constructor parameter (line 44). This will propagate the ledger-specific witness type consistently through the entire simulator setup.

♻️ Proposed fix
 import {
+  type IWitnessWitnesses,
   WitnessPrivateState,
   WitnessWitnesses,
 } from '../fixtures/sample-contracts/witnesses/WitnessWitnesses';
 
 /** Concrete ledger type extracted from the generated artifact */
 type WitnessLedger = ReturnType<typeof ledger>;
+type Witnesses = IWitnessWitnesses<WitnessLedger, WitnessPrivateState>;
 
 const WitnessSimulatorBase = createSimulator<
   WitnessPrivateState,
-  ReturnType<typeof ledger>,
-  ReturnType<typeof WitnessWitnesses>,
+  WitnessLedger,
+  Witnesses,
   WitnessContract<WitnessPrivateState>,
   WitnessArgs
 >({
@@
 export class WitnessSimulator extends WitnessSimulatorBase {
   constructor(
     options: BaseSimulatorOptions<
       WitnessPrivateState,
-      ReturnType<typeof WitnessWitnesses>
+      Witnesses
     > = {},
   ) {

Also applies to: 14–15, 20–25, 34–45

🤖 Prompt for AI Agents
Verify each finding against the current code and only fix it if needed.

In `@packages/simulator/test/integration/WitnessSimulator.ts` around lines 6 - 9,
The simulator currently widens witness typing by using ReturnType<typeof
WitnessWitnesses> in createSimulator and BaseSimulatorOptions; instead, add a
concrete alias like "type Witnesses = IWitnessWitnesses<WitnessLedger,
WitnessPrivateState>" (using WitnessLedger and WitnessPrivateState from the
import) and replace both occurrences of ReturnType<typeof WitnessWitnesses> with
this Witnesses alias so the concrete ledger-specific witness type flows through
createSimulator(...) and the BaseSimulatorOptions constructor consistently;
update references to WitnessWitnesses only for the factory binding and use the
new Witnesses type for the generic parameters.
packages/simulator/test/integration/SampleZOwnableSimulator.ts (1)

9-12: Carry the concrete witness type through the simulator generics.

Line 40 fixes the factory call with SampleZOwnableWitnesses<SampleZOwnableLedger>(), but Lines 29-30 and Line 52 still use ReturnType<typeof SampleZOwnableWitnesses>. This drops the concrete ledger type everywhere else in the simulator, so type safety is only enforced at the factory call itself.

♻️ Proposed fix
 import {
+  type ISampleZOwnableWitnesses,
   SampleZOwnablePrivateState,
   SampleZOwnableWitnesses,
 } from '../fixtures/sample-contracts/witnesses/SampleZOwnableWitnesses';
 
 /** Concrete ledger type extracted from the generated artifact */
 type SampleZOwnableLedger = ReturnType<typeof ledger>;
+type Witnesses = ISampleZOwnableWitnesses<
+  SampleZOwnableLedger,
+  SampleZOwnablePrivateState
+>;
 
 const SampleZOwnableSimulatorBase = createSimulator<
   SampleZOwnablePrivateState,
-  ReturnType<typeof ledger>,
-  ReturnType<typeof SampleZOwnableWitnesses>,
+  SampleZOwnableLedger,
+  Witnesses,
   SampleZOwnable<SampleZOwnablePrivateState>,
   SampleZOwnableArgs
 >({
@@
 export class SampleZOwnableSimulator extends SampleZOwnableSimulatorBase {
   constructor(
     ownerId: Uint8Array,
     instanceSalt: Uint8Array,
     options: BaseSimulatorOptions<
       SampleZOwnablePrivateState,
-      ReturnType<typeof SampleZOwnableWitnesses>
+      Witnesses
     > = {},
   ) {

Also applies to: 20-21, 26-31, 40-53

🤖 Prompt for AI Agents
Verify each finding against the current code and only fix it if needed.

In `@packages/simulator/test/integration/SampleZOwnableSimulator.ts` around lines
9 - 12, The simulator generics are losing the concrete ledger type by using
ReturnType<typeof SampleZOwnableWitnesses> in multiple places; replace those
occurrences with the concrete generic form
SampleZOwnableWitnesses<SampleZOwnableLedger> so the ledger type is carried
through. Specifically, update all generic type references (including the
simulator class/type parameter usages and any variable/const typings that
currently use ReturnType<typeof SampleZOwnableWitnesses>) to use
SampleZOwnableWitnesses<SampleZOwnableLedger>, ensuring the factory call remains
SampleZOwnableWitnesses<SampleZOwnableLedger>() and all related symbols
(SampleZOwnablePrivateState, SampleZOwnableWitnesses, SampleZOwnableLedger, and
the simulator class/type) consistently reference the concrete witness type.
🤖 Prompt for all review comments with AI agents
Verify each finding against the current code and only fix it if needed.

Nitpick comments:
In `@packages/simulator/test/integration/SampleZOwnableSimulator.ts`:
- Around line 9-12: The simulator generics are losing the concrete ledger type
by using ReturnType<typeof SampleZOwnableWitnesses> in multiple places; replace
those occurrences with the concrete generic form
SampleZOwnableWitnesses<SampleZOwnableLedger> so the ledger type is carried
through. Specifically, update all generic type references (including the
simulator class/type parameter usages and any variable/const typings that
currently use ReturnType<typeof SampleZOwnableWitnesses>) to use
SampleZOwnableWitnesses<SampleZOwnableLedger>, ensuring the factory call remains
SampleZOwnableWitnesses<SampleZOwnableLedger>() and all related symbols
(SampleZOwnablePrivateState, SampleZOwnableWitnesses, SampleZOwnableLedger, and
the simulator class/type) consistently reference the concrete witness type.

In `@packages/simulator/test/integration/WitnessSimulator.ts`:
- Around line 6-9: The simulator currently widens witness typing by using
ReturnType<typeof WitnessWitnesses> in createSimulator and BaseSimulatorOptions;
instead, add a concrete alias like "type Witnesses =
IWitnessWitnesses<WitnessLedger, WitnessPrivateState>" (using WitnessLedger and
WitnessPrivateState from the import) and replace both occurrences of
ReturnType<typeof WitnessWitnesses> with this Witnesses alias so the concrete
ledger-specific witness type flows through createSimulator(...) and the
BaseSimulatorOptions constructor consistently; update references to
WitnessWitnesses only for the factory binding and use the new Witnesses type for
the generic parameters.

ℹ️ Review info
⚙️ Run configuration

Configuration used: Organization UI

Review profile: CHILL

Plan: Pro

Run ID: c24306b6-29fc-43a8-92b8-4e73ca32901e

📥 Commits

Reviewing files that changed from the base of the PR and between f1eabab and ca3741c.

📒 Files selected for processing (4)
  • packages/simulator/test/fixtures/sample-contracts/witnesses/SampleZOwnableWitnesses.ts
  • packages/simulator/test/fixtures/sample-contracts/witnesses/WitnessWitnesses.ts
  • packages/simulator/test/integration/SampleZOwnableSimulator.ts
  • packages/simulator/test/integration/WitnessSimulator.ts

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.

1 participant