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

test(prover): move tests for prover to vitest #6074

Merged
merged 40 commits into from
Dec 8, 2023
Merged
Show file tree
Hide file tree
Changes from 39 commits
Commits
Show all changes
40 commits
Select commit Hold shift + click to select a range
1436803
Automatic assertion migration
nazarhussain Oct 13, 2023
3d2bc6e
Fix some left over assertions
nazarhussain Oct 13, 2023
956c4ea
Remove sinon
nazarhussain Oct 13, 2023
afe61cd
Add config files
nazarhussain Oct 13, 2023
460cd2c
Move browser tests to vitest
nazarhussain Oct 20, 2023
b0e26bd
Fix browser tests
nazarhussain Oct 23, 2023
fb4ac25
Add a skip lib check for now
nazarhussain Oct 25, 2023
570338b
Fix the spellings
nazarhussain Oct 30, 2023
f089268
Fix deprecated flags
nazarhussain Oct 30, 2023
2abdd1b
Fix types
nazarhussain Oct 30, 2023
21dd0e7
Update the script tasks
nazarhussain Oct 30, 2023
74cc49a
Fix the e2e tests
nazarhussain Oct 30, 2023
fc6cac1
Fix e2e tests
nazarhussain Oct 31, 2023
d94ebe8
Update webdriverio to fix browser installtion issue
nazarhussain Oct 31, 2023
2c98394
Fix the vitest config
nazarhussain Oct 31, 2023
69a52ef
Add a peer dependency
nazarhussain Oct 31, 2023
0d53b98
Add vite resolution
nazarhussain Oct 31, 2023
acb63b1
Add a manual install for browsers
nazarhussain Oct 31, 2023
e9477ac
Update packages to support additional browser options
nazarhussain Oct 31, 2023
6b8d8ad
Update the resolutions
nazarhussain Oct 31, 2023
5c9e732
Add resolutions to fix dependencies
nazarhussain Nov 6, 2023
bc6fd24
Update the yarn linter script
nazarhussain Nov 6, 2023
c659b45
Add sigfault handler
nazarhussain Nov 8, 2023
f01783a
Rebuild native modules with debug flag
nazarhussain Nov 9, 2023
9034984
Update depedencies
nazarhussain Dec 1, 2023
6f5a50b
Update e2e tests
nazarhussain Dec 1, 2023
980539e
Update dependencies
nazarhussain Dec 1, 2023
e2ae63b
Add browser capabilities
nazarhussain Dec 1, 2023
4e61a67
Revert a whitespace change
nazarhussain Dec 1, 2023
c8be9ac
Remove segfault handler
nazarhussain Dec 1, 2023
7c2fcc1
Remove native dep for lightclient
nazarhussain Dec 1, 2023
a6e1e35
Add debug flag to introspect error
nazarhussain Dec 1, 2023
e6e8be9
Rename a file
nazarhussain Dec 4, 2023
3be4385
Upgrade the vitest package
nazarhussain Dec 5, 2023
52c26dc
Fix the regressions introduced in vitest 1 >
nazarhussain Dec 5, 2023
06c9575
Revert the regression of vitest 1.0.1
nazarhussain Dec 7, 2023
a8a9965
Clean dependencies
nazarhussain Dec 7, 2023
fea8090
Update multiple fork fix
nazarhussain Dec 7, 2023
dc63b2c
Add dependency fix
nazarhussain Dec 7, 2023
2e8d0a0
Fix broken singleThread option for e2e
nazarhussain Dec 7, 2023
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: 4 additions & 1 deletion .github/workflows/test.yml
Original file line number Diff line number Diff line change
Expand Up @@ -270,7 +270,10 @@ jobs:
packages/*/.git-data.json
key: ${{ runner.os }}-node-${{ matrix.node }}-${{ github.sha }}
fail-on-cache-miss: true

- name: Install Chrome browser
run: npx @puppeteer/browsers install chrome
- name: Install Firefox browser
run: npx @puppeteer/browsers install firefox
- name: Browser tests
run: |
export DISPLAY=':99.0'
Expand Down
23 changes: 15 additions & 8 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -52,19 +52,22 @@
"@types/sinon-chai": "^3.2.9",
"@typescript-eslint/eslint-plugin": "6.7.2",
"@typescript-eslint/parser": "6.7.2",
"@vitest/coverage-v8": "^1.0.1",
"@vitest/browser": "^1.0.1",
"c8": "^8.0.1",
"chai": "^4.3.8",
"chai-as-promised": "^7.1.1",
"codecov": "^3.8.3",
"crypto-browserify": "^3.12.0",
"electron": "^26.2.2",
"eslint": "^8.50.0",
"eslint-plugin-import": "^2.28.1",
"eslint-plugin-prettier": "^5.0.0",
"eslint-import-resolver-typescript": "^3.6.1",
"eslint-plugin-chai-expect": "^3.0.0",
"eslint-plugin-import": "^2.28.1",
"eslint-plugin-mocha": "^10.2.0",
"eslint-import-resolver-typescript": "^3.6.1",
"eslint-plugin-prettier": "^5.0.0",
"https-browserify": "^1.0.0",
"jsdom": "^23.0.1",
"karma": "^6.4.2",
"karma-chai": "^0.1.0",
"karma-chrome-launcher": "^3.2.0",
Expand Down Expand Up @@ -93,13 +96,17 @@
"ts-node": "^10.9.1",
"typescript": "^5.2.2",
"typescript-docs-verifier": "^2.5.0",
"webpack": "^5.88.2",
"vite-plugin-node-polyfills": "^0.17.0",
"vite-plugin-top-level-await": "^1.3.1",
"vitest": "^1.0.2",
"vitest-when": "^0.3.0",
"wait-port": "^1.1.0",
"vitest": "^0.34.6",
"vitest-when": "^0.2.0",
"@vitest/coverage-v8": "^0.34.6"
"webdriverio": "^8.24.12",
"webpack": "^5.88.2"
},
"resolutions": {
"dns-over-http-resolver": "^2.1.1"
"dns-over-http-resolver": "^2.1.1",
"chai": "^4.3.10",
"loupe": "^2.3.6"
}
}
2 changes: 1 addition & 1 deletion packages/beacon-node/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -80,7 +80,7 @@
"test:unit:minimal": "vitest --run --segfaultRetry 3 --dir test/unit/ --coverage",
"test:unit:mainnet": "LODESTAR_PRESET=mainnet nyc --cache-dir .nyc_output/.cache -e .ts mocha 'test/unit-mainnet/**/*.test.ts'",
"test:unit": "yarn test:unit:minimal && yarn test:unit:mainnet",
"test:e2e": "LODESTAR_PRESET=minimal vitest --run --segfaultRetry 3 --single-thread --dir test/e2e",
"test:e2e": "LODESTAR_PRESET=minimal vitest --run --segfaultRetry 3 --poolOptions.threads.singleFork --dir test/e2e",
"test:sim": "mocha 'test/sim/**/*.test.ts'",
"test:sim:merge-interop": "mocha 'test/sim/merge-interop.test.ts'",
"test:sim:mergemock": "mocha 'test/sim/mergemock.test.ts'",
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -38,7 +38,7 @@ describe("chain / opPools / SyncCommitteeMessagePool", function () {
vi.clearAllMocks();
});

