diff --git a/.changeset/shaggy-bags-work.md b/.changeset/shaggy-bags-work.md new file mode 100644 index 0000000000..dde70b7039 --- /dev/null +++ b/.changeset/shaggy-bags-work.md @@ -0,0 +1,5 @@ +--- +"hardhat": patch +--- + +Do not send `http_setLedgerOutputEnabled` messages if they reacht the HTTP Provider to prevent unwanted warnings in the local hardhat node logs diff --git a/packages/hardhat-core/src/internal/core/providers/http.ts b/packages/hardhat-core/src/internal/core/providers/http.ts index 09add550c5..ee77af137b 100644 --- a/packages/hardhat-core/src/internal/core/providers/http.ts +++ b/packages/hardhat-core/src/internal/core/providers/http.ts @@ -86,6 +86,15 @@ export class HttpProvider extends EventEmitter implements EIP1193Provider { } public async request(args: RequestArguments): Promise { + if (args.method === "hardhat_setLedgerOutputEnabled") { + const error = new ProviderError( + "hardhat_setLedgerOutputEnabled - Method not supported", + -32004 + ); + // eslint-disable-next-line @nomicfoundation/hardhat-internal-rules/only-hardhat-error + throw error; + } + const jsonRpcRequest = this._getJsonRpcRequest( args.method, args.params as any[] diff --git a/packages/hardhat-core/test/internal/core/providers/http.ts b/packages/hardhat-core/test/internal/core/providers/http.ts index 11d2f156d4..2c92844672 100644 --- a/packages/hardhat-core/test/internal/core/providers/http.ts +++ b/packages/hardhat-core/test/internal/core/providers/http.ts @@ -1,10 +1,11 @@ -import { assert } from "chai"; +import { assert, expect } from "chai"; import { MockAgent, MockPool } from "undici"; import { HttpProvider } from "../../../../src/internal/core/providers/http"; import { ERRORS } from "../../../../src/internal/core/errors-list"; import { SuccessfulJsonRpcResponse } from "../../../../src/internal/util/jsonrpc"; import { expectHardhatError } from "../../../helpers/errors"; +import { ProviderError } from "../../../../src/internal/core/providers/errors"; const TOO_MANY_REQUEST_STATUS = 429; @@ -93,5 +94,19 @@ describe("HttpProvider", function () { assert.equal(result, successResponse.result); assert(tooManyRequestsReturned); }); + + it("should throw an error if it receives hardhat_setLedgerOutputEnabled as a method", async function () { + const mockPool = makeMockPool(url); + mockPool + .intercept({ method: "POST", path: "/" }) + .reply(200, successResponse); + const provider = new HttpProvider(url, networkName, {}, 20000, mockPool); + await expect( + provider.request({ method: "hardhat_setLedgerOutputEnabled" }) + ).to.be.eventually.rejectedWith( + ProviderError, + "hardhat_setLedgerOutputEnabled - Method not supported" + ); + }); }); });