Skip to content

Commit

Permalink
Merge pull request #5578 from NomicFoundation/galargh/set-ledger-outp…
Browse files Browse the repository at this point in the history
…ut-enabled

chore: do not send hardhat_setLedgerOutputEnabled over http
  • Loading branch information
galargh committed Aug 7, 2024
2 parents fcd70ca + d144d83 commit 5aa1774
Show file tree
Hide file tree
Showing 3 changed files with 32 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 beyond the HTTP Provider to prevent unwanted warnings in the logs of the local hardhat node
11 changes: 11 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,17 @@ export class HttpProvider extends EventEmitter implements EIP1193Provider {
}

public async request(args: RequestArguments): Promise<unknown> {
// This is a temporary fix to an issue with noisy warnings in the logs
// of a local node (#5406). This will be fixed in the next major release.
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 5aa1774

Please sign in to comment.