Skip to content
Open
Show file tree
Hide file tree
Changes from all 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
6 changes: 2 additions & 4 deletions .github/workflows/test.yml
Original file line number Diff line number Diff line change
Expand Up @@ -175,10 +175,8 @@ jobs:
- uses: "./.github/actions/setup-and-build"
with:
node: ${{ matrix.node }}
- name: Install Chrome browser
run: npx @puppeteer/browsers install chromedriver@stable --path /tmp
- name: Install Firefox browser
run: npx @puppeteer/browsers install firefox@stable --path /tmp
- name: Install
run: yarn playwright install
- name: Browser tests
run: |
export DISPLAY=':99.0'
Expand Down
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
22 changes: 5 additions & 17 deletions configs/vitest.config.browser.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,5 @@
/// <reference types="@vitest/browser/providers/webdriverio" />

import path from "node:path";
import {playwright} from "@vitest/browser-playwright";
import {nodePolyfills} from "vite-plugin-node-polyfills";
import {defineProject} from "vitest/config";
import {blsBrowserPlugin} from "../scripts/vite/plugins/blsBrowserPlugin.js";
Expand All @@ -21,29 +20,18 @@ export const browserTestProject = defineProject({
headless: true,
ui: false,
screenshotFailures: false,
// Recommended provider is `playwright` but it's causing following error on CI
// Error: Failed to connect to the browser session "af5be85a-7f29-4299-b680-b07f0cfc2520" within the timeout.
// TODO: Debug the issue in later versions of playwright and vitest
provider: "webdriverio",
provider: playwright(),
connectTimeout: 90_0000,
instances: [
// TODO: Add support for webkit when available
// Invalid types from webdriverio for capabilities
{
browser: "firefox",
maxConcurrency: 1,
capabilities: {
browserVersion: "stable",
},
} as never,
// Invalid types from webdriverio for capabilities
},
{
browser: "chrome",
browser: "chromium",
maxConcurrency: 1,
capabilities: {
browserVersion: "stable",
},
} as never,
},
],
},
},
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: true,
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: true,
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
21 changes: 10 additions & 11 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -47,8 +47,9 @@
"@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.7",
"@vitest/browser-playwright": "^4.0.7",
"@vitest/coverage-v8": "^4.0.7",
"bun-types": "^1.2.21",
"crypto-browserify": "^3.12.0",
"dotenv": "^16.4.5",
Expand All @@ -60,6 +61,7 @@
"node-gyp": "^9.4.0",
"npm-run-all": "^4.1.5",
"path-browserify": "^1.0.1",
"playwright": "^1.56.1",
"prettier": "^3.2.5",
"process": "^0.11.10",
"rollup-plugin-visualizer": "^5.12.0",
Expand All @@ -70,20 +72,17 @@
"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",
"wait-port": "^1.1.0",
"webdriverio": "^9.7.2"
"vite-plugin-dts": "^4.5.4",
"vite-plugin-node-polyfills": "^0.24.0",
"vite-plugin-top-level-await": "^1.6.0",
"vitest": "^4.0.7",
"vitest-when": "^0.9.0",
"wait-port": "^1.1.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"
}
}
2 changes: 1 addition & 1 deletion packages/beacon-node/test/mocks/beaconSyncMock.ts
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ export type MockedBeaconSync = Mocked<BeaconSync>;
vi.mock("../../src/sync/index.js", async (importActual) => {
const mod = await importActual<typeof import("../../src/sync/index.js")>();

const BeaconSync = vi.fn().mockImplementation(() => {
const BeaconSync = vi.fn().mockImplementation(function MockedBeaconSync() {
const sync = {
isSynced: vi.fn(),
};
Expand Down
125 changes: 63 additions & 62 deletions packages/beacon-node/test/mocks/mockedBeaconChain.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@ import {PubkeyIndexMap} from "@chainsafe/pubkey-index-map";
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 @@ import {getMockedLogger} from "./loggerMock.js";

export type MockedBeaconChain = Mocked<BeaconChain> & {
logger: Mocked<Logger>;
getHeadState: Mock;
getHeadState: Mocked<CachedBeaconStateAllForks>;
forkChoice: MockedForkChoice;
executionEngine: Mocked<ExecutionEngineHttp>;
executionBuilder: Mocked<ExecutionBuilderHttp>;
Expand All @@ -43,7 +44,7 @@ export type MockedBeaconChain = Mocked<BeaconChain> & {
vi.mock("@lodestar/fork-choice", async (importActual) => {
const mod = await importActual<typeof import("@lodestar/fork-choice")>();

const ForkChoice = vi.fn().mockImplementation(() => {
const ForkChoice = vi.fn().mockImplementation(function MockedForkChoice() {
return {
updateTime: vi.fn(),
getJustifiedBlock: vi.fn(),
Expand Down Expand Up @@ -80,7 +81,7 @@ vi.mock("../../src/chain/lightClient/index.js");
vi.mock("../../src/chain/opPools/index.js", async (importActual) => {
const mod = await importActual<typeof import("../../src/chain/opPools/index.js")>();

const OpPool = vi.fn().mockImplementation(() => {
const OpPool = vi.fn().mockImplementation(function MockedOpPool() {
return {
hasSeenBlsToExecutionChange: vi.fn(),
hasSeenVoluntaryExit: vi.fn(),
Expand All @@ -90,13 +91,13 @@ vi.mock("../../src/chain/opPools/index.js", async (importActual) => {
};
});

const AggregatedAttestationPool = vi.fn().mockImplementation(() => {
const AggregatedAttestationPool = vi.fn().mockImplementation(function MockedAggregatedAttestationPool() {
return {
getAttestationsForBlock: vi.fn(),
};
});

const SyncContributionAndProofPool = vi.fn().mockImplementation(() => {
const SyncContributionAndProofPool = vi.fn().mockImplementation(function MockedSyncContributionAndProofPool() {
return {
getAggregate: vi.fn(),
};
Expand All @@ -113,63 +114,63 @@ vi.mock("../../src/chain/opPools/index.js", async (importActual) => {
vi.mock("../../src/chain/chain.js", async (importActual) => {
const mod = await importActual<typeof import("../../src/chain/chain.js")>();

const BeaconChain = vi
.fn()
.mockImplementation(({clock: clockParam, genesisTime, config}: MockedBeaconChainOptions) => {
const logger = getMockedLogger();
const clock =
clockParam === "real"
? new Clock({config, genesisTime, signal: new AbortController().signal})
: getMockedClock();

return {
config,
opts: {},
genesisTime,
clock,
forkChoice: getMockedForkChoice(),
executionEngine: {
notifyForkchoiceUpdate: vi.fn(),
getPayload: vi.fn(),
getClientVersion: vi.fn(),
},
executionBuilder: {},
// @ts-expect-error
eth1: new Eth1ForBlockProduction(),
opPool: new OpPool(),
aggregatedAttestationPool: new AggregatedAttestationPool(config),
syncContributionAndProofPool: new SyncContributionAndProofPool(config, clock),
// @ts-expect-error
beaconProposerCache: new BeaconProposerCache(),
shufflingCache: new ShufflingCache(),
pubkey2index: new PubkeyIndexMap(),
index2pubkey: [],
produceCommonBlockBody: vi.fn(),
getProposerHead: vi.fn(),
produceBlock: vi.fn(),
produceBlindedBlock: vi.fn(),
getCanonicalBlockAtSlot: vi.fn(),
recomputeForkChoiceHead: vi.fn(),
predictProposerHead: vi.fn(),
getHeadStateAtCurrentEpoch: vi.fn(),
getHeadState: vi.fn(),
getStateBySlot: vi.fn(),
updateBuilderStatus: vi.fn(),
processBlock: vi.fn(),
regenStateForAttestationVerification: vi.fn(),
close: vi.fn(),
logger,
regen: new QueuedStateRegenerator({} as any),
lightClientServer: new LightClientServer({} as any, {} as any),
bls: {
verifySignatureSets: vi.fn().mockResolvedValue(true),
verifySignatureSetsSameMessage: vi.fn().mockResolvedValue([true]),
close: vi.fn().mockResolvedValue(true),
canAcceptWork: vi.fn().mockReturnValue(true),
},
emitter: new ChainEventEmitter(),
};
});
const BeaconChain = vi.fn().mockImplementation(function MockedBeaconChain({
clock: clockParam,
genesisTime,
config,
}: MockedBeaconChainOptions) {
const logger = getMockedLogger();
const clock =
clockParam === "real" ? new Clock({config, genesisTime, signal: new AbortController().signal}) : getMockedClock();

return {
config,
opts: {},
genesisTime,
clock,
forkChoice: getMockedForkChoice(),
executionEngine: {
notifyForkchoiceUpdate: vi.fn(),
getPayload: vi.fn(),
getClientVersion: vi.fn(),
},
executionBuilder: {},
// @ts-expect-error
eth1: new Eth1ForBlockProduction(),
opPool: new OpPool(),
aggregatedAttestationPool: new AggregatedAttestationPool(config),
syncContributionAndProofPool: new SyncContributionAndProofPool(config, clock),
// @ts-expect-error
beaconProposerCache: new BeaconProposerCache(),
shufflingCache: new ShufflingCache(),
pubkey2index: new PubkeyIndexMap(),
index2pubkey: [],
produceCommonBlockBody: vi.fn(),
getProposerHead: vi.fn(),
produceBlock: vi.fn(),
produceBlindedBlock: vi.fn(),
getCanonicalBlockAtSlot: vi.fn(),
recomputeForkChoiceHead: vi.fn(),
predictProposerHead: vi.fn(),
getHeadStateAtCurrentEpoch: vi.fn(),
getHeadState: vi.fn(),
getStateBySlot: vi.fn(),
updateBuilderStatus: vi.fn(),
processBlock: vi.fn(),
regenStateForAttestationVerification: vi.fn(),
close: vi.fn(),
logger,
regen: new QueuedStateRegenerator({} as any),
lightClientServer: new LightClientServer({} as any, {} as any),
bls: {
verifySignatureSets: vi.fn().mockResolvedValue(true),
verifySignatureSetsSameMessage: vi.fn().mockResolvedValue([true]),
close: vi.fn().mockResolvedValue(true),
canAcceptWork: vi.fn().mockReturnValue(true),
},
emitter: new ChainEventEmitter(),
};
});

return {
...mod,
Expand Down
2 changes: 1 addition & 1 deletion packages/beacon-node/test/mocks/mockedBeaconDb.ts
Original file line number Diff line number Diff line change
Expand Up @@ -45,7 +45,7 @@ vi.mock("../../src/db/repositories/index.js");
vi.mock("../../src/db/index.js", async (importActual) => {
const mod = await importActual<typeof import("../../src/db/index.js")>();

const mockedBeaconDb = vi.fn().mockImplementation(() => {
const mockedBeaconDb = vi.fn().mockImplementation(function MockedBeaconDb() {
return {
block: vi.mocked(new BlockRepository({} as any, {} as any)),
blockArchive: vi.mocked(new BlockArchiveRepository({} as any, {} as any)),
Expand Down
2 changes: 1 addition & 1 deletion packages/beacon-node/test/mocks/mockedNetwork.ts
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ import {INetwork, Network} from "../../src/network/index.js";
vi.mock("../../src/network/index.js", async (importActual) => {
const mod = await importActual<typeof import("../../src/network/index.js")>();

const Network = vi.fn().mockImplementation(() => {
const Network = vi.fn().mockImplementation(function MockedNetwork() {
return {};
});

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -12,13 +12,13 @@ vi.mock("../../../../../src/chain/index.js", async (importActual) => {

return {
...mod,
BeaconChain: vi.spyOn(mod, "BeaconChain").mockImplementation(() => {
BeaconChain: vi.spyOn(mod, "BeaconChain").mockImplementation(function MockedBeaconChain() {
return {
emitter: new ChainEventEmitter(),
forkChoice: {
getHead: vi.fn(),
},
} as unknown as BeaconChain;
};
}),
};
});
Expand Down
Loading
Loading