Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

chore: do not send hardhat_setLedgerOutputEnabled over http #5578

Merged
merged 2 commits into from
Aug 7, 2024
Merged
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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
galargh marked this conversation as resolved.
Show resolved Hide resolved
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") {
galargh marked this conversation as resolved.
Show resolved Hide resolved
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"
);
});
});
});