Skip to content

deprecate: remove sim_getConsensusContract dependency#142

Merged
cristiam86 merged 2 commits intomainfrom
cristiam86/sim-consensus-usage
Mar 9, 2026
Merged

deprecate: remove sim_getConsensusContract dependency#142
cristiam86 merged 2 commits intomainfrom
cristiam86/sim-consensus-usage

Conversation

@cristiam86
Copy link
Contributor

@cristiam86 cristiam86 commented Mar 9, 2026

What

  • Deprecated initializeConsensusSmartContract() method as a no-op that emits a warning
  • Removed sim_getConsensusContract RPC call entirely from the codebase
  • Removed fire-and-forget call on client creation and awaited calls from writeContract() and deployContract()
  • The consensus contract is now resolved entirely from static chain definitions

Why

The library should rely on static chain definitions rather than making dynamic RPC calls. This removes a runtime dependency on the sim_getConsensusContract method being available on the chain, simplifying client initialization and reducing unnecessary network calls.

Testing done

  • All 27 tests pass (chains-actions, transactions, contracts-actions, client)
  • Updated test suite to verify the deprecated method emits a warning and makes no network calls
  • Statement coverage: 90% (66% branch coverage)

Decisions made

Kept the method signature for backwards compatibility but made it a pure no-op with a deprecation warning. This allows existing code to continue calling the method without breaking while encouraging migration to chain definitions.

Summary by CodeRabbit

  • Deprecations

    • Consensus contract initialization is deprecated; contracts are resolved from chain definitions.
  • Tests

    • Updated tests to assert deprecation warnings and remove network-dependent flows.
    • Adjusted test scaffolding and mocks for simplified behavior.
  • Chores

    • Added coverage path to ignore list.
    • Removed temporary test TypeScript config and related initialization calls.
    • Added dev tooling for coverage reporting.

Deprecate initializeConsensusSmartContract() as a no-op and stop making
sim_getConsensusContract RPC calls. The consensus contract is now resolved
entirely from static chain definitions. Removed the method's fire-and-forget
call from client creation and the awaited calls from writeContract and
deployContract. Updated all tests accordingly.
@coderabbitai
Copy link

coderabbitai bot commented Mar 9, 2026

No actionable comments were generated in the recent review. 🎉

ℹ️ Recent review info
⚙️ Run configuration

Configuration used: defaults

Review profile: CHILL

Plan: Pro

Run ID: 1b00ec73-3b1d-478a-b452-8277d898bfe2

📥 Commits

Reviewing files that changed from the base of the PR and between 68252d7 and 9a3be62.

📒 Files selected for processing (1)
  • src/chains/actions.ts

📝 Walkthrough

Walkthrough

This PR deprecates initializeConsensusSmartContract (replacing it with a no-op that warns), removes its invocations from client and contract workflows, updates tests to assert the deprecation and remove runtime-fetch logic, adds coverage to .gitignore, adds a Vitest coverage devDependency, and deletes a temporary vitest tsconfig.

Changes

Cohort / File(s) Summary
Consensus Contract Deprecation
src/chains/actions.ts, src/types/clients.ts
Replaced full initializeConsensusSmartContract implementation with a deprecation stub that logs a warning; added JSDoc deprecation note in the client type.
Removed Initialization Calls
src/client/client.ts, src/contracts/actions.ts
Removed calls to initializeConsensusSmartContract() from client startup, writeContract, and deployContract paths.
Tests Updated
tests/chains-actions.test.ts, tests/client.test.ts, tests/contracts-actions.test.ts
Simplified tests to expect deprecation warning and no network calls; removed runtime/fallback contract-fetch scenarios and removed initializeConsensusSmartContract injection in test harnesses.
Config & Tooling
.gitignore, package.json, tsconfig.vitest-temp.json
Added coverage/ to .gitignore, added @vitest/coverage-v8 to devDependencies, and deleted temporary tsconfig.vitest-temp.json.

Estimated code review effort

🎯 3 (Moderate) | ⏱️ ~20 minutes

Possibly related PRs

  • PR #125: Modifies client initialization and consensus smart contract initialization flow; closely related to the deprecation and removal of auto-initialization in this PR.

Poem

🐇 I once chased consensus down the lane,
Now I nibble logs instead of strain.
A quiet warning, soft and bright,
No more fetches in the night—
Hopping forward, light and sane. 🥕

🚥 Pre-merge checks | ✅ 2 | ❌ 1

❌ Failed checks (1 warning)

Check name Status Explanation Resolution
Docstring Coverage ⚠️ Warning Docstring coverage is 0.00% which is insufficient. The required threshold is 80.00%. Write docstrings for the functions missing them to satisfy the coverage threshold.
✅ Passed checks (2 passed)
Check name Status Explanation
Title check ✅ Passed The title 'deprecate: remove sim_getConsensusContract dependency' clearly and specifically describes the main change: deprecating a method and removing the sim_getConsensusContract RPC dependency.
Description check ✅ Passed The description comprehensively covers all key template sections: What (changes made), Why (rationale), and Testing done (test results and coverage). The description is well-structured and complete.

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

✨ Finishing Touches
  • 📝 Generate docstrings (stacked PR)
  • 📝 Generate docstrings (commit on current branch)
🧪 Generate unit tests (beta)
  • Create PR with unit tests
  • Post copyable unit tests in a comment
  • Commit unit tests in branch cristiam86/sim-consensus-usage

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.

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.

Actionable comments posted: 1

Caution

