diff --git a/packages/beacon-node/test/e2e/eth1/jsonRpcHttpClient.test.ts b/packages/beacon-node/test/e2e/eth1/jsonRpcHttpClient.test.ts index 9ab0068c06a0..fdaeda8081cf 100644 --- a/packages/beacon-node/test/e2e/eth1/jsonRpcHttpClient.test.ts +++ b/packages/beacon-node/test/e2e/eth1/jsonRpcHttpClient.test.ts @@ -6,6 +6,10 @@ import {JsonRpcHttpClient} from "../../../src/eth1/provider/jsonRpcHttpClient.js import {getGoerliRpcUrl} from "../../testParams.js"; import {RpcPayload} from "../../../src/eth1/interface.js"; +type FetchError = { + code: string; +}; + describe("eth1 / jsonRpcHttpClient", function () { this.timeout("10 seconds"); @@ -22,6 +26,7 @@ describe("eth1 / jsonRpcHttpClient", function () { abort?: true; timeout?: number; error: any; + errorCode?: string; }[] = [ // // NOTE: This DNS query is very expensive, all cache miss. So it can timeout the tests and cause false positives // { @@ -39,7 +44,8 @@ describe("eth1 / jsonRpcHttpClient", function () { id: "Bad port", url: `http://localhost:${port + 1}`, requestListener: (req, res) => res.end(), - error: "connect ECONNREFUSED", + error: "", + errorCode: "ECONNREFUSED", }, { id: "Not a JSON RPC endpoint", @@ -122,7 +128,6 @@ describe("eth1 / jsonRpcHttpClient", function () { for (const testCase of testCases) { const {id, requestListener, abort, timeout} = testCase; - const error = testCase.error as Error; let {url, payload} = testCase; it(id, async function () { @@ -148,7 +153,16 @@ describe("eth1 / jsonRpcHttpClient", function () { const controller = new AbortController(); if (abort) setTimeout(() => controller.abort(), 50); const eth1JsonRpcClient = new JsonRpcHttpClient([url], {signal: controller.signal}); - await expect(eth1JsonRpcClient.fetch(payload, {timeout})).to.be.rejectedWith(error); + + try { + await eth1JsonRpcClient.fetch(payload, {timeout}); + } catch (error) { + if (testCase.errorCode) { + expect((error as FetchError).code).to.eql(testCase.errorCode); + } else { + expect((error as Error).message).includes(testCase.error); + } + } }); } }); @@ -201,16 +215,18 @@ describe("eth1 / jsonRpcHttpClient - with retries", function () { const controller = new AbortController(); const eth1JsonRpcClient = new JsonRpcHttpClient([url], {signal: controller.signal}); - await expect( - eth1JsonRpcClient.fetchWithRetries(payload, { + try { + await eth1JsonRpcClient.fetchWithRetries(payload, { retryAttempts, shouldRetry: () => { // using the shouldRetry function to keep tab of the retried requests retryCount++; return true; }, - }) - ).to.be.rejectedWith("connect ECONNREFUSED"); + }); + } catch (error) { + expect((error as FetchError).code).eql("ECONNREFUSED"); + } expect(retryCount).to.be.equal(retryAttempts, "connect ECONNREFUSED should be retried before failing"); });