Skip to content

Conversation

FrederikBolding
Copy link
Member

@FrederikBolding FrederikBolding commented Oct 8, 2025

Allow mocking full JSON-RPC method implementations by passing functions. Also introduces mockJsonRpcOnce, which only mocks the first call to the method. The previous method of specifying mocks is still supported.

Closes #2096


Note

Adds function-based JSON-RPC mocking and a new mockJsonRpcOnce helper (with queueing), refactoring store/middleware to support per-mock implementations and one-time behavior.

  • API:
    • Extend mockJsonRpc to accept function implementations in packages/snaps-simulation/src/helpers.ts and types in packages/snaps-simulation/src/types.ts.
    • Add mockJsonRpcOnce to Snap/helpers and expose via packages/snaps-jest/src/helpers.ts.
  • Store & Middleware:
    • Refactor mocks state to store { implementation, once } by id; remove getJsonRpcMock, keep getJsonRpcMocks (packages/snaps-simulation/src/store/mocks.ts).
    • Update middleware to async, iterate mocks, execute implementations, and auto-remove once mocks (packages/snaps-simulation/src/middleware/mock.ts).
    • Introduce nanoid-based IDs and allow non-serializable middleware (serializableCheck: false).
  • Tests:
    • Add tests for function-based mocks, mockJsonRpcOnce, and queued mocks in helpers tests; update middleware/store tests to new structure.

Written by Cursor Bugbot for commit 5c765f1. This will update automatically on new commits. Configure here.

@FrederikBolding FrederikBolding changed the title wip: Allow mocking JSON-RPC implementations feat: Allow mocking JSON-RPC implementations Oct 8, 2025
@FrederikBolding FrederikBolding marked this pull request as ready for review October 8, 2025 13:06
@FrederikBolding FrederikBolding requested a review from a team as a code owner October 8, 2025 13:06
cursor[bot]

This comment was marked as outdated.

@FrederikBolding FrederikBolding requested a review from Mrtenz October 8, 2025 13:12
Copy link

codecov bot commented Oct 8, 2025

Codecov Report

✅ All modified and coverable lines are covered by tests.
✅ Project coverage is 98.29%. Comparing base (3754d30) to head (5c765f1).
⚠️ Report is 1 commits behind head on main.

Additional details and impacted files
@@           Coverage Diff           @@
##             main    #3667   +/-   ##
=======================================
  Coverage   98.29%   98.29%           
=======================================
  Files         417      417           
  Lines       11907    11924   +17     
  Branches     1848     1852    +4     
=======================================
+ Hits        11704    11721   +17     
  Misses        203      203           

☔ View full report in Codecov by Sentry.
📢 Have feedback on the report? Share it here.

🚀 New features to boost your workflow:
  • ❄️ Test Analytics: Detect flaky tests, report on failures, and find test suite problems.
  • 📦 JS Bundle Analysis: Save yourself from yourself by tracking and limiting bundle sizes in JS merges.

@FrederikBolding FrederikBolding requested a review from Mrtenz October 8, 2025 13:33
@FrederikBolding FrederikBolding added this pull request to the merge queue Oct 8, 2025
Merged via the queue into main with commit bbe558a Oct 8, 2025
121 checks passed
@FrederikBolding FrederikBolding deleted the fb/mock-json-rpc-implementation branch October 8, 2025 13:49
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.

Allow mocking JSON-RPC methods based on params

2 participants