Some comments are outside the diff and can’t be posted inline due to platform limitations.

⚠️ Outside diff range comments (2)
tests/chains-actions.test.ts (1)

4-19: ⚠️ Potential issue | 🟡 Minor

Keep this fixture aligned with GenLayerChain.

The helper now only fills part of the GenLayer chain shape and then hides the mismatch with as any. That weakens the test against the SDK’s real contract; please add the remaining GenLayer-specific fields or type the fixture as GenLayerChain.

As per coding guidelines, **/*chain*.{ts,tsx}: Extend viem's Chain type with GenLayer-specific properties: isStudio, consensusMainContract / consensusDataContract, stakingContract, defaultNumberOfInitialValidators, and defaultConsensusMaxRotations.

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

In `@tests/chains-actions.test.ts` around lines 4 - 19, The fixture created by
makeClient currently only provides a partial Chain shape and uses "as any";
replace or type it as GenLayerChain and populate the GenLayer-specific
properties required by the SDK: add isStudio (boolean), consensusMainContract
and consensusDataContract (with address, abi, bytecode shapes already used),
stakingContract, defaultNumberOfInitialValidators, and
defaultConsensusMaxRotations, and ensure rpcUrls and chain.id remain; update the
return type of makeClient to GenLayerChain (instead of any) so the test fixture
matches the real GenLayerChain shape.
tests/contracts-actions.test.ts (1)

64-89: ⚠️ Potential issue | 🟡 Minor

Make the deprecated initializer fail fast in these harnesses.

These clients now provide a resolved initializeConsensusSmartContract, so writeContract() can regress and call the deprecated method again without breaking this suite. Prefer a throwing mock here, or assert not.toHaveBeenCalled() after each path.

Suggested fix
-    initializeConsensusSmartContract: vi.fn().mockResolvedValue(undefined),
+    initializeConsensusSmartContract: vi.fn(async () => {
+      throw new Error("unexpected initializeConsensusSmartContract call");
+    }),

Also applies to: 223-242, 301-320

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

In `@tests/contracts-actions.test.ts` around lines 64 - 89, The client mock's
initializeConsensusSmartContract is currently mocked to resolve
(mockResolvedValue), allowing writeContract to silently call the deprecated
initializer; change initializeConsensusSmartContract to a failing mock (e.g.,
vi.fn().mockRejectedValue(new Error('deprecated initializer called')) or
vi.fn().mockImplementation(() => { throw new Error('deprecated initializer
called') })) so tests fail fast if the deprecated path is invoked, and update
the other client mocks found in the same test (the other client occurrences)
similarly; alternatively, after exercising each code path assert
initializeConsensusSmartContract.not.toHaveBeenCalled() to ensure the deprecated
initializer was not used.
🤖 Prompt for all review comments with AI agents
Verify each finding against the current code and only fix it if needed.

Inline comments:
In `@src/chains/actions.ts`:
- Around line 3-14: The parameter name for chainActions is unused causing a
no-unused-vars lint failure; rename the function parameter client to _client in
the chainActions declaration to keep the same signature and semantics while
satisfying the linter (referencing the chainActions function and its deprecated
method initializeConsensusSmartContract).

---

Outside diff comments:
In `@tests/chains-actions.test.ts`:
- Around line 4-19: The fixture created by makeClient currently only provides a
partial Chain shape and uses "as any"; replace or type it as GenLayerChain and
populate the GenLayer-specific properties required by the SDK: add isStudio
(boolean), consensusMainContract and consensusDataContract (with address, abi,
bytecode shapes already used), stakingContract,
defaultNumberOfInitialValidators, and defaultConsensusMaxRotations, and ensure
rpcUrls and chain.id remain; update the return type of makeClient to
GenLayerChain (instead of any) so the test fixture matches the real
GenLayerChain shape.

In `@tests/contracts-actions.test.ts`:
- Around line 64-89: The client mock's initializeConsensusSmartContract is
currently mocked to resolve (mockResolvedValue), allowing writeContract to
silently call the deprecated initializer; change
initializeConsensusSmartContract to a failing mock (e.g.,
vi.fn().mockRejectedValue(new Error('deprecated initializer called')) or
vi.fn().mockImplementation(() => { throw new Error('deprecated initializer
called') })) so tests fail fast if the deprecated path is invoked, and update
the other client mocks found in the same test (the other client occurrences)
similarly; alternatively, after exercising each code path assert
initializeConsensusSmartContract.not.toHaveBeenCalled() to ensure the deprecated
initializer was not used.

ℹ️ Review info
⚙️ Run configuration

Configuration used: defaults

Review profile: CHILL

Plan: Pro

Run ID: 309b96b1-6f84-4b7f-b0b1-2700f87b22c2

📥 Commits

Reviewing files that changed from the base of the PR and between 46e95f0 and 68252d7.

⛔ Files ignored due to path filters (1)
  • package-lock.json is excluded by !**/package-lock.json
📒 Files selected for processing (10)
  • .gitignore
  • package.json
  • src/chains/actions.ts
  • src/client/client.ts
  • src/contracts/actions.ts
  • src/types/clients.ts
  • tests/chains-actions.test.ts
  • tests/client.test.ts
  • tests/contracts-actions.test.ts
  • tsconfig.vitest-temp.json
💤 Files with no reviewable changes (3)
  • tsconfig.vitest-temp.json
  • src/contracts/actions.ts
  • src/client/client.ts

@cristiam86 cristiam86 merged commit 0683465 into main Mar 9, 2026
3 checks passed
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