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: clean up prettier-ignore in tests #6464

Merged
merged 8 commits into from
Feb 22, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
78 changes: 38 additions & 40 deletions packages/api/test/unit/beacon/genericServerTest/debug.test.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import {describe, it, expect, MockInstance, beforeAll, afterAll} from "vitest";
import {describe, it, expect, MockInstance, beforeAll, afterAll, vi} from "vitest";
import {toHexString} from "@chainsafe/ssz";
import {FastifyInstance} from "fastify";
import {ssz} from "@lodestar/types";
Expand All @@ -12,51 +12,49 @@ import {registerRoute} from "../../../../src/utils/server/registerRoute.js";
import {HttpClient} from "../../../../src/utils/client/httpClient.js";
import {testData} from "../testData/debug.js";

describe(
"beacon / debug",
() => {
runGenericServerTest<Api, ReqTypes>(config, getClient, getRoutes, testData);
describe("beacon / debug", () => {
// Extend timeout since states are very big
vi.setConfig({testTimeout: 30_000});

// Get state by SSZ
runGenericServerTest<Api, ReqTypes>(config, getClient, getRoutes, testData);

describe("getState() in SSZ format", () => {
const mockApi = getMockApi<Api>(routesData);
let baseUrl: string;
let server: FastifyInstance;
// Get state by SSZ

beforeAll(async () => {
const res = getTestServer();
server = res.server;
for (const route of Object.values(getRoutes(config, mockApi))) {
registerRoute(server, route);
}
baseUrl = await res.start();
});
describe("getState() in SSZ format", () => {
const mockApi = getMockApi<Api>(routesData);
let baseUrl: string;
let server: FastifyInstance;

afterAll(async () => {
if (server !== undefined) await server.close();
});
beforeAll(async () => {
const res = getTestServer();
server = res.server;
for (const route of Object.values(getRoutes(config, mockApi))) {
registerRoute(server, route);
}
baseUrl = await res.start();
});

for (const method of ["getState" as const, "getStateV2" as const]) {
it(method, async () => {
const state = ssz.phase0.BeaconState.defaultValue();
const stateSerialized = ssz.phase0.BeaconState.serialize(state);
(mockApi[method] as MockInstance).mockResolvedValue(stateSerialized);
afterAll(async () => {
if (server !== undefined) await server.close();
});

const httpClient = new HttpClient({baseUrl});
const client = getClient(config, httpClient);
for (const method of ["getState" as const, "getStateV2" as const]) {
it(method, async () => {
const state = ssz.phase0.BeaconState.defaultValue();
const stateSerialized = ssz.phase0.BeaconState.serialize(state);
(mockApi[method] as MockInstance).mockResolvedValue(stateSerialized);

const res = await client[method]("head", "ssz");
const httpClient = new HttpClient({baseUrl});
const client = getClient(config, httpClient);

expect(res.ok).toBe(true);
const res = await client[method]("head", "ssz");

if (res.ok) {
expect(toHexString(res.response)).toBe(toHexString(stateSerialized));
}
});
}
});
},
// Extend timeout since states are very big
{timeout: 30 * 1000}
);
expect(res.ok).toBe(true);

if (res.ok) {
expect(toHexString(res.response)).toBe(toHexString(stateSerialized));
}
});
}
});
});
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import {describe, beforeAll, afterAll, it, expect} from "vitest";
import {describe, beforeAll, afterAll, it, expect, vi} from "vitest";
import {createBeaconConfig} from "@lodestar/config";
import {chainConfig as chainConfigDef} from "@lodestar/config/default";
import {Api, getClient} from "@lodestar/api/beacon";
Expand All @@ -10,6 +10,8 @@ import {BeaconNode} from "../../../../../../src/node/nodejs.js";
import {getAndInitDevValidators} from "../../../../../utils/node/validator.js";

