Skip to content

Commit

Permalink
chore: do not send hardhat_setLedgerOutputEnabled over http
Browse files Browse the repository at this point in the history
  • Loading branch information
galargh committed Aug 7, 2024
1 parent 83721d9 commit 6771f00
Show file tree
Hide file tree
Showing 3 changed files with 30 additions and 1 deletion.
5 changes: 5 additions & 0 deletions .changeset/shaggy-bags-work.md
Original file line number Diff line number Diff line change
@@ -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
9 changes: 9 additions & 0 deletions packages/hardhat-core/src/internal/core/providers/http.ts
Original file line number Diff line number Diff line change
Expand Up @@ -86,6 +86,15 @@ export class HttpProvider extends EventEmitter implements EIP1193Provider {
}

public async request(args: RequestArguments): Promise<unknown> {
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[]
Expand Down
17 changes: 16 additions & 1 deletion packages/hardhat-core/test/internal/core/providers/http.ts
Original file line number Diff line number Diff line change
@@ -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;

Expand Down Expand Up @@ -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"
);
});
});
});

0 comments on commit 6771f00

Please sign in to comment.