feat: support batch JSON-RPC request matching in mocks#95
Merged
gregorydemay merged 9 commits intomainfrom Mar 20, 2026
Merged
Conversation
Extract JSON-RPC body matching fields (method, id, params) into a dedicated `SingleJsonRpcMatcher` struct with its own builder methods and a `matches_body` helper. This prepares for making the request matcher generic over single vs batch JSON-RPC bodies. Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
Rename the struct to `JsonRpcHttpRequestMatcher<B>` and introduce: - `impl<B>` block for shared HTTP-level builders and `matches_http` helper - `impl JsonRpcHttpRequestMatcher<SingleJsonRpcMatcher>` for body-specific builders (`with_method`, `with_id`, `with_params`) and the `CanisterHttpRequestMatcher` trait impl - Type alias `JsonRpcRequestMatcher = JsonRpcHttpRequestMatcher<SingleJsonRpcMatcher>` preserving full backward compatibility Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
Add `JsonRpcHttpRequestMatcher<Vec<SingleJsonRpcMatcher>>` with a `batch` constructor and a `CanisterHttpRequestMatcher` impl that deserializes the body as a JSON array and matches pairwise in order. Introduce `BatchJsonRpcRequestMatcher` type alias for ergonomics. Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
Add `batch_json_rpc_request_matcher_tests` module with tests covering batch matching, wrong method/size/order/params, and HTTP-level constraints (url, host). Export new types (`BatchJsonRpcRequestMatcher`, `JsonRpcHttpRequestMatcher`, `SingleJsonRpcMatcher`) from `lib.rs`. Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
Rename the struct to `JsonRpcHttpResponse<B>` and introduce: - `JsonRpcResponse` type alias for `JsonRpcHttpResponse<Value>` (single) - `BatchJsonRpcResponse` type alias for `JsonRpcHttpResponse<Vec<Value>>` - Generic `From<JsonRpcHttpResponse<B>> for CanisterHttpResponse` impl - Single-specific `with_id`/`with_raw_id` and `From` conversions - Batch-specific `From<Vec<Value>>` conversion Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
gregorydemay
added a commit
to dfinity/evm-rpc-canister
that referenced
this pull request
Mar 11, 2026
Point canhttp, ic-canister-runtime, and ic-pocket-canister-runtime to dfinity/canhttp#95 which adds BatchJsonRpcRequestMatcher for testing batch JSON-RPC requests. Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
lpahlavi
reviewed
Mar 16, 2026
Contributor
lpahlavi
left a comment
There was a problem hiding this comment.
Thanks for the PR @gregorydemay! Mostly a comment regarding naming from me, but otherwise LGTM! 💪
gregorydemay
commented
Mar 20, 2026
Contributor
Author
gregorydemay
left a comment
There was a problem hiding this comment.
Thanks for the review @lpahlavi ! Should be ready for another round. Once merged I will proceed to cutting a new release.
lpahlavi
approved these changes
Mar 20, 2026
Contributor
lpahlavi
left a comment
There was a problem hiding this comment.
Thanks for the changes @gregorydemay, PR LGTM!
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Motivation
Extend the mock infrastructure to mock JSON-RPC batch requests and responses, where a JSON-RPC batch request is an array of individual JSON-RPC requests sent in a single HTTPS outcall.
Summary
JsonRpcRequestMatchergeneric over the body matcher (JsonRpcHttpRequestMatcher<B>) to support both single and batch JSON-RPC requestsSingleJsonRpcMatcher, reusable for both single and batch matchersJsonRpcResponse→JsonRpcHttpResponse<B>for batch responsesJsonRpcRequestMatcher,JsonRpcResponse)New public types
JsonRpcHttpRequestMatcher<B>— generic request matcherSingleJsonRpcMatcher— body-level matcher for a single JSON-RPC requestBatchJsonRpcRequestMatcher— type alias forJsonRpcHttpRequestMatcher<Vec<SingleJsonRpcMatcher>>JsonRpcHttpResponse<B>— generic responseBatchJsonRpcResponse— type alias forJsonRpcHttpResponse<Vec<Value>>🤖 Generated with Claude Code