describe("beacon node api", function () {
vi.setConfig({testTimeout: 60_000});

const restPort = 9596;
const config = createBeaconConfig(chainConfigDef, Buffer.alloc(32, 0xaa));
const validatorCount = 8;
Expand Down Expand Up @@ -62,8 +64,6 @@ describe("beacon node api", function () {
expect(res.response.data.elOffline).toEqual(false);
});

// To make the code review easy for code block below
/* prettier-ignore */
it("should return 'el_offline' as 'true' when EL not available", async () => {
const portElOffline = 9597;
const bnElOffline = await getDevBeaconNode({
Expand Down Expand Up @@ -109,8 +109,7 @@ describe("beacon node api", function () {

await Promise.all(validators.map((v) => v.close()));
await bnElOffline.close();
},
{timeout: 60_000});
});
});

describe("getHealth", () => {
Expand Down
9 changes: 4 additions & 5 deletions packages/beacon-node/test/e2e/api/lodestar/lodestar.test.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import {describe, it, afterEach, expect} from "vitest";
import {describe, it, afterEach, expect, vi} from "vitest";
import {createBeaconConfig, ChainConfig} from "@lodestar/config";
import {chainConfig as chainConfigDef} from "@lodestar/config/default";
import {phase0} from "@lodestar/types";
Expand All @@ -11,6 +11,8 @@ import {ClockEvent} from "../../../../src/util/clock.js";
import {BeaconNode} from "../../../../src/index.js";

describe("api / impl / validator", function () {
vi.setConfig({testTimeout: 60_000});

describe("getLiveness endpoint", function () {
let bn: BeaconNode | undefined;
const SECONDS_PER_SLOT = 2;
Expand Down Expand Up @@ -74,8 +76,6 @@ describe("api / impl / validator", function () {
});
});

// To make the code review easy for code block below
/* prettier-ignore */
it("Should return only for previous, current and next epoch", async function () {
const chainConfig: ChainConfig = {...chainConfigDef, SECONDS_PER_SLOT, ALTAIR_FORK_EPOCH};
const genesisValidatorsRoot = Buffer.alloc(32, 0xaa);
Expand Down Expand Up @@ -128,7 +128,6 @@ describe("api / impl / validator", function () {
`Request epoch ${currentEpoch - 2} is more than one epoch before or after the current epoch ${currentEpoch}`
)
);
},
{timeout: 60_000});
});
});
});
8 changes: 4 additions & 4 deletions packages/beacon-node/test/e2e/chain/lightclient.test.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import {describe, it, expect, afterEach} from "vitest";
import {describe, it, expect, afterEach, vi} from "vitest";
import {JsonPath, toHexString, fromHexString} from "@chainsafe/ssz";
import {computeDescriptor, TreeOffsetProof} from "@chainsafe/persistent-merkle-tree";
import {ChainConfig} from "@lodestar/config";
Expand All @@ -14,9 +14,9 @@ import {getDevBeaconNode} from "../../utils/node/beacon.js";
import {getAndInitDevValidators} from "../../utils/node/validator.js";
import {HeadEventData} from "../../../src/chain/index.js";

// To make the code review easy for code block below
/* prettier-ignore */
describe("chain / lightclient", function () {
vi.setConfig({testTimeout: 600_000});

/**
* Max distance between beacon node head and lightclient head
* If SECONDS_PER_SLOT === 1, there should be some margin for slow blocks,
Expand Down Expand Up @@ -178,7 +178,7 @@ describe("chain / lightclient", function () {
const head = await bn.db.block.get(fromHexString(headSummary.blockRoot));
if (!head) throw Error("First beacon node has no head block");
});
}, {timeout: 600_000});
});

// TODO: Re-incorporate for REST-only light-client
async function getHeadStateProof(
Expand Down
18 changes: 8 additions & 10 deletions packages/beacon-node/test/e2e/eth1/jsonRpcHttpClient.test.ts
Original file line number Diff line number Diff line change
@@ -1,15 +1,15 @@
import crypto from "node:crypto";
import http from "node:http";
import {describe, it, expect, afterEach} from "vitest";
import {describe, it, expect, afterEach, vi} from "vitest";
import {FetchError} from "@lodestar/api";
import {sleep} from "@lodestar/utils";
import {JsonRpcHttpClient} from "../../../src/eth1/provider/jsonRpcHttpClient.js";
import {getGoerliRpcUrl} from "../../testParams.js";
import {RpcPayload} from "../../../src/eth1/interface.js";

// To make the code review easy for code block below
/* prettier-ignore */
describe("eth1 / jsonRpcHttpClient", function () {
vi.setConfig({testTimeout: 10_000});

const port = 36421;
const noMethodError = {code: -32601, message: "Method not found"};
const notInSpecError = "JSON RPC Error not in spec";
Expand Down Expand Up @@ -160,11 +160,11 @@ describe("eth1 / jsonRpcHttpClient", function () {
expect.assertions(1);
});
}
}, {timeout: 10_000});
});

// To make the code review easy for code block below
/* prettier-ignore */
describe("eth1 / jsonRpcHttpClient - with retries", function () {
vi.setConfig({testTimeout: 10_000});

const port = 36421;
const noMethodError = {code: -32601, message: "Method not found"};
const afterHooks: (() => Promise<void>)[] = [];
Expand Down Expand Up @@ -281,9 +281,7 @@ describe("eth1 / jsonRpcHttpClient - with retries", function () {

const controller = new AbortController();
const eth1JsonRpcClient = new JsonRpcHttpClient([url], {signal: controller.signal});
await expect(eth1JsonRpcClient.fetchWithRetries(payload, {retries, timeout})).rejects.toThrow(
"Timeout request"
);
await expect(eth1JsonRpcClient.fetchWithRetries(payload, {retries, timeout})).rejects.toThrow("Timeout request");
expect(requestCount).toBeWithMessage(retries + 1, "Timeout request should be retried before failing");
});

Expand Down Expand Up @@ -346,4 +344,4 @@ describe("eth1 / jsonRpcHttpClient - with retries", function () {
await expect(eth1JsonRpcClient.fetchWithRetries(payload, {retries})).rejects.toThrow("Method not found");
expect(requestCount).toBeWithMessage(1, "Payload error (non-network error) should not be retried");
});
}, {timeout: 10_000});
});