Use code 3 for JSON-RPC responses where there has been a revert#8104
Use code 3 for JSON-RPC responses where there has been a revert#8104ChristopherDedominici merged 22 commits intomainfrom
Conversation
🦋 Changeset detectedLatest commit: 92ba0a7 The changes in this PR will be included in the next version bump. This PR includes changesets to release 7 packages
Not sure what this means? Click here to learn what changesets are. Click here if you're a maintainer who wants to add another changeset to this PR |
There was a problem hiding this comment.
Pull request overview
Updates Hardhat’s JSON-RPC error handling to align revert responses with the de facto geth/anvil convention (error code: 3 and raw hex revert data), improving compatibility with tooling that expects this shape (per #8043).
Changes:
- Treat errors with numeric
code === 3as revert errors and emit geth/anvil-style JSON-RPC error responses (raw hexdata). - Add
code = 3(andname) toSolidityErrorso stack-trace-based reverts propagate with the expected JSON-RPC error code. - Update node JSON-RPC handler tests to validate the new response shape for code-3 errors.
Reviewed changes
Copilot reviewed 3 out of 3 changed files in this pull request and generated 1 comment.
| File | Description |
|---|---|
| packages/hardhat/test/internal/builtin-plugins/node/json-rpc/handler.ts | Adjusts tests to assert geth/anvil-style revert error formatting for code-3 errors. |
| packages/hardhat/src/internal/builtin-plugins/node/json-rpc/handler.ts | Updates _handleError to avoid wrapping code-3 errors and to serialize revert data as a raw hex string. |
| packages/hardhat/src/internal/builtin-plugins/network-manager/edr/stack-traces/stack-trace-solidity-errors.ts | Adds SolidityError.CODE/code (3) and sets name to ensure revert errors carry the expected code. |
hardhatTotal size of the bundle: List of dependencies (sorted by size) |
|
Review the following changes in direct dependencies. Learn more about Socket for GitHub.
|
| import { assertHardhatInvariant } from "@nomicfoundation/hardhat-errors"; | ||
| import { ensureError } from "@nomicfoundation/hardhat-utils/error"; | ||
| import { isPrefixedHexString } from "@nomicfoundation/hardhat-utils/hex"; | ||
| import { |
There was a problem hiding this comment.
I don't get why this needs to be changed. I would have assumed that it was still working as expected.
If I revert the changes to this package, except for the package.json, the tests still pass.
| @@ -0,0 +1,176 @@ | |||
| import type { HardhatViemHelpers } from "@nomicfoundation/hardhat-viem/types"; | |||
There was a problem hiding this comment.
I think this tests should be present in hardhat-viem, not this package.
alcuadrado
left a comment
There was a problem hiding this comment.
left a tiny comment but LGTM
Co-authored-by: Patricio Palladino <email@patriciopalladino.com>
| server = await hre.network.createServer(); | ||
| ({ address, port } = await server.listen()); | ||
| }); | ||
|
|
||
| after(async () => { | ||
| await server.close(); | ||
| }); | ||
|
|
||
| beforeEach(async () => { | ||
| ({ viem } = await hre.network.connect({ | ||
| network: "localhost", | ||
| override: { | ||
| url: `http://${address}:${port}`, | ||
| }, |
There was a problem hiding this comment.
In the HTTP suite, the test uses the address returned by server.listen() to build the client URL. When the JSON-RPC server is bound to 0.0.0.0/:: (common in Docker/CI), that address is not always a reliable connect target for HTTP clients and can make this test flaky. Prefer binding the server explicitly to 127.0.0.1 (e.g. via hre.network.createServer("default", "127.0.0.1")) and using 127.0.0.1 in the override URL, while still keeping port from listen().
Fixes: #8043