it("should preaggregate SyncCommitteeContribution", () => {
it("should propagate SyncCommitteeContribution", () => {
clockStub.secFromSlot.mockReturnValue(0);
let contribution = cache.getContribution(subcommitteeIndex, syncCommittee.slot, syncCommittee.beaconBlockRoot);
expect(contribution).not.toBeNull();
Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import {describe, it, expect, beforeEach, afterEach, vi, SpyInstance, Mock} from "vitest";
import {describe, it, expect, beforeEach, afterEach, vi, Mock, MockInstance} from "vitest";
import {config} from "@lodestar/config/default";
import {ForkName, SLOTS_PER_EPOCH} from "@lodestar/params";
import {routes} from "@lodestar/api";
Expand All @@ -20,7 +20,7 @@ describe("PrepareNextSlot scheduler", () => {
let regenStub: MockedBeaconChain["regen"];
let loggerStub: MockedLogger;
let beaconProposerCacheStub: MockedBeaconChain["beaconProposerCache"];
let getForkStub: SpyInstance<[number], ForkName>;
let getForkStub: MockInstance<[number], ForkName>;
let updateBuilderStatus: MockedBeaconChain["updateBuilderStatus"];
jeluard marked this conversation as resolved.
Show resolved Hide resolved
let executionEngineStub: MockedBeaconChain["executionEngine"];
const emitPayloadAttributes = true;
Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import {describe, it, expect, beforeEach, afterEach, vi, SpyInstance} from "vitest";
import {describe, it, expect, beforeEach, afterEach, vi, MockInstance} from "vitest";
import {config} from "@lodestar/config/default";
import {TimeoutError} from "@lodestar/utils";
import {Eth1DepositDataTracker} from "../../../src/eth1/eth1DepositDataTracker.js";
Expand All @@ -17,8 +17,8 @@ describe("Eth1DepositDataTracker", function () {
const eth1Provider = new Eth1Provider(config, opts, signal, null);
let db: BeaconDb;
let eth1DepositDataTracker: Eth1DepositDataTracker;
let getBlocksByNumberStub: SpyInstance;
let getDepositEventsStub: SpyInstance;
let getBlocksByNumberStub: MockInstance;
let getDepositEventsStub: MockInstance;

beforeEach(() => {
db = getMockedBeaconDb();
Expand Down
4 changes: 2 additions & 2 deletions packages/beacon-node/test/unit/monitoring/service.test.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import {describe, it, expect, beforeEach, beforeAll, afterAll, vi, afterEach, SpyInstance} from "vitest";
import {describe, it, expect, beforeEach, beforeAll, afterAll, vi, afterEach, MockInstance} from "vitest";
import {ErrorAborted, TimeoutError} from "@lodestar/utils";
import {RegistryMetricCreator} from "../../../src/index.js";
import {HistogramExtra} from "../../../src/metrics/utils/histogram.js";
Expand Down Expand Up @@ -115,7 +115,7 @@ describe("monitoring / service", () => {
});

describe("MonitoringService - close", () => {
let clearTimeout: SpyInstance;
let clearTimeout: MockInstance;

beforeAll(() => {
clearTimeout = vi.spyOn(global, "clearTimeout");
Expand Down
4 changes: 3 additions & 1 deletion packages/cli/test/sim/multi_fork.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@
import path from "node:path";
import {sleep, toHex, toHexString} from "@lodestar/utils";
import {ApiError} from "@lodestar/api";
import {SLOTS_PER_EPOCH} from "@lodestar/params";
import {CLIQUE_SEALING_PERIOD, SIM_TESTS_SECONDS_PER_SLOT} from "../utils/simulation/constants.js";
import {AssertionMatch, BeaconClient, ExecutionClient, ValidatorClient} from "../utils/simulation/interfaces.js";
import {SimulationEnvironment} from "../utils/simulation/SimulationEnvironment.js";
Expand Down Expand Up @@ -213,7 +214,8 @@ const unknownBlockSync = await env.createNodePair({
// unknown block sync can work only if the gap is maximum `slotImportTolerance * 2`
// default value for slotImportTolerance is one epoch, so if gap is more than 2 epoch
// unknown block sync will not work. So why we have to increase it for tests.
"sync.slotImportTolerance": headForUnknownBlockSync.response.data.message.slot / 2 + 2,
// Adding SLOTS_PER_EPOCH will cover the case if the node starts on the last slot of epoch
"sync.slotImportTolerance": headForUnknownBlockSync.response.data.message.slot / 2 + SLOTS_PER_EPOCH,
Copy link
Contributor Author

Choose a reason for hiding this comment

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

Eph 8/6 0.320[unknown-block-sync-node-beacon_lodestar] �[32minfo�[39m: Lodestar network=dev, version=v1.12.0/fc67c5e, commit=fc67c5e7bef36b868d69a0bc55d4c33068106e85
....
....
Eph 8/6 1.720[unknown-block-sync-node-beacon_lodestar/sync] �[36mverbose�[39m: UnknownBlockSync enabled.
Eph 8/6 1.720[unknown-block-sync-node-beacon_lodestar/sync] �[34mdebug�[39m: RangeSync disabled.
....
....
Eph 9/7 0.003[unknown-block-sync-node-beacon_lodestar/sync] �[32minfo�[39m: Initiating epoch check for sync progress
....
....
Eph 10/0 0.006[unknown-block-sync-node-beacon_lodestar/sync] �[36mverbose�[39m: UnknownBlockSync disabled.
....
....

As from the logs its seen that UnknownBlockSync disabled right after the Initiating epoch check for sync progress because it was open epoch over epoch since it was started when we calculated the epoch slotImportTolerance. So had to increase the tolerance level more.

},
},
},
Expand Down
8 changes: 0 additions & 8 deletions packages/prover/.mocharc.yaml

This file was deleted.

3 changes: 0 additions & 3 deletions packages/prover/.nycrc.json

This file was deleted.

9 changes: 0 additions & 9 deletions packages/prover/karma.config.cjs

This file was deleted.

9 changes: 6 additions & 3 deletions packages/prover/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -53,9 +53,12 @@
"lint:fix": "yarn run lint --fix",
"pretest": "yarn run check-types",
"test": "yarn test:unit && yarn test:e2e",
"test:unit": "nyc --cache-dir .nyc_output/.cache -e .ts mocha 'test/unit/**/*.test.ts'",
"test:browsers": "yarn karma start karma.config.cjs",
"test:e2e": "LODESTAR_PRESET=minimal mocha 'test/e2e/**/*.test.ts'",
"test:unit": "vitest --run --dir test/unit/ --coverage",
"test:browsers": "yarn test:browsers:chrome && yarn test:browsers:firefox && yarn test:browsers:electron",
"test:browsers:chrome": "vitest --run --browser chrome --config ./vitest.browser.config.ts --dir test/unit",
"test:browsers:firefox": "vitest --run --browser firefox --config ./vitest.browser.config.ts --dir test/unit",
"test:browsers:electron": "echo 'Electron tests will be introduced back in the future as soon vitest supports electron.'",
Copy link
Contributor Author

Choose a reason for hiding this comment

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

We can bring back electron to our stack, soon when vitest bring it support, else writing a custom BrowserProvider will not be difficult for it.

"test:e2e": "LODESTAR_PRESET=minimal vitest --run --poolOptions.threads.singleThread --dir test/e2e",
"check-readme": "typescript-docs-verifier",
"generate-fixtures": "node --loader ts-node/esm scripts/generate_fixtures.ts"
},
Expand Down
23 changes: 11 additions & 12 deletions packages/prover/test/e2e/cli/cmds/start.test.ts
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
import childProcess from "node:child_process";
import {writeFile, mkdir} from "node:fs/promises";
import path from "node:path";
import {expect} from "chai";
import {describe, it, expect, beforeAll, afterAll} from "vitest";
import Web3 from "web3";
import {runCliCommand, spawnCliCommand, stopChildProcess} from "@lodestar/test-utils";
import {sleep} from "@lodestar/utils";
Expand All @@ -15,11 +15,11 @@ describe("prover/start", () => {
it("should show help", async () => {
const output = await runCliCommand(cli, ["start", "--help"]);

expect(output).contains("Show help");
expect(output).toEqual(expect.stringContaining("Show help"));
});

it("should fail when --executionRpcUrl is missing", async () => {
await expect(runCliCommand(cli, ["start", "--port", "8088"])).eventually.rejectedWith(
await expect(runCliCommand(cli, ["start", "--port", "8088"])).rejects.toThrow(
"Missing required argument: executionRpcUrl"
);
});
Expand All @@ -33,22 +33,21 @@ describe("prover/start", () => {
"--beaconBootnodes",
"http://localhost:0000",
])
).eventually.rejectedWith("Arguments beaconBootnodes and beaconUrls are mutually exclusive");
).rejects.toThrow("Arguments beaconBootnodes and beaconUrls are mutually exclusive");
});

it("should fail when both of --beaconUrls and --beaconBootnodes are not provided", async () => {
await expect(
runCliCommand(cli, ["start", "--port", "8088", "--executionRpcUrl", "http://localhost:3000"])
).eventually.rejectedWith("Either --beaconUrls or --beaconBootnodes must be provided");
).rejects.toThrow("Either --beaconUrls or --beaconBootnodes must be provided");
});

describe("when started", () => {
let proc: childProcess.ChildProcess;
const paramsFilePath = path.join("/tmp", "e2e-test-env", "params.json");
const web3: Web3 = new Web3(proxyUrl);

before(async function () {
this.timeout(50000);
beforeAll(async function () {
await waitForCapellaFork();
await mkdir(path.dirname(paramsFilePath), {recursive: true});
await writeFile(paramsFilePath, JSON.stringify(chainConfigToJson(config as ChainConfig)));
Expand All @@ -72,22 +71,22 @@ describe("prover/start", () => {
);
// Give sometime to the prover to start proxy server
await sleep(3000);
});
}, 50000);

after(async () => {
afterAll(async () => {
await stopChildProcess(proc);
});

it("should respond to verified calls", async () => {
const accounts = await web3.eth.getAccounts();

expect(accounts.length).to.be.gt(0);
await expect(web3.eth.getBalance(accounts[0])).eventually.not.null;
expect(accounts.length).toBeGreaterThan(0);
await expect(web3.eth.getBalance(accounts[0])).resolves.not.toBeNull();
});

it("should respond to unverified calls", async () => {
// Because web3 latest version return numbers as bigint by default
await expect(web3.eth.getChainId()).eventually.eql(BigInt(chainId));
await expect(web3.eth.getChainId()).resolves.toEqual(BigInt(chainId));
});
});
});
18 changes: 8 additions & 10 deletions packages/prover/test/e2e/web3_batch_request.test.ts
Original file line number Diff line number Diff line change
@@ -1,18 +1,16 @@
/* eslint-disable @typescript-eslint/naming-convention */
import {expect} from "chai";
import {describe, it, expect, beforeAll} from "vitest";
import Web3 from "web3";
import {LCTransport} from "../../src/interfaces.js";
import {createVerifiedExecutionProvider} from "../../src/web3_provider.js";
import {rpcUrl, beaconUrl, config} from "../utils/e2e_env.js";
import {getVerificationFailedMessage} from "../../src/utils/json_rpc.js";

/* prettier-ignore */
describe("web3_batch_requests", function () {
// Give some margin to sync light client
this.timeout("10s");

let web3: Web3;

before(() => {
beforeAll(() => {
const {provider} = createVerifiedExecutionProvider(new Web3.providers.HttpProvider(rpcUrl), {
transport: LCTransport.Rest,
urls: [beaconUrl],
Expand Down Expand Up @@ -45,8 +43,8 @@ describe("web3_batch_requests", function () {

await batch.execute();

expect(results.length).to.be.gt(1);
await expect(Promise.all(results)).to.be.fulfilled;
expect(results.length).toBeGreaterThan(1);
await expect(Promise.all(results)).resolves.toBeDefined();
});

it("should be able to process batch request containing error", async () => {
Expand All @@ -66,8 +64,8 @@ describe("web3_batch_requests", function () {

await batch.execute();

await expect(successRequest).to.be.fulfilled;
await expect(errorRequest).to.be.rejectedWith(getVerificationFailedMessage("eth_getBlockByHash"));
await expect(successRequest).resolves.toBeDefined();
await expect(errorRequest).rejects.toThrow(getVerificationFailedMessage("eth_getBlockByHash"));
});
});
});
}, {timeout: 10_000});
17 changes: 8 additions & 9 deletions packages/prover/test/e2e/web3_provider.test.ts
Original file line number Diff line number Diff line change
@@ -1,15 +1,14 @@
/* eslint-disable @typescript-eslint/naming-convention */
import {expect} from "chai";
import {describe, it, expect, beforeAll} from "vitest";
import Web3 from "web3";
import {ethers} from "ethers";
import {LCTransport} from "../../src/interfaces.js";
import {createVerifiedExecutionProvider} from "../../src/web3_provider.js";
import {waitForCapellaFork, testTimeout, rpcUrl, beaconUrl, config} from "../utils/e2e_env.js";

/* prettier-ignore */
describe("web3_provider", function () {
this.timeout(testTimeout);

before("wait for the capella fork", async () => {
beforeAll(async () => {
await waitForCapellaFork();
});

Expand All @@ -26,8 +25,8 @@ describe("web3_provider", function () {
const accounts = await web3.eth.getAccounts();
// `getProof` will always remain the non-verified method
// as we use it to create proof and verify
expect(accounts).not.to.be.empty;
await expect(web3.eth.getProof(accounts[0], [], "latest")).fulfilled;
expect(Object.keys(accounts)).not.toHaveLength(0);
await expect(web3.eth.getProof(accounts[0], [], "latest")).resolves.toBeDefined();
});
});

Expand All @@ -40,9 +39,9 @@ describe("web3_provider", function () {
});
const accounts = await provider.listAccounts();

expect(accounts).not.to.be.empty;
await expect(provider.send("eth_getProof", [accounts[0].address, [], "latest"])).fulfilled;
expect(Object.keys(accounts)).not.toHaveLength(0);
await expect(provider.send("eth_getProof", [accounts[0].address, [], "latest"])).resolves.toBeDefined();
});
});
});
});
}, {timeout: testTimeout});
2 changes: 2 additions & 0 deletions packages/prover/test/globalSetup.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
export async function setup(): Promise<void> {}
export async function teardown(): Promise<void> {}
Loading
Loading