Skip to content
Open
Show file tree
Hide file tree
Changes from 6 commits
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
2 changes: 1 addition & 1 deletion configs/vite.config.base.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
import {visualizer} from "rollup-plugin-visualizer";
import {UserConfig, defineConfig} from "vite";
import {defineConfig} from "vite";
import {nodePolyfills} from "vite-plugin-node-polyfills";
import topLevelAwait from "vite-plugin-top-level-await";
import {blsBrowserPlugin} from "../scripts/vite/plugins/blsBrowserPlugin.js";
Expand Down
14 changes: 4 additions & 10 deletions configs/vitest.config.e2e.ts
Original file line number Diff line number Diff line change
Expand Up @@ -17,11 +17,8 @@ export const e2eMinimalProject = defineProject({
LODESTAR_PRESET: "minimal",
},
pool: "forks",
poolOptions: {
forks: {
singleFork: true,
},
},
maxWorkers: 1,
isolate: false,
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This combination will replace singleFork: true in from older version

sequence: {
concurrent: false,
shuffle: false,
Expand All @@ -43,11 +40,8 @@ export const e2eMainnetProject = defineProject({
LODESTAR_PRESET: "mainnet",
},
pool: "forks",
poolOptions: {
forks: {
singleFork: true,
},
},
maxWorkers: 1,
isolate: false,
sequence: {
concurrent: false,
shuffle: false,
Expand Down
16 changes: 2 additions & 14 deletions configs/vitest.config.unit.ts
Original file line number Diff line number Diff line change
Expand Up @@ -7,19 +7,12 @@ const setupFiles = [
path.join(import.meta.dirname, "../scripts/vitest/setupFiles/lodestarPreset.ts"),
];

const isBun = "bun" in process.versions;

export const unitTestMinimalProject = defineProject({
test: {
name: "unit-minimal",
include: ["**/test/unit-minimal/**/*.test.ts"],
setupFiles,
// Current vitest `forks` pool is not yet supported with Bun
// so we conditionally switch to our custom pool which run tests in main process
pool: isBun ? "vitest-in-process-pool" : "forks",
poolOptions: {
forks: isBun ? {singleFork: true} : {},
},
pool: "forks",
env: {
LODESTAR_PRESET: "minimal",
},
Expand All @@ -39,12 +32,7 @@ export const unitTestMainnetProject = defineProject({
// for now I tried to identify such tests an increase the limit a bit higher
testTimeout: 20_000,
hookTimeout: 20_000,
// Current vitest `forks` pool is not yet supported with Bun
// so we conditionally switch to our custom pool which run tests in main process
pool: isBun ? "vitest-in-process-pool" : "forks",
poolOptions: {
forks: isBun ? {singleFork: true} : {},
},
pool: "forks",
env: {
LODESTAR_PRESET: "mainnet",
},
Expand Down
18 changes: 8 additions & 10 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -47,8 +47,8 @@
"@chainsafe/biomejs-config": "^1.0.0",
"@types/node": "^22.18.6",
"@types/react": "^19.1.12",
"@vitest/browser": "3.0.9",
"@vitest/coverage-v8": "3.0.9",
"@vitest/browser": "^4.0.6",
"@vitest/coverage-v8": "^4.0.6",
"bun-types": "^1.2.21",
"crypto-browserify": "^3.12.0",
"dotenv": "^16.4.5",
Expand All @@ -70,20 +70,18 @@
"typescript": "^5.9.2",
"typescript-docs-verifier": "^3.0.1",
"vite": "^6.0.11",
"vite-plugin-dts": "^4.5.0",
"vite-plugin-node-polyfills": "^0.23.0",
"vite-plugin-top-level-await": "^1.5.0",
"vitest": "3.0.9",
"vitest-in-process-pool": "2.0.1",
"vitest-when": "^0.6.1",
"vite-plugin-dts": "^4.5.4",
"vite-plugin-node-polyfills": "^0.24.0",
"vite-plugin-top-level-await": "^1.6.0",
"vitest": "^4.0.6",
"vitest-when": "^0.9.0",
"wait-port": "^1.1.0",
"webdriverio": "^9.7.2"
"webdriverio": "^9.20.0"
},
"resolutions": {
"dns-over-http-resolver": "^2.1.1",
"loupe": "^2.3.6",
"testcontainers/**/nan": "^2.19.0",
"vitest": "3.0.9",
"elliptic": ">=6.6.1"
}
}
3 changes: 2 additions & 1 deletion packages/beacon-node/test/mocks/mockedBeaconChain.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@
import {ChainForkConfig} from "@lodestar/config";
import {config as defaultConfig} from "@lodestar/config/default";
import {EpochDifference, ForkChoice, ProtoBlock} from "@lodestar/fork-choice";
import {CachedBeaconStateAllForks} from "@lodestar/state-transition";
import {Logger} from "@lodestar/utils";
import {BeaconProposerCache} from "../../src/chain/beaconProposerCache.js";
import {BeaconChain} from "../../src/chain/chain.js";
Expand All @@ -20,7 +21,7 @@

export type MockedBeaconChain = Mocked<BeaconChain> & {
logger: Mocked<Logger>;
getHeadState: Mock;
getHeadState: Mocked<CachedBeaconStateAllForks>;
forkChoice: MockedForkChoice;
executionEngine: Mocked<ExecutionEngineHttp>;
executionBuilder: Mocked<ExecutionBuilderHttp>;
Expand Down Expand Up @@ -197,7 +198,7 @@

export function getMockedForkChoice(): MockedForkChoice {
// ForkChoice package is mocked globally
return vi.mocked(new ForkChoice({} as any, {} as any, {} as any, {} as any, {} as any));

Check failure on line 201 in packages/beacon-node/test/mocks/mockedBeaconChain.ts

View workflow job for this annotation

GitHub Actions / Unit Tests (22)

packages/beacon-node/test/unit-minimal/chain/opPools/aggregatedAttestationPool.test.ts > AggregatedAttestationPool - get packed attestations - Electra > Committee 1 and 2 has 2 versions of aggregationBits - only 1 attestation is included

TypeError: () => { return { updateTime: __vite_ssr_import_0__.vi.fn(), getJustifiedBlock: __vite_ssr_impor...<omitted>... } is not a constructor ❯ getMockedForkChoice packages/beacon-node/test/mocks/mockedBeaconChain.ts:201:20 ❯ packages/beacon-node/test/unit-minimal/chain/opPools/aggregatedAttestationPool.test.ts:219:22

Check failure on line 201 in packages/beacon-node/test/mocks/mockedBeaconChain.ts

View workflow job for this annotation

GitHub Actions / Unit Tests (22)

packages/beacon-node/test/unit-minimal/chain/opPools/aggregatedAttestationPool.test.ts > AggregatedAttestationPool - get packed attestations - Electra > Committee 1 and 2 has 2 versions of aggregationBits

TypeError: () => { return { updateTime: __vite_ssr_import_0__.vi.fn(), getJustifiedBlock: __vite_ssr_impor...<omitted>... } is not a constructor ❯ getMockedForkChoice packages/beacon-node/test/mocks/mockedBeaconChain.ts:201:20 ❯ packages/beacon-node/test/unit-minimal/chain/opPools/aggregatedAttestationPool.test.ts:219:22

Check failure on line 201 in packages/beacon-node/test/mocks/mockedBeaconChain.ts

View workflow job for this annotation

GitHub Actions / Unit Tests (22)

packages/beacon-node/test/unit-minimal/chain/opPools/aggregatedAttestationPool.test.ts > AggregatedAttestationPool - get packed attestations - Electra > Full participation but all are seen in the state

TypeError: () => { return { updateTime: __vite_ssr_import_0__.vi.fn(), getJustifiedBlock: __vite_ssr_impor...<omitted>... } is not a constructor ❯ getMockedForkChoice packages/beacon-node/test/mocks/mockedBeaconChain.ts:201:20 ❯ packages/beacon-node/test/unit-minimal/chain/opPools/aggregatedAttestationPool.test.ts:219:22

Check failure on line 201 in packages/beacon-node/test/mocks/mockedBeaconChain.ts

View workflow job for this annotation

GitHub Actions / Unit Tests (22)

packages/beacon-node/test/unit-minimal/chain/opPools/aggregatedAttestationPool.test.ts > AggregatedAttestationPool - get packed attestations - Electra > Full participation

TypeError: () => { return { updateTime: __vite_ssr_import_0__.vi.fn(), getJustifiedBlock: __vite_ssr_impor...<omitted>... } is not a constructor ❯ getMockedForkChoice packages/beacon-node/test/mocks/mockedBeaconChain.ts:201:20 ❯ packages/beacon-node/test/unit-minimal/chain/opPools/aggregatedAttestationPool.test.ts:219:22

Check failure on line 201 in packages/beacon-node/test/mocks/mockedBeaconChain.ts

View workflow job for this annotation

GitHub Actions / Unit Tests (22)

packages/beacon-node/test/unit-minimal/chain/opPools/aggregatedAttestationPool.test.ts > AggregatedAttestationPool - Altair > incompatible shuffling - incorrect pivot block root

TypeError: () => { return { updateTime: __vite_ssr_import_0__.vi.fn(), getJustifiedBlock: __vite_ssr_impor...<omitted>... } is not a constructor ❯ getMockedForkChoice packages/beacon-node/test/mocks/mockedBeaconChain.ts:201:20 ❯ packages/beacon-node/test/unit-minimal/chain/opPools/aggregatedAttestationPool.test.ts:100:22

Check failure on line 201 in packages/beacon-node/test/mocks/mockedBeaconChain.ts

View workflow job for this annotation

GitHub Actions / Unit Tests (22)

packages/beacon-node/test/unit-minimal/chain/opPools/aggregatedAttestationPool.test.ts > AggregatedAttestationPool - Altair > incorrect source

TypeError: () => { return { updateTime: __vite_ssr_import_0__.vi.fn(), getJustifiedBlock: __vite_ssr_impor...<omitted>... } is not a constructor ❯ getMockedForkChoice packages/beacon-node/test/mocks/mockedBeaconChain.ts:201:20 ❯ packages/beacon-node/test/unit-minimal/chain/opPools/aggregatedAttestationPool.test.ts:100:22

Check failure on line 201 in packages/beacon-node/test/mocks/mockedBeaconChain.ts

View workflow job for this annotation

GitHub Actions / Unit Tests (22)

packages/beacon-node/test/unit-minimal/chain/opPools/aggregatedAttestationPool.test.ts > AggregatedAttestationPool - Altair > one is seen and one is NOT

TypeError: () => { return { updateTime: __vite_ssr_import_0__.vi.fn(), getJustifiedBlock: __vite_ssr_impor...<omitted>... } is not a constructor ❯ getMockedForkChoice packages/beacon-node/test/mocks/mockedBeaconChain.ts:201:20 ❯ packages/beacon-node/test/unit-minimal/chain/opPools/aggregatedAttestationPool.test.ts:100:22

Check failure on line 201 in packages/beacon-node/test/mocks/mockedBeaconChain.ts

View workflow job for this annotation

GitHub Actions / Unit Tests (22)

packages/beacon-node/test/unit-minimal/chain/opPools/aggregatedAttestationPool.test.ts > AggregatedAttestationPool - Altair > all validators are NOT seen

TypeError: () => { return { updateTime: __vite_ssr_import_0__.vi.fn(), getJustifiedBlock: __vite_ssr_impor...<omitted>... } is not a constructor ❯ getMockedForkChoice packages/beacon-node/test/mocks/mockedBeaconChain.ts:201:20 ❯ packages/beacon-node/test/unit-minimal/chain/opPools/aggregatedAttestationPool.test.ts:100:22

Check failure on line 201 in packages/beacon-node/test/mocks/mockedBeaconChain.ts

View workflow job for this annotation

GitHub Actions / Unit Tests (22)

packages/beacon-node/test/unit-minimal/chain/opPools/aggregatedAttestationPool.test.ts > AggregatedAttestationPool - Altair > all validators are seen

TypeError: () => { return { updateTime: __vite_ssr_import_0__.vi.fn(), getJustifiedBlock: __vite_ssr_impor...<omitted>... } is not a constructor ❯ getMockedForkChoice packages/beacon-node/test/mocks/mockedBeaconChain.ts:201:20 ❯ packages/beacon-node/test/unit-minimal/chain/opPools/aggregatedAttestationPool.test.ts:100:22

Check failure on line 201 in packages/beacon-node/test/mocks/mockedBeaconChain.ts

View workflow job for this annotation

GitHub Actions / Unit Tests (22)

packages/beacon-node/test/unit-minimal/chain/opPools/aggregatedAttestationPool.test.ts > AggregatedAttestationPool - Altair > getNotSeenValidatorsFn

TypeError: () => { return { updateTime: __vite_ssr_import_0__.vi.fn(), getJustifiedBlock: __vite_ssr_impor...<omitted>... } is not a constructor ❯ getMockedForkChoice packages/beacon-node/test/mocks/mockedBeaconChain.ts:201:20 ❯ packages/beacon-node/test/unit-minimal/chain/opPools/aggregatedAttestationPool.test.ts:100:22
}

// To avoid loading the package in test while mocked, exporting frequently used types and constants
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -66,7 +66,7 @@ describe("validate voluntary exit", () => {
vi.spyOn(chainStub, "getHeadStateAtCurrentEpoch").mockResolvedValue(state);
vi.spyOn(opPool, "hasSeenBlsToExecutionChange");
vi.spyOn(opPool, "hasSeenVoluntaryExit");
vi.spyOn(chainStub.bls, "verifySignatureSets").mockResolvedValue(true);
chainStub.bls.verifySignatureSets.mockResolvedValue(true);
});

afterEach(() => {
Expand Down Expand Up @@ -165,7 +165,7 @@ describe("validate voluntary exit", () => {

opPool.hasSeenVoluntaryExit.mockReturnValue(false);

vi.spyOn(chainStub.bls, "verifySignatureSets").mockResolvedValue(false);
chainStub.bls.verifySignatureSets.mockResolvedValue(false);

await expectRejectedWithLodestarError(
validateGossipVoluntaryExit(chainStub, signedVoluntaryExitInvalidSig),
Expand Down
5 changes: 3 additions & 2 deletions packages/beacon-node/test/unit/sync/unknownBlock.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,8 @@ import {getRandPeerIdStr, getRandPeerSyncMeta} from "../../utils/peer.js";

describe.skip(
"sync by UnknownBlockSync",
// spacer comment to avoid unnecessary changes in git
{timeout: 20_000},
() => {
const logger = testLogger();
const slotSec = 0.3;
Expand Down Expand Up @@ -258,8 +260,7 @@ describe.skip(
syncService.close();
});
}
},
{timeout: 20_000}
}
);

describe("UnknownBlockSync", () => {
Expand Down
8 changes: 6 additions & 2 deletions packages/cli/test/utils/runUtils.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
import fs from "node:fs";
import {expect} from "vitest";
import {DeeplyAllowMatchers, expect} from "vitest";
import {apiTokenFileName} from "../../src/cmds/validator/keymanager/server.js";
import {recursiveLookup} from "../../src/util/index.js";

Expand All @@ -23,7 +23,11 @@ export function expectDeepEquals<T>(a: T, b: T, message: string): void {
/**
* Similar to `expectDeepEquals` but only checks presence of all elements in array, irrespective of their order.
*/
export function expectDeepEqualsUnordered<T>(a: T[], b: T[], message: string): void {
export function expectDeepEqualsUnordered<T>(
a: DeeplyAllowMatchers<T>[],
b: DeeplyAllowMatchers<T>[],
message: string
): void {
expect(a).toEqualWithMessage(expect.arrayContaining(b), message);
expect(b).toEqualWithMessage(expect.arrayContaining(a), message);
expect(a).toHaveLength(b.length);
Expand Down
4 changes: 2 additions & 2 deletions packages/spec-test-util/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -57,9 +57,9 @@
"@lodestar/utils": "^1.35.0",
"rimraf": "^4.4.1",
"snappyjs": "^0.7.0",
"vitest": "3.0.9"
"vitest": "^4.0.6"
},
"peerDependencies": {
"vitest": "3.0.9"
"vitest": "^4.0.6"
}
}
4 changes: 2 additions & 2 deletions packages/test-utils/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -57,12 +57,12 @@
"axios": "^1.3.4",
"testcontainers": "^10.2.1",
"tmp": "^0.2.1",
"vitest": "3.0.9"
"vitest": "^4.0.6"
},
"devDependencies": {
"@types/yargs": "^17.0.24"
},
"peerDependencies": {
"vitest": "3.0.9"
"vitest": "^4.0.6"
}
}
32 changes: 32 additions & 0 deletions scripts/vite/plugins/esmCjsInteropPlugin.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,32 @@
import { createRequire } from "node:module";
import {UserConfig, ConfigEnv, Plugin} from "vite";

const require = createRequire(import.meta.url);
const prettyFormatCjsPath = require.resolve("../../../node_modules/pretty-format/build/index.js");

const isBun = "bun" in process.versions;

// This plugin is developed to overcome an esm resolution issue in Bun runtime.
// TODO: Should remove this plugin when following issue is resolved
// https://github.com/oven-sh/bun/issues/24341
export function esmCjsInteropPlugin(): Plugin {
return {
name: "esmCjsInteropPlugin",
config(_config: UserConfig, _env: ConfigEnv) {
if(!isBun) return {};

return {
test: {
server: {
deps: {
inline: ["pretty-format", "vitest-when"],
},
}
},
resolve: {
alias: [{find: /^pretty-format$/, replacement: prettyFormatCjsPath}],
},
};
},
};
}
2 changes: 1 addition & 1 deletion types/vitest/index.d.ts
Original file line number Diff line number Diff line change
Expand Up @@ -41,6 +41,6 @@ interface CustomAsymmetricMatchers<R = unknown> extends CustomMatchers<R> {
}

declare module "vitest" {
interface Assertion<T = any> extends CustomMatchers<T> {}
interface Assertion<T = any> extends CustomMatchers<T> {}
interface AsymmetricMatchersContaining extends CustomAsymmetricMatchers {}
}
18 changes: 8 additions & 10 deletions vitest.config.ts
Original file line number Diff line number Diff line change
@@ -1,24 +1,23 @@
import path from "node:path";
import {ViteUserConfig, defineConfig} from "vitest/config";
import {TestUserConfig, defineConfig} from "vitest/config";
import {browserTestProject} from "./configs/vitest.config.browser.js";
import {e2eMainnetProject, e2eMinimalProject} from "./configs/vitest.config.e2e.js";
import {specProjectMainnet, specProjectMinimal} from "./configs/vitest.config.spec.js";
import {typesTestProject} from "./configs/vitest.config.types.js";
import {unitTestMainnetProject, unitTestMinimalProject} from "./configs/vitest.config.unit.js";
import {esmCjsInteropPlugin} from "./scripts/vite/plugins/esmCjsInteropPlugin.js";

const isBun = "bun" in process.versions;

export function getReporters(): ViteUserConfig["test"]["reporters"] {
if (isBun) return [["default", {summary: false}]];
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

That was hack to for older process pool, not needed now.

if (process.env.GITHUB_ACTIONS) return ["verbose", "hanging-process", "github-actions"];
export function getReporters(): TestUserConfig["reporters"] {
if (process.env.GITHUB_ACTIONS) return ["tree", "hanging-process", "github-actions"];
if (process.env.TEST_COMPACT_OUTPUT) return ["basic", "hanging-process"];

return ["verbose", "hanging-process"];
return ["tree", "hanging-process"];
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Newer verbose reporter print flat output, and tree replaces to old verbose formatter.

}

export default defineConfig({
plugins: [esmCjsInteropPlugin()],
test: {
workspace: [
projects: [
{
extends: true,
...unitTestMinimalProject,
Expand Down Expand Up @@ -77,9 +76,8 @@ export default defineConfig({
onConsoleLog: () => !process.env.TEST_QUIET_CONSOLE,
coverage: {
enabled: false,
include: ["packages/**/src/**.{ts}"],
clean: true,
all: false,
extension: [".ts"],
provider: "v8",
reporter: [["lcovonly", {file: "lcov.info"}], ["text"]],
reportsDirectory: "./coverage",
Expand Down
Loading
Loading