From e4680ec094447521d86d377991cf8ecd844d4541 Mon Sep 17 00:00:00 2001 From: Nazar Hussain Date: Tue, 12 Sep 2023 04:45:53 +0200 Subject: [PATCH 01/28] Enable debug logging for e2e tests --- packages/beacon-node/package.json | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/packages/beacon-node/package.json b/packages/beacon-node/package.json index 44759696641a..9ed5e081e4a1 100644 --- a/packages/beacon-node/package.json +++ b/packages/beacon-node/package.json @@ -80,7 +80,7 @@ "test:unit:minimal": "nyc --cache-dir .nyc_output/.cache -e .ts mocha 'test/unit/**/*.test.ts'", "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": "mocha 'test/e2e/**/*.test.ts'", + "test:e2e": "LOG_LEVEL=debug mocha 'test/e2e/**/*.test.ts'", "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'", From c8d67fe1331b978a01209fdf850360accb6e5fb2 Mon Sep 17 00:00:00 2001 From: Nazar Hussain Date: Mon, 18 Sep 2023 16:02:44 +0200 Subject: [PATCH 02/28] Reduce the duration of lightclient test --- packages/beacon-node/test/e2e/chain/lightclient.test.ts | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/packages/beacon-node/test/e2e/chain/lightclient.test.ts b/packages/beacon-node/test/e2e/chain/lightclient.test.ts index d5b645b39dd0..f83a658b9565 100644 --- a/packages/beacon-node/test/e2e/chain/lightclient.test.ts +++ b/packages/beacon-node/test/e2e/chain/lightclient.test.ts @@ -23,7 +23,8 @@ describe("chain / lightclient", function () { const maxLcHeadTrackingDiffSlots = 4; const validatorCount = 8; const validatorClientCount = 4; - const targetSyncCommittee = 3; + // Reduced from 3 to 1, so test can complete in 10 epoch vs 27 epoch + const targetSyncCommittee = 1; /** N sync committee periods + 1 epoch of margin */ const finalizedEpochToReach = targetSyncCommittee * EPOCHS_PER_SYNC_COMMITTEE_PERIOD + 1; /** Given 100% participation the fastest epoch to reach finalization is +2 epochs. -1 for margin */ From 47a74c7440524435bbba1e92586e16715d9f6b4f Mon Sep 17 00:00:00 2001 From: Nazar Hussain Date: Mon, 18 Sep 2023 16:04:54 +0200 Subject: [PATCH 03/28] Run all e2e tests with minimal preset --- packages/beacon-node/package.json | 2 +- packages/cli/package.json | 2 +- packages/logger/package.json | 2 +- packages/params/package.json | 2 +- packages/validator/package.json | 2 +- 5 files changed, 5 insertions(+), 5 deletions(-) diff --git a/packages/beacon-node/package.json b/packages/beacon-node/package.json index 9ed5e081e4a1..285aa891f237 100644 --- a/packages/beacon-node/package.json +++ b/packages/beacon-node/package.json @@ -80,7 +80,7 @@ "test:unit:minimal": "nyc --cache-dir .nyc_output/.cache -e .ts mocha 'test/unit/**/*.test.ts'", "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": "LOG_LEVEL=debug mocha 'test/e2e/**/*.test.ts'", + "test:e2e": "LOG_LEVEL=debug LODESTAR_PRESET=minimal mocha 'test/e2e/**/*.test.ts'", "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'", diff --git a/packages/cli/package.json b/packages/cli/package.json index a4a387fc670b..fc6ff0201bfc 100644 --- a/packages/cli/package.json +++ b/packages/cli/package.json @@ -32,7 +32,7 @@ "lint:fix": "yarn run lint --fix", "pretest": "yarn run check-types", "test:unit": "nyc --cache-dir .nyc_output/.cache -e .ts mocha 'test/unit/**/*.test.ts'", - "test:e2e": "mocha --timeout 30000 'test/e2e/**/*.test.ts'", + "test:e2e": "LODESTAR_PRESET=minimal mocha --timeout 30000 'test/e2e/**/*.test.ts'", "test:sim:multifork": "LODESTAR_PRESET=minimal node --loader ts-node/esm test/sim/multi_fork.test.ts", "test:sim:mixedclient": "LODESTAR_PRESET=minimal node --loader ts-node/esm test/sim/mixed_client.test.ts", "test:sim:endpoints": "LODESTAR_PRESET=minimal node --loader ts-node/esm test/sim/endpoints.test.ts", diff --git a/packages/logger/package.json b/packages/logger/package.json index 838e3385d4e4..79ac91120f99 100644 --- a/packages/logger/package.json +++ b/packages/logger/package.json @@ -58,7 +58,7 @@ "pretest": "yarn run check-types", "test:unit": "mocha 'test/unit/**/*.test.ts'", "test:browsers": "yarn karma start karma.config.cjs", - "test:e2e": "mocha 'test/e2e/**/*.test.ts'", + "test:e2e": "LODESTAR_PRESET=minimal mocha 'test/e2e/**/*.test.ts'", "check-readme": "typescript-docs-verifier" }, "types": "lib/index.d.ts", diff --git a/packages/params/package.json b/packages/params/package.json index 180b58990ca9..abaa37d87894 100644 --- a/packages/params/package.json +++ b/packages/params/package.json @@ -55,7 +55,7 @@ "test": "yarn run check-types", "test:unit": "mocha 'test/unit/**/*.test.ts'", "test:browsers": "yarn karma start karma.config.cjs", - "test:e2e": "mocha 'test/e2e/**/*.test.ts'", + "test:e2e": "LODESTAR_PRESET=minimal mocha 'test/e2e/**/*.test.ts'", "check-readme": "typescript-docs-verifier" }, "repository": { diff --git a/packages/validator/package.json b/packages/validator/package.json index ed1433cf48c3..862962a6e02a 100644 --- a/packages/validator/package.json +++ b/packages/validator/package.json @@ -32,7 +32,7 @@ "test": "yarn test:unit", "test:e2e:only": "mocha 'test/e2e/**/*.test.ts'", "test:spec": "mocha 'test/spec/**/*.test.ts'", - "test:e2e": "yarn run download-spec-tests && yarn test:spec && yarn test:e2e:only", + "test:e2e": "LODESTAR_PRESET=minimal yarn run download-spec-tests && yarn test:spec && yarn test:e2e:only", "download-spec-tests": "node --loader=ts-node/esm test/spec/downloadTests.ts", "coverage": "codecov -F lodestar-validator", "check-readme": "typescript-docs-verifier" From c72189fc7669399124ae94da46372f020784103c Mon Sep 17 00:00:00 2001 From: Nazar Hussain Date: Mon, 18 Sep 2023 16:22:03 +0200 Subject: [PATCH 04/28] Fix the few e2e tests --- packages/params/test/e2e/overridePreset.test.ts | 3 +++ packages/params/test/e2e/setPreset.test.ts | 3 +++ 2 files changed, 6 insertions(+) diff --git a/packages/params/test/e2e/overridePreset.test.ts b/packages/params/test/e2e/overridePreset.test.ts index e16dd97a08ef..c03e54a480da 100644 --- a/packages/params/test/e2e/overridePreset.test.ts +++ b/packages/params/test/e2e/overridePreset.test.ts @@ -24,6 +24,9 @@ describe("Override preset", function () { this.timeout(30_000); it("Should correctly override preset", async () => { + // These commands can not run with minimal preset + if (process.env.LODESTAR_PRESET === "minimal") delete process.env.LODESTAR_PRESET; + await exec(`node --loader ts-node/esm ${path.join(__dirname, scriptNames.ok)}`); }); diff --git a/packages/params/test/e2e/setPreset.test.ts b/packages/params/test/e2e/setPreset.test.ts index 2b7ff271cd94..38942d2ee514 100644 --- a/packages/params/test/e2e/setPreset.test.ts +++ b/packages/params/test/e2e/setPreset.test.ts @@ -24,6 +24,9 @@ describe("setPreset", function () { this.timeout(30_000); it("Should correctly set preset", async () => { + // These commands can not run with minimal preset + if (process.env.LODESTAR_PRESET === "minimal") delete process.env.LODESTAR_PRESET; + await exec(`node --loader ts-node/esm ${path.join(__dirname, scriptNames.ok)}`); }); From 0d3f1d62578b1ae162a61bb56f57331c38361b27 Mon Sep 17 00:00:00 2001 From: Nazar Hussain Date: Mon, 18 Sep 2023 16:42:29 +0200 Subject: [PATCH 05/28] Fix test job names --- .github/workflows/test-e2e.yml | 4 ++-- .github/workflows/test.yml | 4 ++-- 2 files changed, 4 insertions(+), 4 deletions(-) diff --git a/.github/workflows/test-e2e.yml b/.github/workflows/test-e2e.yml index 25d49c64ad01..2da6d9f8d980 100644 --- a/.github/workflows/test-e2e.yml +++ b/.github/workflows/test-e2e.yml @@ -18,8 +18,8 @@ env: NETHERMIND_DOCKER_IMAGE: nethermind/nethermind:1.18.0 jobs: - tests-main: - name: Tests + e2e-tests: + name: E2E Tests runs-on: buildjet-4vcpu-ubuntu-2204 strategy: fail-fast: false diff --git a/.github/workflows/test.yml b/.github/workflows/test.yml index 22bef8d6c10a..441d6fc022ab 100644 --- a/.github/workflows/test.yml +++ b/.github/workflows/test.yml @@ -13,8 +13,8 @@ on: workflow_dispatch: jobs: - tests-main: - name: Tests + unit-tests: + name: Unit Tests runs-on: buildjet-4vcpu-ubuntu-2204 strategy: fail-fast: false From 781d9aceeb664537b35afc3022a436c6f66e08a1 Mon Sep 17 00:00:00 2001 From: Nazar Hussain Date: Mon, 18 Sep 2023 16:44:18 +0200 Subject: [PATCH 06/28] Fix the task script --- packages/beacon-node/package.json | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/packages/beacon-node/package.json b/packages/beacon-node/package.json index 285aa891f237..35638fa67109 100644 --- a/packages/beacon-node/package.json +++ b/packages/beacon-node/package.json @@ -80,7 +80,7 @@ "test:unit:minimal": "nyc --cache-dir .nyc_output/.cache -e .ts mocha 'test/unit/**/*.test.ts'", "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": "LOG_LEVEL=debug LODESTAR_PRESET=minimal mocha 'test/e2e/**/*.test.ts'", + "test:e2e": "LODESTAR_PRESET=minimal mocha 'test/e2e/**/*.test.ts'", "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'", From 32c63eafe3ac0d2685bc28f694b164e2f32fc21d Mon Sep 17 00:00:00 2001 From: Nazar Hussain Date: Mon, 18 Sep 2023 17:00:25 +0200 Subject: [PATCH 07/28] Add yarn cache to node actions --- .github/workflows/benchmark.yml | 1 + .github/workflows/docs-check.yml | 1 + .github/workflows/docs.yml | 1 + .github/workflows/publish-dev.yml | 1 + .github/workflows/publish-rc.yml | 1 + .github/workflows/publish-stable.yml | 1 + .github/workflows/test-browser.yml | 1 + .github/workflows/test-e2e.yml | 1 + .github/workflows/test-sim-merge.yml | 1 + .github/workflows/test-sim.yml | 1 + .github/workflows/test-spec.yml | 1 + .github/workflows/test.yml | 1 + 12 files changed, 12 insertions(+) diff --git a/.github/workflows/benchmark.yml b/.github/workflows/benchmark.yml index 98842a38b026..bd802e83bc69 100644 --- a/.github/workflows/benchmark.yml +++ b/.github/workflows/benchmark.yml @@ -34,6 +34,7 @@ jobs: with: node-version: 20 check-latest: true + cache: yarn - name: Node.js version id: node run: echo "v8CppApiVersion=$(node --print "process.versions.modules")" >> $GITHUB_OUTPUT diff --git a/.github/workflows/docs-check.yml b/.github/workflows/docs-check.yml index 1556cd191b55..a3c4363920a1 100644 --- a/.github/workflows/docs-check.yml +++ b/.github/workflows/docs-check.yml @@ -16,6 +16,7 @@ jobs: - uses: actions/setup-node@v3 with: node-version: 20 + cache: yarn - name: Node.js version id: node run: echo "v8CppApiVersion=$(node --print "process.versions.modules")" >> $GITHUB_OUTPUT diff --git a/.github/workflows/docs.yml b/.github/workflows/docs.yml index cdceb49d808a..a19def8e72de 100644 --- a/.github/workflows/docs.yml +++ b/.github/workflows/docs.yml @@ -15,6 +15,7 @@ jobs: with: node-version: 20 check-latest: true + cache: yarn - name: Node.js version id: node run: echo "v8CppApiVersion=$(node --print "process.versions.modules")" >> $GITHUB_OUTPUT diff --git a/.github/workflows/publish-dev.yml b/.github/workflows/publish-dev.yml index a656f8562bf3..2e71cc86c33c 100644 --- a/.github/workflows/publish-dev.yml +++ b/.github/workflows/publish-dev.yml @@ -23,6 +23,7 @@ jobs: node-version: 20 registry-url: "https://registry.npmjs.org" check-latest: true + cache: yarn - name: Node.js version id: node run: echo "v8CppApiVersion=$(node --print "process.versions.modules")" >> $GITHUB_OUTPUT diff --git a/.github/workflows/publish-rc.yml b/.github/workflows/publish-rc.yml index 005d2738b1c6..c0dfe3b513dd 100644 --- a/.github/workflows/publish-rc.yml +++ b/.github/workflows/publish-rc.yml @@ -56,6 +56,7 @@ jobs: with: node-version: 20 check-latest: true + cache: yarn - name: Node.js version id: node run: echo "v8CppApiVersion=$(node --print "process.versions.modules")" >> $GITHUB_OUTPUT diff --git a/.github/workflows/publish-stable.yml b/.github/workflows/publish-stable.yml index 01e222d48e72..c0d046891bdf 100644 --- a/.github/workflows/publish-stable.yml +++ b/.github/workflows/publish-stable.yml @@ -62,6 +62,7 @@ jobs: with: node-version: 20 check-latest: true + cache: yarn - name: Node.js version id: node run: echo "v8CppApiVersion=$(node --print "process.versions.modules")" >> $GITHUB_OUTPUT diff --git a/.github/workflows/test-browser.yml b/.github/workflows/test-browser.yml index c4c478b53a07..28b5d65e4684 100644 --- a/.github/workflows/test-browser.yml +++ b/.github/workflows/test-browser.yml @@ -30,6 +30,7 @@ jobs: with: node-version: ${{matrix.node}} check-latest: true + cache: yarn - name: Node.js version id: node run: echo "v8CppApiVersion=$(node --print "process.versions.modules")" >> $GITHUB_OUTPUT diff --git a/.github/workflows/test-e2e.yml b/.github/workflows/test-e2e.yml index 2da6d9f8d980..d8e467e6caf5 100644 --- a/.github/workflows/test-e2e.yml +++ b/.github/workflows/test-e2e.yml @@ -32,6 +32,7 @@ jobs: with: node-version: ${{matrix.node}} check-latest: true + cache: yarn - name: Node.js version id: node run: echo "v8CppApiVersion=$(node --print "process.versions.modules")" >> $GITHUB_OUTPUT diff --git a/.github/workflows/test-sim-merge.yml b/.github/workflows/test-sim-merge.yml index 277a75862079..e9aeb09f4607 100644 --- a/.github/workflows/test-sim-merge.yml +++ b/.github/workflows/test-sim-merge.yml @@ -32,6 +32,7 @@ jobs: with: node-version: 20 check-latest: true + cache: yarn - name: Node.js version id: node run: echo "v8CppApiVersion=$(node --print "process.versions.modules")" >> $GITHUB_OUTPUT diff --git a/.github/workflows/test-sim.yml b/.github/workflows/test-sim.yml index 9fea85cd94af..a6e2581fdee6 100644 --- a/.github/workflows/test-sim.yml +++ b/.github/workflows/test-sim.yml @@ -33,6 +33,7 @@ jobs: with: node-version: 20 check-latest: true + cache: yarn - name: Node.js version id: node run: echo "v8CppApiVersion=$(node --print "process.versions.modules")" >> $GITHUB_OUTPUT diff --git a/.github/workflows/test-spec.yml b/.github/workflows/test-spec.yml index eb17c2e2babf..21063b924092 100644 --- a/.github/workflows/test-spec.yml +++ b/.github/workflows/test-spec.yml @@ -26,6 +26,7 @@ jobs: with: node-version: 20 check-latest: true + cache: yarn - name: Node.js version id: node run: echo "v8CppApiVersion=$(node --print "process.versions.modules")" >> $GITHUB_OUTPUT diff --git a/.github/workflows/test.yml b/.github/workflows/test.yml index 441d6fc022ab..549fc5b72ac1 100644 --- a/.github/workflows/test.yml +++ b/.github/workflows/test.yml @@ -27,6 +27,7 @@ jobs: with: node-version: ${{matrix.node}} check-latest: true + cache: yarn - name: Node.js version id: node run: echo "v8CppApiVersion=$(node --print "process.versions.modules")" >> $GITHUB_OUTPUT From 83e847a85033ca57ade530902144f396d9c01a14 Mon Sep 17 00:00:00 2001 From: Nazar Hussain Date: Mon, 18 Sep 2023 21:38:36 +0200 Subject: [PATCH 08/28] Update few e2e tests after code review --- .../test/e2e/api/impl/config.test.ts | 2 -- .../test/e2e/api/impl/getBlobSidecars.test.ts | 35 ------------------- .../e2e/api/impl/lightclient/endpoint.test.ts | 9 +++-- .../test/e2e/api/lodestar/lodestar.test.ts | 3 +- .../test/e2e/chain/bls/multithread.test.ts | 2 ++ .../e2e/doppelganger/doppelganger.test.ts | 1 + .../e2e/eth1/eth1ForBlockProduction.test.ts | 1 + .../e2e/eth1/eth1MergeBlockTracker.test.ts | 1 + .../test/e2e/eth1/eth1Provider.test.ts | 1 + .../beacon-node/test/e2e/eth1/stream.test.ts | 1 + .../beacon-node/test/e2e/network/mdns.test.ts | 1 + .../test/e2e/network/onWorker/workerEcho.ts | 13 ------- .../e2e/network/onWorker/workerEchoHandler.ts | 35 ------------------- 13 files changed, 13 insertions(+), 92 deletions(-) delete mode 100644 packages/beacon-node/test/e2e/api/impl/getBlobSidecars.test.ts delete mode 100644 packages/beacon-node/test/e2e/network/onWorker/workerEcho.ts delete mode 100644 packages/beacon-node/test/e2e/network/onWorker/workerEchoHandler.ts diff --git a/packages/beacon-node/test/e2e/api/impl/config.test.ts b/packages/beacon-node/test/e2e/api/impl/config.test.ts index e4fa5b29211e..9ba196310e47 100644 --- a/packages/beacon-node/test/e2e/api/impl/config.test.ts +++ b/packages/beacon-node/test/e2e/api/impl/config.test.ts @@ -17,8 +17,6 @@ const CONSTANT_NAMES_SKIP_LIST = new Set([ ]); describe("api / impl / config", function () { - this.timeout(60 * 1000); - it("Ensure all constants are exposed", async () => { const constantNames = await downloadRemoteConstants(ethereumConsensusSpecsTests.specVersion); diff --git a/packages/beacon-node/test/e2e/api/impl/getBlobSidecars.test.ts b/packages/beacon-node/test/e2e/api/impl/getBlobSidecars.test.ts deleted file mode 100644 index 60b960f85acb..000000000000 --- a/packages/beacon-node/test/e2e/api/impl/getBlobSidecars.test.ts +++ /dev/null @@ -1,35 +0,0 @@ -import {expect} from "chai"; -import {config} from "@lodestar/config/default"; -import {ssz} from "@lodestar/types"; -import {GENESIS_SLOT} from "@lodestar/params"; - -import {setupApiImplTestServer, ApiImplTestModules} from "../../../unit/api/impl/index.test.js"; -import {zeroProtoBlock} from "../../../utils/mocks/chain.js"; - -describe("getBlobSideCar", function () { - let server: ApiImplTestModules; - - before(function () { - server = setupApiImplTestServer(); - }); - - // TODO: Write actual tests against the real BeaconChain class, this test is useless - it.skip("getBlobSideCar From BlobSidecars", async () => { - const block = config.getForkTypes(GENESIS_SLOT).SignedBeaconBlock.defaultValue(); - const blobSidecars = ssz.deneb.BlobSidecars.defaultValue(); - const wrappedBlobSidecars = { - blockRoot: ssz.Root.defaultValue(), - slot: block.message.slot, - blobSidecars, - }; - - server.forkChoiceStub.getFinalizedBlock.returns(zeroProtoBlock); - - server.dbStub.blockArchive.get.resolves(block); - server.dbStub.blobSidecars.get.resolves(wrappedBlobSidecars); - - const returnedBlobSideCars = await server.blockApi.getBlobSidecars("genesis"); - - expect(returnedBlobSideCars.data).to.equal(blobSidecars); - }); -}); diff --git a/packages/beacon-node/test/e2e/api/impl/lightclient/endpoint.test.ts b/packages/beacon-node/test/e2e/api/impl/lightclient/endpoint.test.ts index 716c4d196367..c0a91096f25b 100644 --- a/packages/beacon-node/test/e2e/api/impl/lightclient/endpoint.test.ts +++ b/packages/beacon-node/test/e2e/api/impl/lightclient/endpoint.test.ts @@ -31,7 +31,7 @@ describe("lightclient api", function () { let validators: Validator[]; const afterEachCallbacks: (() => Promise | void)[] = []; - this.beforeEach(async () => { + before(async () => { bn = await getDevBeaconNode({ params: chainConfig, options: { @@ -41,7 +41,7 @@ describe("lightclient api", function () { rest: { enabled: true, port: restPort, - api: ["lightclient"], + // api: ["lightclient"], }, }, chain: {blsVerifyAllMainThread: true}, @@ -64,7 +64,7 @@ describe("lightclient api", function () { afterEachCallbacks.push(() => Promise.all(validators.map((validator) => validator.close()))); }); - afterEach(async () => { + after(async () => { while (afterEachCallbacks.length > 0) { const callback = afterEachCallbacks.pop(); if (callback) await callback(); @@ -120,10 +120,9 @@ describe("lightclient api", function () { it("getCommitteeRoot() for the 1st period", async function () { await waitForBestUpdate(); - const lightclient = getClient({baseUrl: `http://127.0.0.1:${restPort}`}, {config}).lightclient; + const {lightclient, beacon: client} = getClient({baseUrl: `http://127.0.0.1:${restPort}`}, {config}); const committeeRes = await lightclient.getCommitteeRoot(0, 1); ApiError.assert(committeeRes); - const client = getClient({baseUrl: `http://127.0.0.1:${restPort}`}, {config}).beacon; const validatorResponse = await client.getStateValidators("head"); ApiError.assert(validatorResponse); const pubkeys = validatorResponse.response.data.map((v) => v.validator.pubkey); diff --git a/packages/beacon-node/test/e2e/api/lodestar/lodestar.test.ts b/packages/beacon-node/test/e2e/api/lodestar/lodestar.test.ts index 2a79daae914c..852413ac4c89 100644 --- a/packages/beacon-node/test/e2e/api/lodestar/lodestar.test.ts +++ b/packages/beacon-node/test/e2e/api/lodestar/lodestar.test.ts @@ -38,8 +38,7 @@ describe("api / impl / validator", function () { const genesisValidatorsRoot = Buffer.alloc(32, 0xaa); const config = createBeaconConfig(chainConfig, genesisValidatorsRoot); - const testLoggerOpts: TestLoggerOpts = {level: LogLevel.info}; - const loggerNodeA = testLogger("Node-A", testLoggerOpts); + const loggerNodeA = testLogger("Node-A"); const bn = await getDevBeaconNode({ params: testParams, diff --git a/packages/beacon-node/test/e2e/chain/bls/multithread.test.ts b/packages/beacon-node/test/e2e/chain/bls/multithread.test.ts index 27ea9e094382..3bf32d05702e 100644 --- a/packages/beacon-node/test/e2e/chain/bls/multithread.test.ts +++ b/packages/beacon-node/test/e2e/chain/bls/multithread.test.ts @@ -78,6 +78,7 @@ describe("chain / bls / multithread queue", function () { expect(isValid).to.deep.equal([true, true, true], `sig set ${i} returned invalid`); } } + await pool.close(); } for (const priority of [true, false]) { @@ -122,6 +123,7 @@ describe("chain / bls / multithread queue", function () { for (const [i, isValid] of isValidArr.entries()) { expect(isValid).to.equal(true, `sig set ${i} returned invalid`); } + await pool.close(); }); } }); diff --git a/packages/beacon-node/test/e2e/doppelganger/doppelganger.test.ts b/packages/beacon-node/test/e2e/doppelganger/doppelganger.test.ts index 610072ebafe3..65c6eb387393 100644 --- a/packages/beacon-node/test/e2e/doppelganger/doppelganger.test.ts +++ b/packages/beacon-node/test/e2e/doppelganger/doppelganger.test.ts @@ -21,6 +21,7 @@ import {BeaconNode} from "../../../src/node/index.js"; // // Attempting to do both 1. and 2. in this e2e test more expensive than necessary. // Unit tests in the validator cover 2., so some test in lodestar package should cover 1. +// https://github.com/ChainSafe/lodestar/issues/5967 describe.skip("doppelganger / doppelganger test", function () { const afterEachCallbacks: (() => Promise | void)[] = []; afterEach(async () => { diff --git a/packages/beacon-node/test/e2e/eth1/eth1ForBlockProduction.test.ts b/packages/beacon-node/test/e2e/eth1/eth1ForBlockProduction.test.ts index cb537b14563f..1c67788e3fb6 100644 --- a/packages/beacon-node/test/e2e/eth1/eth1ForBlockProduction.test.ts +++ b/packages/beacon-node/test/e2e/eth1/eth1ForBlockProduction.test.ts @@ -27,6 +27,7 @@ const pyrmontDepositsDataRoot = [ "0x61cef7d8a3f7c590a2dc066ae1c95def5ce769b3e9471fdb34f36f7a7246965e", ]; +// https://github.com/ChainSafe/lodestar/issues/5967 describe.skip("eth1 / Eth1Provider", function () { this.timeout("2 min"); diff --git a/packages/beacon-node/test/e2e/eth1/eth1MergeBlockTracker.test.ts b/packages/beacon-node/test/e2e/eth1/eth1MergeBlockTracker.test.ts index 67d392500cd5..868a06724894 100644 --- a/packages/beacon-node/test/e2e/eth1/eth1MergeBlockTracker.test.ts +++ b/packages/beacon-node/test/e2e/eth1/eth1MergeBlockTracker.test.ts @@ -15,6 +15,7 @@ import {getGoerliRpcUrl} from "../../testParams.js"; // This test is constantly failing. We must unblock PR so this issue is a TODO to debug it and re-enable latter. // It's OKAY to disable temporarily since this functionality is tested indirectly by the sim merge tests. // See https://github.com/ChainSafe/lodestar/issues/4197 +// https://github.com/ChainSafe/lodestar/issues/5967 describe.skip("eth1 / Eth1MergeBlockTracker", function () { this.timeout("2 min"); diff --git a/packages/beacon-node/test/e2e/eth1/eth1Provider.test.ts b/packages/beacon-node/test/e2e/eth1/eth1Provider.test.ts index c5c94f49712c..52f9dd4f264d 100644 --- a/packages/beacon-node/test/e2e/eth1/eth1Provider.test.ts +++ b/packages/beacon-node/test/e2e/eth1/eth1Provider.test.ts @@ -8,6 +8,7 @@ import {Eth1Provider, parseEth1Block} from "../../../src/eth1/provider/eth1Provi import {Eth1Block} from "../../../src/eth1/interface.js"; import {getGoerliRpcUrl} from "../../testParams.js"; +// https://github.com/ChainSafe/lodestar/issues/5967 describe.skip("eth1 / Eth1Provider", function () { this.timeout("2 min"); diff --git a/packages/beacon-node/test/e2e/eth1/stream.test.ts b/packages/beacon-node/test/e2e/eth1/stream.test.ts index ca4d48a302cc..372f9abdb935 100644 --- a/packages/beacon-node/test/e2e/eth1/stream.test.ts +++ b/packages/beacon-node/test/e2e/eth1/stream.test.ts @@ -6,6 +6,7 @@ import {Eth1Provider} from "../../../src/eth1/provider/eth1Provider.js"; import {getGoerliRpcUrl} from "../../testParams.js"; import {Eth1Options} from "../../../src/eth1/options.js"; +// https://github.com/ChainSafe/lodestar/issues/5967 describe.skip("Eth1 streams", function () { this.timeout("2 min"); diff --git a/packages/beacon-node/test/e2e/network/mdns.test.ts b/packages/beacon-node/test/e2e/network/mdns.test.ts index f08e57a25045..a18e939cfda5 100644 --- a/packages/beacon-node/test/e2e/network/mdns.test.ts +++ b/packages/beacon-node/test/e2e/network/mdns.test.ts @@ -24,6 +24,7 @@ import {memoOnce} from "../../utils/cache.js"; let port = 9000; const mu = "/ip4/127.0.0.1/tcp/0"; +// https://github.com/ChainSafe/lodestar/issues/5967 // eslint-disable-next-line mocha/no-skipped-tests describe.skip("mdns", function () { this.timeout(50000); diff --git a/packages/beacon-node/test/e2e/network/onWorker/workerEcho.ts b/packages/beacon-node/test/e2e/network/onWorker/workerEcho.ts deleted file mode 100644 index a448a8821792..000000000000 --- a/packages/beacon-node/test/e2e/network/onWorker/workerEcho.ts +++ /dev/null @@ -1,13 +0,0 @@ -import worker from "node:worker_threads"; -import {expose} from "@chainsafe/threads/worker"; - -const parentPort = worker.parentPort; -if (!parentPort) throw Error("parentPort must be defined"); - -parentPort.on("message", (data) => { - parentPort.postMessage(data); -}); - -expose(() => { - // -}); diff --git a/packages/beacon-node/test/e2e/network/onWorker/workerEchoHandler.ts b/packages/beacon-node/test/e2e/network/onWorker/workerEchoHandler.ts deleted file mode 100644 index 0b84ace618f1..000000000000 --- a/packages/beacon-node/test/e2e/network/onWorker/workerEchoHandler.ts +++ /dev/null @@ -1,35 +0,0 @@ -import worker_threads from "node:worker_threads"; -import {spawn, Worker} from "@chainsafe/threads"; - -export type EchoWorker = { - send(data: T): Promise; - close(): Promise; -}; - -export async function getEchoWorker(): Promise { - const workerThreadjs = new Worker("./workerEcho.js"); - const worker = workerThreadjs as unknown as worker_threads.Worker; - - // eslint-disable-next-line @typescript-eslint/no-explicit-any - await spawn(workerThreadjs, { - // A Lodestar Node may do very expensive task at start blocking the event loop and causing - // the initialization to timeout. The number below is big enough to almost disable the timeout - timeout: 5 * 60 * 1000, - // TODO: types are broken on spawn, which claims that `NetworkWorkerApi` does not satifies its contrains - }); - - return { - send(data: T): Promise { - return new Promise((resolve, reject) => { - worker.once("message", (data) => resolve(data)); - worker.once("messageerror", reject); - worker.once("error", reject); - worker.postMessage(data); - }); - }, - - async close() { - await workerThreadjs.terminate(); - }, - }; -} From 5a040a9ca54f14b1002186320e7a222adf5acb87 Mon Sep 17 00:00:00 2001 From: Nazar Hussain Date: Tue, 19 Sep 2023 09:59:47 +0200 Subject: [PATCH 09/28] Fix the type export to use with transpilation --- packages/api/package.json | 2 +- packages/api/src/beacon/index.ts | 2 +- .../api/src/beacon/routes/beacon/index.ts | 7 +- packages/api/src/builder/server/index.ts | 2 +- packages/api/src/index.ts | 17 +--- packages/api/src/keymanager/server/index.ts | 2 +- packages/api/src/utils/client/httpClient.ts | 2 +- packages/beacon-node/package.json | 4 +- .../beacon-node/src/chain/blocks/index.ts | 2 +- packages/beacon-node/src/chain/bls/index.ts | 5 +- .../beacon-node/src/chain/forkChoice/index.ts | 2 +- packages/beacon-node/src/chain/interface.ts | 4 +- packages/beacon-node/src/db/index.ts | 2 +- .../beacon-node/src/db/repositories/index.ts | 3 +- packages/beacon-node/src/eth1/index.ts | 3 +- .../src/execution/engine/interface.ts | 2 +- packages/beacon-node/src/index.ts | 16 ++-- .../src/network/reqresp/ReqRespBeaconNode.ts | 2 +- packages/beacon-node/src/sync/interface.ts | 2 +- .../e2e/network/gossipsub-without-mocha.ts | 90 +++++++++++++++++++ .../test/e2e/network/onWorker/workerEcho.ts | 13 +++ .../e2e/network/onWorker/workerEchoHandler.ts | 35 ++++++++ packages/cli/package.json | 4 +- packages/cli/test/tsconfig.json | 6 ++ packages/config/package.json | 2 +- packages/config/src/genesisConfig/index.ts | 2 +- packages/db/package.json | 2 +- packages/db/src/controller/index.ts | 4 +- packages/flare/package.json | 2 +- packages/fork-choice/package.json | 2 +- packages/fork-choice/src/index.ts | 25 +++--- packages/light-client/package.json | 2 +- packages/light-client/src/index.ts | 2 +- packages/light-client/src/spec/index.ts | 3 +- packages/logger/package.json | 4 +- packages/logger/src/interface.ts | 3 +- packages/params/package.json | 4 +- packages/params/src/index.ts | 15 +--- packages/prover/package.json | 4 +- packages/prover/src/interfaces.ts | 2 +- packages/reqresp/package.json | 4 +- packages/reqresp/src/index.ts | 6 +- packages/state-transition/package.json | 2 +- packages/state-transition/src/index.ts | 16 ++-- packages/state-transition/src/types.ts | 6 +- packages/types/package.json | 2 +- packages/utils/package.json | 2 +- packages/utils/src/index.ts | 4 +- packages/validator/package.json | 4 +- packages/validator/src/index.ts | 13 ++- .../validator/src/slashingProtection/index.ts | 5 +- 51 files changed, 257 insertions(+), 114 deletions(-) create mode 100644 packages/beacon-node/test/e2e/network/gossipsub-without-mocha.ts create mode 100644 packages/beacon-node/test/e2e/network/onWorker/workerEcho.ts create mode 100644 packages/beacon-node/test/e2e/network/onWorker/workerEchoHandler.ts create mode 100644 packages/cli/test/tsconfig.json diff --git a/packages/api/package.json b/packages/api/package.json index f87de28f0882..2f93b00646c4 100644 --- a/packages/api/package.json +++ b/packages/api/package.json @@ -65,7 +65,7 @@ "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:unit": "TS_NODE_TRANSPILE_ONLY=true nyc --cache-dir .nyc_output/.cache -e .ts mocha 'test/unit/**/*.test.ts'", "check-readme": "typescript-docs-verifier" }, "dependencies": { diff --git a/packages/api/src/beacon/index.ts b/packages/api/src/beacon/index.ts index e86895e3beae..7cbd86252471 100644 --- a/packages/api/src/beacon/index.ts +++ b/packages/api/src/beacon/index.ts @@ -1,4 +1,4 @@ -import {Api} from "./routes/index.js"; +import type {Api} from "./routes/index.js"; // NOTE: Don't export server here so it's not bundled to all consumers diff --git a/packages/api/src/beacon/routes/beacon/index.ts b/packages/api/src/beacon/routes/beacon/index.ts index d8879ca2d695..4d0c8186fd22 100644 --- a/packages/api/src/beacon/routes/beacon/index.ts +++ b/packages/api/src/beacon/routes/beacon/index.ts @@ -15,10 +15,11 @@ import * as state from "./state.js"; export * as block from "./block.js"; export * as pool from "./pool.js"; export * as state from "./state.js"; -export {BlockId, BlockHeaderResponse, BroadcastValidation} from "./block.js"; -export {AttestationFilters} from "./pool.js"; +export {BroadcastValidation} from "./block.js"; +export type {BlockId, BlockHeaderResponse} from "./block.js"; +export type {AttestationFilters} from "./pool.js"; // TODO: Review if re-exporting all these types is necessary -export { +export type { StateId, ValidatorId, ValidatorStatus, diff --git a/packages/api/src/builder/server/index.ts b/packages/api/src/builder/server/index.ts index 2421abbc0dcc..3f979af4094a 100644 --- a/packages/api/src/builder/server/index.ts +++ b/packages/api/src/builder/server/index.ts @@ -5,7 +5,7 @@ import { ServerRoutes, getGenericJsonServer, registerRoute, - RouteConfig, + type RouteConfig, } from "../../utils/server/index.js"; import {Api, ReqTypes, routesData, getReturnTypes, getReqSerializers} from "../routes.js"; diff --git a/packages/api/src/index.ts b/packages/api/src/index.ts index a0436611798e..27ef2ada69d3 100644 --- a/packages/api/src/index.ts +++ b/packages/api/src/index.ts @@ -1,19 +1,10 @@ // Re-exporting beacon only for backwards compatibility export * from "./beacon/index.js"; export * from "./interfaces.js"; -export {HttpStatusCode, HttpErrorCodes, HttpSuccessCodes} from "./utils/client/httpStatusCode.js"; -export { - HttpClient, - IHttpClient, - HttpClientOptions, - HttpClientModules, - HttpError, - ApiError, - Metrics, - FetchError, - isFetchError, - fetch, -} from "./utils/client/index.js"; +export {HttpStatusCode} from "./utils/client/httpStatusCode.js"; +export type {HttpErrorCodes, HttpSuccessCodes} from "./utils/client/httpStatusCode.js"; +export {HttpClient, HttpError, ApiError, FetchError, isFetchError, fetch} from "./utils/client/index.js"; +export type {IHttpClient, HttpClientOptions, HttpClientModules, Metrics} from "./utils/client/index.js"; export * from "./utils/routes.js"; // NOTE: Don't export server here so it's not bundled to all consumers diff --git a/packages/api/src/keymanager/server/index.ts b/packages/api/src/keymanager/server/index.ts index 2421abbc0dcc..3f979af4094a 100644 --- a/packages/api/src/keymanager/server/index.ts +++ b/packages/api/src/keymanager/server/index.ts @@ -5,7 +5,7 @@ import { ServerRoutes, getGenericJsonServer, registerRoute, - RouteConfig, + type RouteConfig, } from "../../utils/server/index.js"; import {Api, ReqTypes, routesData, getReturnTypes, getReqSerializers} from "../routes.js"; diff --git a/packages/api/src/utils/client/httpClient.ts b/packages/api/src/utils/client/httpClient.ts index 54a7ca8d4e42..2c0d682019c5 100644 --- a/packages/api/src/utils/client/httpClient.ts +++ b/packages/api/src/utils/client/httpClient.ts @@ -3,7 +3,7 @@ import {ReqGeneric, RouteDef} from "../index.js"; import {ApiClientResponse, ApiClientSuccessResponse} from "../../interfaces.js"; import {fetch, isFetchError} from "./fetch.js"; import {stringifyQuery, urlJoin} from "./format.js"; -import {Metrics} from "./metrics.js"; +import type {Metrics} from "./metrics.js"; import {HttpStatusCode} from "./httpStatusCode.js"; /** A higher default timeout, validator will sets its own shorter timeoutMs */ diff --git a/packages/beacon-node/package.json b/packages/beacon-node/package.json index 35638fa67109..d0728418c1d8 100644 --- a/packages/beacon-node/package.json +++ b/packages/beacon-node/package.json @@ -79,8 +79,8 @@ "test": "yarn test:unit && yarn test:e2e", "test:unit:minimal": "nyc --cache-dir .nyc_output/.cache -e .ts mocha 'test/unit/**/*.test.ts'", "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 mocha 'test/e2e/**/*.test.ts'", + "test:unit": "TS_NODE_TRANSPILE_ONLY=true yarn test:unit:minimal && yarn test:unit:mainnet", + "test:e2e": "TS_NODE_TRANSPILE_ONLY=true LODESTAR_PRESET=minimal mocha 'test/e2e/**/*.test.ts'", "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'", diff --git a/packages/beacon-node/src/chain/blocks/index.ts b/packages/beacon-node/src/chain/blocks/index.ts index 46369a64d586..569fd0771022 100644 --- a/packages/beacon-node/src/chain/blocks/index.ts +++ b/packages/beacon-node/src/chain/blocks/index.ts @@ -11,7 +11,7 @@ import {assertLinearChainSegment} from "./utils/chainSegment.js"; import {BlockInput, FullyVerifiedBlock, ImportBlockOpts} from "./types.js"; import {verifyBlocksSanityChecks} from "./verifyBlocksSanityChecks.js"; import {removeEagerlyPersistedBlockInputs} from "./writeBlockInputToDb.js"; -export {ImportBlockOpts, AttestationImportOpt} from "./types.js"; +export {type ImportBlockOpts, AttestationImportOpt} from "./types.js"; const QUEUE_MAX_LENGTH = 256; diff --git a/packages/beacon-node/src/chain/bls/index.ts b/packages/beacon-node/src/chain/bls/index.ts index d13d367c153b..3ee72ac66cbd 100644 --- a/packages/beacon-node/src/chain/bls/index.ts +++ b/packages/beacon-node/src/chain/bls/index.ts @@ -1,3 +1,4 @@ -export {IBlsVerifier} from "./interface.js"; -export {BlsMultiThreadWorkerPool, BlsMultiThreadWorkerPoolModules} from "./multithread/index.js"; +export type {IBlsVerifier} from "./interface.js"; +export type {BlsMultiThreadWorkerPoolModules} from "./multithread/index.js"; +export {BlsMultiThreadWorkerPool} from "./multithread/index.js"; export {BlsSingleThreadVerifier} from "./singleThread.js"; diff --git a/packages/beacon-node/src/chain/forkChoice/index.ts b/packages/beacon-node/src/chain/forkChoice/index.ts index 4de9d3e6ca23..7e195a84922d 100644 --- a/packages/beacon-node/src/chain/forkChoice/index.ts +++ b/packages/beacon-node/src/chain/forkChoice/index.ts @@ -21,7 +21,7 @@ import {ChainEventEmitter} from "../emitter.js"; import {ChainEvent} from "../emitter.js"; import {GENESIS_SLOT} from "../../constants/index.js"; -export {ForkChoiceOpts}; +export type {ForkChoiceOpts}; /** * Fork Choice extended with a ChainEventEmitter diff --git a/packages/beacon-node/src/chain/interface.ts b/packages/beacon-node/src/chain/interface.ts index 78fbf2c5a3fe..211ac7e3777a 100644 --- a/packages/beacon-node/src/chain/interface.ts +++ b/packages/beacon-node/src/chain/interface.ts @@ -37,8 +37,8 @@ import {IChainOptions} from "./options.js"; import {AssembledBlockType, BlockAttributes, BlockType} from "./produceBlock/produceBlockBody.js"; import {SeenAttestationDatas} from "./seenCache/seenAttestationData.js"; -export {BlockType, AssembledBlockType}; -export {ProposerPreparationData}; +export {BlockType, type AssembledBlockType}; +export {type ProposerPreparationData}; export type BlockHash = RootHex; export type StateGetOpts = { diff --git a/packages/beacon-node/src/db/index.ts b/packages/beacon-node/src/db/index.ts index 217764734af0..ed48845b6b97 100644 --- a/packages/beacon-node/src/db/index.ts +++ b/packages/beacon-node/src/db/index.ts @@ -1,2 +1,2 @@ -export {IBeaconDb} from "./interface.js"; +export type {IBeaconDb} from "./interface.js"; export {BeaconDb} from "./beacon.js"; diff --git a/packages/beacon-node/src/db/repositories/index.ts b/packages/beacon-node/src/db/repositories/index.ts index 774f58b81535..4a66a0ba9876 100644 --- a/packages/beacon-node/src/db/repositories/index.ts +++ b/packages/beacon-node/src/db/repositories/index.ts @@ -2,7 +2,8 @@ export {BlobSidecarsRepository} from "./blobSidecars.js"; export {BlobSidecarsArchiveRepository} from "./blobSidecarsArchive.js"; export {BlockRepository} from "./block.js"; -export {BlockArchiveBatchPutBinaryItem, BlockArchiveRepository, BlockFilterOptions} from "./blockArchive.js"; +export {BlockArchiveRepository} from "./blockArchive.js"; +export type {BlockArchiveBatchPutBinaryItem, BlockFilterOptions} from "./blockArchive.js"; export {StateArchiveRepository} from "./stateArchive.js"; export {AttesterSlashingRepository} from "./attesterSlashing.js"; diff --git a/packages/beacon-node/src/eth1/index.ts b/packages/beacon-node/src/eth1/index.ts index 3e44a0a6620d..f53af42ff6a3 100644 --- a/packages/beacon-node/src/eth1/index.ts +++ b/packages/beacon-node/src/eth1/index.ts @@ -6,7 +6,8 @@ import {Eth1DepositDataTracker, Eth1DepositDataTrackerModules} from "./eth1Depos import {Eth1MergeBlockTracker, Eth1MergeBlockTrackerModules} from "./eth1MergeBlockTracker.js"; import {Eth1Options} from "./options.js"; import {Eth1Provider} from "./provider/eth1Provider.js"; -export {IEth1ForBlockProduction, IEth1Provider, Eth1Provider}; +export {Eth1Provider}; +export type {IEth1ForBlockProduction, IEth1Provider}; // This module encapsulates all consumer functionality to the execution node (formerly eth1). The execution client // has to: diff --git a/packages/beacon-node/src/execution/engine/interface.ts b/packages/beacon-node/src/execution/engine/interface.ts index f2ce00e43a45..c4543c45a3e2 100644 --- a/packages/beacon-node/src/execution/engine/interface.ts +++ b/packages/beacon-node/src/execution/engine/interface.ts @@ -6,7 +6,7 @@ import {DATA, QUANTITY} from "../../eth1/provider/utils.js"; import {PayloadIdCache, PayloadId, WithdrawalV1} from "./payloadIdCache.js"; import {ExecutionPayloadBody} from "./types.js"; -export {PayloadIdCache, PayloadId, WithdrawalV1}; +export {PayloadIdCache, type PayloadId, type WithdrawalV1}; export enum ExecutionPayloadStatus { /** given payload is valid */ diff --git a/packages/beacon-node/src/index.ts b/packages/beacon-node/src/index.ts index 69adb74d5471..aa555a1ab0ca 100644 --- a/packages/beacon-node/src/index.ts +++ b/packages/beacon-node/src/index.ts @@ -1,17 +1,23 @@ export {initStateFromAnchorState, initStateFromDb, initStateFromEth1} from "./chain/index.js"; -export {BeaconDb, IBeaconDb} from "./db/index.js"; -export {Eth1Provider, IEth1Provider} from "./eth1/index.js"; -export {createNodeJsLibp2p, NodeJsLibp2pOpts} from "./network/index.js"; +export {BeaconDb, type IBeaconDb} from "./db/index.js"; +export {Eth1Provider, type IEth1Provider} from "./eth1/index.js"; +export {createNodeJsLibp2p, type NodeJsLibp2pOpts} from "./network/index.js"; export * from "./node/index.js"; // Export metrics utilities to de-duplicate validator metrics -export {RegistryMetricCreator, collectNodeJSMetrics, HttpMetricsServer, getHttpMetricsServer} from "./metrics/index.js"; +export { + RegistryMetricCreator, + collectNodeJSMetrics, + type HttpMetricsServer, + getHttpMetricsServer, +} from "./metrics/index.js"; // Export monitoring service to make it usable by validator export {MonitoringService} from "./monitoring/index.js"; // Export generic RestApi server for CLI -export {RestApiServer, RestApiServerOpts, RestApiServerModules, RestApiServerMetrics} from "./api/rest/base.js"; +export {RestApiServer} from "./api/rest/base.js"; +export type {RestApiServerOpts, RestApiServerModules, RestApiServerMetrics} from "./api/rest/base.js"; // Export type util for CLI - TEMP move to lodestar-types eventually export {getStateTypeFromBytes} from "./util/multifork.js"; diff --git a/packages/beacon-node/src/network/reqresp/ReqRespBeaconNode.ts b/packages/beacon-node/src/network/reqresp/ReqRespBeaconNode.ts index 994be87833d6..69b83ee327c6 100644 --- a/packages/beacon-node/src/network/reqresp/ReqRespBeaconNode.ts +++ b/packages/beacon-node/src/network/reqresp/ReqRespBeaconNode.ts @@ -35,7 +35,7 @@ import * as protocols from "./protocols.js"; import {collectExactOneTyped} from "./utils/collect.js"; export {getReqRespHandlers} from "./handlers/index.js"; -export {ReqRespMethod, RequestTypedContainer} from "./types.js"; +export {ReqRespMethod, type RequestTypedContainer} from "./types.js"; export interface ReqRespBeaconNodeModules { libp2p: Libp2p; diff --git a/packages/beacon-node/src/sync/interface.ts b/packages/beacon-node/src/sync/interface.ts index a9092e6503ab..4dd2fd96e21a 100644 --- a/packages/beacon-node/src/sync/interface.ts +++ b/packages/beacon-node/src/sync/interface.ts @@ -8,7 +8,7 @@ import {IBeaconChain} from "../chain/index.js"; import {Metrics} from "../metrics/index.js"; import {IBeaconDb} from "../db/index.js"; import {SyncChainDebugState} from "./range/chain.js"; -export {SyncChainDebugState}; +export type {SyncChainDebugState}; export type SyncingStatus = routes.node.SyncingStatus; diff --git a/packages/beacon-node/test/e2e/network/gossipsub-without-mocha.ts b/packages/beacon-node/test/e2e/network/gossipsub-without-mocha.ts new file mode 100644 index 000000000000..fa14fa13c4f6 --- /dev/null +++ b/packages/beacon-node/test/e2e/network/gossipsub-without-mocha.ts @@ -0,0 +1,90 @@ +import wtf from "wtfnode"; +import {createChainForkConfig, defaultChainConfig} from "@lodestar/config"; +import {sleep} from "@lodestar/utils"; +import {computeStartSlotAtEpoch} from "@lodestar/state-transition"; +import {ssz} from "@lodestar/types"; +import {Network} from "../../../src/network/index.js"; +import {GossipType, GossipHandlers, GossipHandlerParamGeneric} from "../../../src/network/gossip/index.js"; +import {connect, onPeerConnect, getNetworkForTest} from "../../utils/network.js"; + +await runTests({useWorker: false}); +console.log("\n\n%%%%%%%%%%%% finished non worker tests"); +wtf.dump(); +await sleep(2000); +console.log("\n\n\n"); +wtf.dump(); + +await runTests({useWorker: true}); +console.log("\n\n%%%%%%%%%%%% finished worker tests"); +wtf.dump(); +await sleep(1000); +console.log("\n\n\n"); +wtf.dump(); + +async function runTests({useWorker}: {useWorker: boolean}): Promise { + console.log("\n\n%%%%%%%%%%%% starting tests with useWorker", useWorker); + console.log("%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%"); + const afterEachCallbacks: (() => Promise | void)[] = []; + + // Schedule all forks at ALTAIR_FORK_EPOCH to avoid generating the pubkeys cache + /* eslint-disable @typescript-eslint/naming-convention */ + const config = createChainForkConfig({ + ...defaultChainConfig, + ALTAIR_FORK_EPOCH: 1, + BELLATRIX_FORK_EPOCH: 1, + CAPELLA_FORK_EPOCH: 1, + }); + computeStartSlotAtEpoch(config.ALTAIR_FORK_EPOCH); + + // eslint-disable-next-line @typescript-eslint/explicit-function-return-type + async function mockModules(gossipHandlersPartial?: Partial) { + const [netA, closeA] = await getNetworkForTest("A", config, {opts: {useWorker}, gossipHandlersPartial}); + const [netB, closeB] = await getNetworkForTest("B", config, {opts: {useWorker}, gossipHandlersPartial}); + + afterEachCallbacks.push(async () => { + await closeA(); + await closeB(); + }); + + return {netA, netB}; + } + + let onVoluntaryExit: (ve: Uint8Array) => void; + const onVoluntaryExitPromise = new Promise((resolve) => (onVoluntaryExit = resolve)); + + const {netA, netB} = await mockModules({ + [GossipType.voluntary_exit]: async ({gossipData}: GossipHandlerParamGeneric) => { + onVoluntaryExit(gossipData.serializedData); + }, + }); + + await Promise.all([onPeerConnect(netA), onPeerConnect(netB), connect(netA, netB)]); + console.log("%%%%%", netA.getConnectedPeerCount()); + console.log("%%%%%", netB.getConnectedPeerCount()); + + await netA.subscribeGossipCoreTopics(); + await netB.subscribeGossipCoreTopics(); + + // Wait to have a peer connected to a topic + while (!netA.closed) { + await sleep(500); + if (await hasSomeMeshPeer(netA)) { + break; + } + } + + const voluntaryExit = ssz.phase0.SignedVoluntaryExit.defaultValue(); + voluntaryExit.message.epoch = config.ALTAIR_FORK_EPOCH; + await netA.publishVoluntaryExit(voluntaryExit); + + await onVoluntaryExitPromise; + + while (afterEachCallbacks.length > 0) { + const callback = afterEachCallbacks.pop(); + if (callback) await callback(); + } +} + +async function hasSomeMeshPeer(net: Network): Promise { + return Object.values(await net.dumpMeshPeers()).some((peers) => peers.length > 0); +} diff --git a/packages/beacon-node/test/e2e/network/onWorker/workerEcho.ts b/packages/beacon-node/test/e2e/network/onWorker/workerEcho.ts new file mode 100644 index 000000000000..a448a8821792 --- /dev/null +++ b/packages/beacon-node/test/e2e/network/onWorker/workerEcho.ts @@ -0,0 +1,13 @@ +import worker from "node:worker_threads"; +import {expose} from "@chainsafe/threads/worker"; + +const parentPort = worker.parentPort; +if (!parentPort) throw Error("parentPort must be defined"); + +parentPort.on("message", (data) => { + parentPort.postMessage(data); +}); + +expose(() => { + // +}); diff --git a/packages/beacon-node/test/e2e/network/onWorker/workerEchoHandler.ts b/packages/beacon-node/test/e2e/network/onWorker/workerEchoHandler.ts new file mode 100644 index 000000000000..0b84ace618f1 --- /dev/null +++ b/packages/beacon-node/test/e2e/network/onWorker/workerEchoHandler.ts @@ -0,0 +1,35 @@ +import worker_threads from "node:worker_threads"; +import {spawn, Worker} from "@chainsafe/threads"; + +export type EchoWorker = { + send(data: T): Promise; + close(): Promise; +}; + +export async function getEchoWorker(): Promise { + const workerThreadjs = new Worker("./workerEcho.js"); + const worker = workerThreadjs as unknown as worker_threads.Worker; + + // eslint-disable-next-line @typescript-eslint/no-explicit-any + await spawn(workerThreadjs, { + // A Lodestar Node may do very expensive task at start blocking the event loop and causing + // the initialization to timeout. The number below is big enough to almost disable the timeout + timeout: 5 * 60 * 1000, + // TODO: types are broken on spawn, which claims that `NetworkWorkerApi` does not satifies its contrains + }); + + return { + send(data: T): Promise { + return new Promise((resolve, reject) => { + worker.once("message", (data) => resolve(data)); + worker.once("messageerror", reject); + worker.once("error", reject); + worker.postMessage(data); + }); + }, + + async close() { + await workerThreadjs.terminate(); + }, + }; +} diff --git a/packages/cli/package.json b/packages/cli/package.json index fc6ff0201bfc..b0e7320359cb 100644 --- a/packages/cli/package.json +++ b/packages/cli/package.json @@ -31,8 +31,8 @@ "lint": "eslint --color --ext .ts src/ test/", "lint:fix": "yarn run lint --fix", "pretest": "yarn run check-types", - "test:unit": "nyc --cache-dir .nyc_output/.cache -e .ts mocha 'test/unit/**/*.test.ts'", - "test:e2e": "LODESTAR_PRESET=minimal mocha --timeout 30000 'test/e2e/**/*.test.ts'", + "test:unit": "TS_NODE_TRANSPILE_ONLY=true nyc --cache-dir .nyc_output/.cache -e .ts mocha 'test/unit/**/*.test.ts'", + "test:e2e": "TS_NODE_TRANSPILE_ONLY=true LODESTAR_PRESET=minimal mocha --timeout 30000 'test/e2e/**/*.test.ts'", "test:sim:multifork": "LODESTAR_PRESET=minimal node --loader ts-node/esm test/sim/multi_fork.test.ts", "test:sim:mixedclient": "LODESTAR_PRESET=minimal node --loader ts-node/esm test/sim/mixed_client.test.ts", "test:sim:endpoints": "LODESTAR_PRESET=minimal node --loader ts-node/esm test/sim/endpoints.test.ts", diff --git a/packages/cli/test/tsconfig.json b/packages/cli/test/tsconfig.json new file mode 100644 index 000000000000..484405d0e8b8 --- /dev/null +++ b/packages/cli/test/tsconfig.json @@ -0,0 +1,6 @@ +{ + "extends": "../tsconfig.json", + "ts-node": { + "transpileOnly": true + } +} diff --git a/packages/config/package.json b/packages/config/package.json index 8fd9bd835b5c..0047ae507e85 100644 --- a/packages/config/package.json +++ b/packages/config/package.json @@ -50,7 +50,7 @@ "lint": "eslint --color --ext .ts src/", "lint:fix": "yarn run lint --fix", "pretest": "yarn run check-types", - "test:unit": "nyc --cache-dir .nyc_output/.cache -e .ts mocha 'test/unit/**/*.test.ts'", + "test:unit": "TS_NODE_TRANSPILE_ONLY=true nyc --cache-dir .nyc_output/.cache -e .ts mocha 'test/unit/**/*.test.ts'", "check-readme": "typescript-docs-verifier" }, "repository": { diff --git a/packages/config/src/genesisConfig/index.ts b/packages/config/src/genesisConfig/index.ts index 23c9e08d1e8e..52fdd03880a6 100644 --- a/packages/config/src/genesisConfig/index.ts +++ b/packages/config/src/genesisConfig/index.ts @@ -3,7 +3,7 @@ import {ForkName, SLOTS_PER_EPOCH, DOMAIN_VOLUNTARY_EXIT} from "@lodestar/params import {DomainType, ForkDigest, phase0, Root, Slot, ssz, Version} from "@lodestar/types"; import {ChainForkConfig} from "../beaconConfig.js"; import {ForkDigestHex, CachedGenesis} from "./types.js"; -export {ForkDigestContext} from "./types.js"; +export type {ForkDigestContext} from "./types.js"; export function createCachedGenesis(chainForkConfig: ChainForkConfig, genesisValidatorsRoot: Root): CachedGenesis { const domainCache = new Map>(); diff --git a/packages/db/package.json b/packages/db/package.json index f9227668e829..d5d0e686bf0b 100644 --- a/packages/db/package.json +++ b/packages/db/package.json @@ -33,7 +33,7 @@ "lint:fix": "yarn run lint --fix", "pretest": "yarn run check-types", "test": "yarn test:unit", - "test:unit": "mocha 'test/unit/**/*.test.ts'", + "test:unit": "TS_NODE_TRANSPILE_ONLY=true mocha 'test/unit/**/*.test.ts'", "check-readme": "typescript-docs-verifier" }, "dependencies": { diff --git a/packages/db/src/controller/index.ts b/packages/db/src/controller/index.ts index 4dbe95621d1b..d1142c15379c 100644 --- a/packages/db/src/controller/index.ts +++ b/packages/db/src/controller/index.ts @@ -1,3 +1,3 @@ -export {Db, DbReqOpts, DatabaseController, FilterOptions, KeyValue} from "./interface.js"; +export type {Db, DbReqOpts, DatabaseController, FilterOptions, KeyValue} from "./interface.js"; export {LevelDbController} from "./level.js"; -export {LevelDbControllerMetrics} from "./metrics.js"; +export type {LevelDbControllerMetrics} from "./metrics.js"; diff --git a/packages/flare/package.json b/packages/flare/package.json index 05f6094f3a16..8a41d0aedb72 100644 --- a/packages/flare/package.json +++ b/packages/flare/package.json @@ -44,7 +44,7 @@ "lint": "eslint --color --ext .ts src/", "lint:fix": "yarn run lint --fix", "pretest": "yarn run check-types", - "test:unit": "nyc --cache-dir .nyc_output/.cache -e .ts mocha 'test/unit/**/*.test.ts'", + "test:unit": "TS_NODE_TRANSPILE_ONLY=true nyc --cache-dir .nyc_output/.cache -e .ts mocha 'test/unit/**/*.test.ts'", "check-readme": "typescript-docs-verifier" }, "repository": { diff --git a/packages/fork-choice/package.json b/packages/fork-choice/package.json index 0e8de6bf52f5..31572791896d 100644 --- a/packages/fork-choice/package.json +++ b/packages/fork-choice/package.json @@ -34,7 +34,7 @@ "lint:fix": "yarn run lint --fix", "pretest": "yarn run check-types", "test": "yarn test:unit", - "test:unit": "mocha --colors -r ts-node/register 'test/unit/**/*.test.ts'", + "test:unit": "TS_NODE_TRANSPILE_ONLY=true mocha --colors -r ts-node/register 'test/unit/**/*.test.ts'", "check-readme": "typescript-docs-verifier" }, "dependencies": { diff --git a/packages/fork-choice/src/index.ts b/packages/fork-choice/src/index.ts index 922e624bae97..ff0711599a54 100644 --- a/packages/fork-choice/src/index.ts +++ b/packages/fork-choice/src/index.ts @@ -1,28 +1,33 @@ export {ProtoArray} from "./protoArray/protoArray.js"; -export { +export type { ProtoBlock, ProtoNode, - ExecutionStatus, MaybeValidExecutionStatus, BlockExecution, LVHValidResponse, LVHInvalidResponse, } from "./protoArray/interface.js"; +export {ExecutionStatus} from "./protoArray/interface.js"; -export {ForkChoice, ForkChoiceOpts, assertValidTerminalPowBlock} from "./forkChoice/forkChoice.js"; +export {ForkChoice, type ForkChoiceOpts, assertValidTerminalPowBlock} from "./forkChoice/forkChoice.js"; export { - IForkChoice, - PowBlockHex, + type IForkChoice, + type PowBlockHex, EpochDifference, - AncestorResult, + type AncestorResult, AncestorStatus, - ForkChoiceMetrics, + type ForkChoiceMetrics, } from "./forkChoice/interface.js"; -export {ForkChoiceStore, IForkChoiceStore, CheckpointWithHex, JustifiedBalancesGetter} from "./forkChoice/store.js"; export { - InvalidAttestation, + ForkChoiceStore, + type IForkChoiceStore, + type CheckpointWithHex, + type JustifiedBalancesGetter, +} from "./forkChoice/store.js"; +export { + type InvalidAttestation, InvalidAttestationCode, - InvalidBlock, + type InvalidBlock, InvalidBlockCode, ForkChoiceError, ForkChoiceErrorCode, diff --git a/packages/light-client/package.json b/packages/light-client/package.json index 95bca9e36b29..69f4c6a2eead 100644 --- a/packages/light-client/package.json +++ b/packages/light-client/package.json @@ -60,7 +60,7 @@ "pretest": "yarn run check-types", "test": "yarn test:unit && yarn test:e2e", "test:browsers": "yarn karma start karma.config.cjs", - "test:unit": "LODESTAR_PRESET=minimal nyc --cache-dir .nyc_output/.cache -e .ts mocha 'test/unit/**/*.test.ts'", + "test:unit": "TS_NODE_TRANSPILE_ONLY=true LODESTAR_PRESET=minimal nyc --cache-dir .nyc_output/.cache -e .ts mocha 'test/unit/**/*.test.ts'", "check-readme": "typescript-docs-verifier" }, "dependencies": { diff --git a/packages/light-client/src/index.ts b/packages/light-client/src/index.ts index 67dc86762ede..ba0acb0d0c99 100644 --- a/packages/light-client/src/index.ts +++ b/packages/light-client/src/index.ts @@ -18,7 +18,7 @@ import {LightClientTransport} from "./transport/interface.js"; // Re-export types export {LightclientEvent} from "./events.js"; -export {SyncCommitteeFast} from "./types.js"; +export type {SyncCommitteeFast} from "./types.js"; export {upgradeLightClientFinalityUpdate, upgradeLightClientOptimisticUpdate} from "./spec/utils.js"; export type GenesisData = { diff --git a/packages/light-client/src/spec/index.ts b/packages/light-client/src/spec/index.ts index 2cd58c42883e..e81dba437dea 100644 --- a/packages/light-client/src/spec/index.ts +++ b/packages/light-client/src/spec/index.ts @@ -6,7 +6,8 @@ import {getSyncCommitteeAtPeriod, processLightClientUpdate, ProcessUpdateOpts} f import {ILightClientStore, LightClientStore, LightClientStoreEvents} from "./store.js"; import {ZERO_FINALITY_BRANCH, ZERO_HEADER, ZERO_NEXT_SYNC_COMMITTEE_BRANCH, ZERO_SYNC_COMMITTEE} from "./utils.js"; -export {isBetterUpdate, toLightClientUpdateSummary, LightClientUpdateSummary} from "./isBetterUpdate.js"; +export {isBetterUpdate, toLightClientUpdateSummary} from "./isBetterUpdate.js"; +export type {LightClientUpdateSummary} from "./isBetterUpdate.js"; export {upgradeLightClientHeader} from "./utils.js"; export class LightclientSpec { diff --git a/packages/logger/package.json b/packages/logger/package.json index 79ac91120f99..6b1fb1fce23a 100644 --- a/packages/logger/package.json +++ b/packages/logger/package.json @@ -56,9 +56,9 @@ "lint": "eslint --color --ext .ts src/ test/", "lint:fix": "yarn run lint --fix", "pretest": "yarn run check-types", - "test:unit": "mocha 'test/unit/**/*.test.ts'", + "test:unit": "TS_NODE_TRANSPILE_ONLY=true mocha 'test/unit/**/*.test.ts'", "test:browsers": "yarn karma start karma.config.cjs", - "test:e2e": "LODESTAR_PRESET=minimal mocha 'test/e2e/**/*.test.ts'", + "test:e2e": "TS_NODE_TRANSPILE_ONLY=true LODESTAR_PRESET=minimal mocha 'test/e2e/**/*.test.ts'", "check-readme": "typescript-docs-verifier" }, "types": "lib/index.d.ts", diff --git a/packages/logger/src/interface.ts b/packages/logger/src/interface.ts index 9b413accd0ad..8f270b0dc4ee 100644 --- a/packages/logger/src/interface.ts +++ b/packages/logger/src/interface.ts @@ -2,7 +2,8 @@ import {LEVEL, MESSAGE} from "triple-beam"; import {LogLevel, Logger, LogHandler, LogData} from "@lodestar/utils"; -export {LogLevel, Logger, LogHandler, LogData, LEVEL, MESSAGE}; +export {LogLevel, LEVEL, MESSAGE}; +export type {Logger, LogHandler, LogData}; export const logLevelNum: {[K in LogLevel]: number} = { [LogLevel.error]: 0, diff --git a/packages/params/package.json b/packages/params/package.json index abaa37d87894..95fa6d859a23 100644 --- a/packages/params/package.json +++ b/packages/params/package.json @@ -53,9 +53,9 @@ "lint": "eslint --color --ext .ts src/ test/", "lint:fix": "yarn run lint --fix", "test": "yarn run check-types", - "test:unit": "mocha 'test/unit/**/*.test.ts'", + "test:unit": "TS_NODE_TRANSPILE_ONLY=true mocha 'test/unit/**/*.test.ts'", "test:browsers": "yarn karma start karma.config.cjs", - "test:e2e": "LODESTAR_PRESET=minimal mocha 'test/e2e/**/*.test.ts'", + "test:e2e": "TS_NODE_TRANSPILE_ONLY=true LODESTAR_PRESET=minimal mocha 'test/e2e/**/*.test.ts'", "check-readme": "typescript-docs-verifier" }, "repository": { diff --git a/packages/params/src/index.ts b/packages/params/src/index.ts index b167f25ffd97..cdf9d7e8d144 100644 --- a/packages/params/src/index.ts +++ b/packages/params/src/index.ts @@ -5,18 +5,9 @@ import {gnosisPreset} from "./presets/gnosis.js"; import {presetStatus} from "./presetStatus.js"; import {userSelectedPreset, userOverrides} from "./setPreset.js"; -export {BeaconPreset} from "./types.js"; -export { - ForkName, - ForkSeq, - ForkLightClient, - ForkExecution, - ForkBlobs, - isForkExecution, - isForkWithdrawals, - isForkBlobs, - isForkLightClient, -} from "./forkName.js"; +export type {BeaconPreset} from "./types.js"; +export type {ForkLightClient, ForkExecution, ForkBlobs} from "./forkName.js"; +export {ForkName, ForkSeq, isForkExecution, isForkWithdrawals, isForkBlobs, isForkLightClient} from "./forkName.js"; export {presetToJson} from "./json.js"; export {PresetName}; diff --git a/packages/prover/package.json b/packages/prover/package.json index 9822b25cf60e..6f577327ff24 100644 --- a/packages/prover/package.json +++ b/packages/prover/package.json @@ -53,9 +53,9 @@ "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:unit": "TS_NODE_TRANSPILE_ONLY=true 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:e2e": "TS_NODE_TRANSPILE_ONLY=true LODESTAR_PRESET=minimal mocha 'test/e2e/**/*.test.ts'", "check-readme": "typescript-docs-verifier", "generate-fixtures": "node --loader ts-node/esm scripts/generate_fixtures.ts" }, diff --git a/packages/prover/src/interfaces.ts b/packages/prover/src/interfaces.ts index 1f191be8bf4f..334bc48837a8 100644 --- a/packages/prover/src/interfaces.ts +++ b/packages/prover/src/interfaces.ts @@ -5,7 +5,7 @@ import {ProofProvider} from "./proof_provider/proof_provider.js"; import {JsonRpcRequest, JsonRpcRequestOrBatch, JsonRpcResponse, JsonRpcResponseOrBatch} from "./types.js"; import {ELRpc} from "./utils/rpc.js"; -export {NetworkName} from "@lodestar/config/networks"; +export type {NetworkName} from "@lodestar/config/networks"; export enum LCTransport { Rest = "Rest", P2P = "P2P", diff --git a/packages/reqresp/package.json b/packages/reqresp/package.json index d24fc6379462..b81735d700ce 100644 --- a/packages/reqresp/package.json +++ b/packages/reqresp/package.json @@ -49,8 +49,8 @@ "lint": "eslint --color --ext .ts src/ test/", "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": "yarn test:unit", + "test:unit": "TS_NODE_TRANSPILE_ONLY=true nyc --cache-dir .nyc_output/.cache -e .ts mocha 'test/unit/**/*.test.ts'", "check-readme": "typescript-docs-verifier" }, "dependencies": { diff --git a/packages/reqresp/src/index.ts b/packages/reqresp/src/index.ts index 9a39d4fe0d5f..9bb07c1a4fce 100644 --- a/packages/reqresp/src/index.ts +++ b/packages/reqresp/src/index.ts @@ -1,5 +1,7 @@ -export {ReqResp, ReqRespOpts} from "./ReqResp.js"; -export {getMetrics, Metrics, MetricsRegister} from "./metrics.js"; +export {ReqResp} from "./ReqResp.js"; +export type {ReqRespOpts} from "./ReqResp.js"; +export {getMetrics} from "./metrics.js"; +export type {Metrics, MetricsRegister} from "./metrics.js"; export {Encoding as ReqRespEncoding} from "./types.js"; // Expose enums renamed export * from "./types.js"; export * from "./interface.js"; diff --git a/packages/state-transition/package.json b/packages/state-transition/package.json index 133e149188b7..417f0f1d8983 100644 --- a/packages/state-transition/package.json +++ b/packages/state-transition/package.json @@ -52,7 +52,7 @@ "check-types": "tsc", "lint": "eslint --color --ext .ts src/ test/", "lint:fix": "yarn run lint --fix", - "test:unit": "mocha 'test/unit/**/*.test.ts'", + "test:unit": "TS_NODE_TRANSPILE_ONLY=true mocha 'test/unit/**/*.test.ts'", "check-readme": "typescript-docs-verifier" }, "types": "lib/index.d.ts", diff --git a/packages/state-transition/src/index.ts b/packages/state-transition/src/index.ts index 8c9a296ebd9f..f9db0bb84887 100644 --- a/packages/state-transition/src/index.ts +++ b/packages/state-transition/src/index.ts @@ -2,9 +2,9 @@ export * from "./stateTransition.js"; export * from "./constants/index.js"; export * from "./util/index.js"; export * from "./signatureSets/index.js"; -export {BeaconStateTransitionMetrics} from "./metrics.js"; +export type {BeaconStateTransitionMetrics} from "./metrics.js"; -export { +export type { CachedBeaconStatePhase0, CachedBeaconStateAltair, CachedBeaconStateBellatrix, @@ -25,25 +25,25 @@ export { // Main state caches export { createCachedBeaconState, - BeaconStateCache, + type BeaconStateCache, isCachedBeaconState, isStateBalancesNodesPopulated, isStateValidatorsNodesPopulated, } from "./cache/stateCache.js"; export { EpochCache, - EpochCacheImmutableData, + type EpochCacheImmutableData, createEmptyEpochCacheImmutableData, EpochCacheError, EpochCacheErrorCode, } from "./cache/epochCache.js"; -export {EpochTransitionCache, beforeProcessEpoch} from "./cache/epochTransitionCache.js"; +export {type EpochTransitionCache, beforeProcessEpoch} from "./cache/epochTransitionCache.js"; // Aux data-structures -export {PubkeyIndexMap, Index2PubkeyCache} from "./cache/pubkeyCache.js"; +export {PubkeyIndexMap, type Index2PubkeyCache} from "./cache/pubkeyCache.js"; export { - EffectiveBalanceIncrements, + type EffectiveBalanceIncrements, getEffectiveBalanceIncrementsZeroed, getEffectiveBalanceIncrementsWithLen, } from "./cache/effectiveBalanceIncrements.js"; @@ -53,7 +53,7 @@ export {isValidVoluntaryExit} from "./block/processVoluntaryExit.js"; export {isValidBlsToExecutionChange} from "./block/processBlsToExecutionChange.js"; export {assertValidProposerSlashing} from "./block/processProposerSlashing.js"; export {assertValidAttesterSlashing} from "./block/processAttesterSlashing.js"; -export {ExecutionPayloadStatus, DataAvailableStatus, BlockExternalData} from "./block/externalData.js"; +export {ExecutionPayloadStatus, DataAvailableStatus, type BlockExternalData} from "./block/externalData.js"; // BeaconChain, to prepare new blocks export {becomesNewEth1Data} from "./block/processEth1Data.js"; diff --git a/packages/state-transition/src/types.ts b/packages/state-transition/src/types.ts index 3271253ee8d3..6b6b1f6260b2 100644 --- a/packages/state-transition/src/types.ts +++ b/packages/state-transition/src/types.ts @@ -1,7 +1,7 @@ export {EpochCache} from "./cache/epochCache.js"; -export {EpochTransitionCache} from "./cache/epochTransitionCache.js"; +export type {EpochTransitionCache} from "./cache/epochTransitionCache.js"; -export { +export type { CachedBeaconStateAllForks, CachedBeaconStateExecutions, CachedBeaconStatePhase0, @@ -11,7 +11,7 @@ export { CachedBeaconStateDeneb, } from "./cache/stateCache.js"; -export { +export type { BeaconStateAllForks, BeaconStateExecutions, BeaconStatePhase0, diff --git a/packages/types/package.json b/packages/types/package.json index 45676cc616f0..c350161eb118 100644 --- a/packages/types/package.json +++ b/packages/types/package.json @@ -61,7 +61,7 @@ "check-types": "tsc", "lint": "eslint --color --ext .ts src/ test/", "lint:fix": "yarn run lint --fix", - "test:unit": "mocha 'test/**/*.test.ts'", + "test:unit": "TS_NODE_TRANSPILE_ONLY=true mocha 'test/**/*.test.ts'", "test:browsers": "yarn karma start karma.config.cjs", "check-readme": "typescript-docs-verifier" }, diff --git a/packages/utils/package.json b/packages/utils/package.json index 6e2bc4ab50fa..18dca134347b 100644 --- a/packages/utils/package.json +++ b/packages/utils/package.json @@ -31,7 +31,7 @@ "lint": "eslint --color --ext .ts src/ test/", "lint:fix": "yarn run lint --fix", "pretest": "yarn run check-types", - "test:unit": "mocha 'test/**/*.test.ts'", + "test:unit": "TS_NODE_TRANSPILE_ONLY=true mocha 'test/**/*.test.ts'", "test:browsers": "yarn karma start karma.config.cjs", "check-readme": "typescript-docs-verifier" }, diff --git a/packages/utils/src/index.ts b/packages/utils/src/index.ts index 8e622b310c31..be939673845c 100644 --- a/packages/utils/src/index.ts +++ b/packages/utils/src/index.ts @@ -9,12 +9,12 @@ export * from "./logger.js"; export * from "./map.js"; export * from "./math.js"; export * from "./objects.js"; -export {retry, RetryOptions} from "./retry.js"; +export {retry, type RetryOptions} from "./retry.js"; export * from "./notNullish.js"; export * from "./sleep.js"; export * from "./sort.js"; export * from "./timeout.js"; -export {RecursivePartial, bnToNum} from "./types.js"; +export {type RecursivePartial, bnToNum} from "./types.js"; export * from "./validation.js"; export * from "./verifyMerkleBranch.js"; export * from "./promise.js"; diff --git a/packages/validator/package.json b/packages/validator/package.json index 862962a6e02a..e1cb35298c69 100644 --- a/packages/validator/package.json +++ b/packages/validator/package.json @@ -31,8 +31,8 @@ "test:unit": "nyc --cache-dir .nyc_output/.cache -e .ts mocha 'test/unit/**/*.test.ts'", "test": "yarn test:unit", "test:e2e:only": "mocha 'test/e2e/**/*.test.ts'", - "test:spec": "mocha 'test/spec/**/*.test.ts'", - "test:e2e": "LODESTAR_PRESET=minimal yarn run download-spec-tests && yarn test:spec && yarn test:e2e:only", + "test:spec": "TS_NODE_TRANSPILE_ONLY=true mocha 'test/spec/**/*.test.ts'", + "test:e2e": "TS_NODE_TRANSPILE_ONLY=true LODESTAR_PRESET=minimal yarn run download-spec-tests && yarn test:spec && yarn test:e2e:only", "download-spec-tests": "node --loader=ts-node/esm test/spec/downloadTests.ts", "coverage": "codecov -F lodestar-validator", "check-readme": "typescript-docs-verifier" diff --git a/packages/validator/src/index.ts b/packages/validator/src/index.ts index a6f3f878d358..35e05303e615 100644 --- a/packages/validator/src/index.ts +++ b/packages/validator/src/index.ts @@ -1,17 +1,14 @@ -export {Validator, ValidatorOptions} from "./validator.js"; -export { - ValidatorStore, - SignerType, +export {Validator, type ValidatorOptions} from "./validator.js"; +export {ValidatorStore, SignerType, defaultOptions, BuilderSelection} from "./services/validatorStore.js"; +export type { Signer, SignerLocal, SignerRemote, ValidatorProposerConfig, - defaultOptions, ProposerConfig, - BuilderSelection, } from "./services/validatorStore.js"; export {waitForGenesis} from "./genesis.js"; -export {getMetrics, Metrics, MetricsRegister} from "./metrics.js"; +export {getMetrics, type Metrics, type MetricsRegister} from "./metrics.js"; // Remote signer client export { @@ -21,7 +18,7 @@ export { } from "./util/externalSignerClient.js"; // Types -export {ProcessShutdownCallback} from "./types.js"; +export type {ProcessShutdownCallback} from "./types.js"; export * from "./slashingProtection/index.js"; export * from "./repositories/index.js"; diff --git a/packages/validator/src/slashingProtection/index.ts b/packages/validator/src/slashingProtection/index.ts index 505a0981a212..7186e5d67d9c 100644 --- a/packages/validator/src/slashingProtection/index.ts +++ b/packages/validator/src/slashingProtection/index.ts @@ -22,8 +22,9 @@ import {SlashingProtectionBlock, SlashingProtectionAttestation} from "./types.js export {InvalidAttestationError, InvalidAttestationErrorCode} from "./attestation/index.js"; export {InvalidBlockError, InvalidBlockErrorCode} from "./block/index.js"; -export {InterchangeError, InterchangeErrorErrorCode, Interchange, InterchangeFormat} from "./interchange/index.js"; -export {ISlashingProtection, InterchangeFormatVersion, SlashingProtectionBlock, SlashingProtectionAttestation}; +export {InterchangeError, InterchangeErrorErrorCode} from "./interchange/index.js"; +export type {Interchange, InterchangeFormat} from "./interchange/index.js"; +export type {ISlashingProtection, InterchangeFormatVersion, SlashingProtectionBlock, SlashingProtectionAttestation}; /** * Handles slashing protection for validator proposer and attester duties as well as slashing protection * during a validator interchange import/export process. From b0fb3412d8591dd9f8e346e9831eed35dcedbd87 Mon Sep 17 00:00:00 2001 From: Nazar Hussain Date: Tue, 19 Sep 2023 10:09:33 +0200 Subject: [PATCH 10/28] Remove unused file --- .../e2e/network/gossipsub-without-mocha.ts | 90 ------------------- 1 file changed, 90 deletions(-) delete mode 100644 packages/beacon-node/test/e2e/network/gossipsub-without-mocha.ts diff --git a/packages/beacon-node/test/e2e/network/gossipsub-without-mocha.ts b/packages/beacon-node/test/e2e/network/gossipsub-without-mocha.ts deleted file mode 100644 index fa14fa13c4f6..000000000000 --- a/packages/beacon-node/test/e2e/network/gossipsub-without-mocha.ts +++ /dev/null @@ -1,90 +0,0 @@ -import wtf from "wtfnode"; -import {createChainForkConfig, defaultChainConfig} from "@lodestar/config"; -import {sleep} from "@lodestar/utils"; -import {computeStartSlotAtEpoch} from "@lodestar/state-transition"; -import {ssz} from "@lodestar/types"; -import {Network} from "../../../src/network/index.js"; -import {GossipType, GossipHandlers, GossipHandlerParamGeneric} from "../../../src/network/gossip/index.js"; -import {connect, onPeerConnect, getNetworkForTest} from "../../utils/network.js"; - -await runTests({useWorker: false}); -console.log("\n\n%%%%%%%%%%%% finished non worker tests"); -wtf.dump(); -await sleep(2000); -console.log("\n\n\n"); -wtf.dump(); - -await runTests({useWorker: true}); -console.log("\n\n%%%%%%%%%%%% finished worker tests"); -wtf.dump(); -await sleep(1000); -console.log("\n\n\n"); -wtf.dump(); - -async function runTests({useWorker}: {useWorker: boolean}): Promise { - console.log("\n\n%%%%%%%%%%%% starting tests with useWorker", useWorker); - console.log("%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%"); - const afterEachCallbacks: (() => Promise | void)[] = []; - - // Schedule all forks at ALTAIR_FORK_EPOCH to avoid generating the pubkeys cache - /* eslint-disable @typescript-eslint/naming-convention */ - const config = createChainForkConfig({ - ...defaultChainConfig, - ALTAIR_FORK_EPOCH: 1, - BELLATRIX_FORK_EPOCH: 1, - CAPELLA_FORK_EPOCH: 1, - }); - computeStartSlotAtEpoch(config.ALTAIR_FORK_EPOCH); - - // eslint-disable-next-line @typescript-eslint/explicit-function-return-type - async function mockModules(gossipHandlersPartial?: Partial) { - const [netA, closeA] = await getNetworkForTest("A", config, {opts: {useWorker}, gossipHandlersPartial}); - const [netB, closeB] = await getNetworkForTest("B", config, {opts: {useWorker}, gossipHandlersPartial}); - - afterEachCallbacks.push(async () => { - await closeA(); - await closeB(); - }); - - return {netA, netB}; - } - - let onVoluntaryExit: (ve: Uint8Array) => void; - const onVoluntaryExitPromise = new Promise((resolve) => (onVoluntaryExit = resolve)); - - const {netA, netB} = await mockModules({ - [GossipType.voluntary_exit]: async ({gossipData}: GossipHandlerParamGeneric) => { - onVoluntaryExit(gossipData.serializedData); - }, - }); - - await Promise.all([onPeerConnect(netA), onPeerConnect(netB), connect(netA, netB)]); - console.log("%%%%%", netA.getConnectedPeerCount()); - console.log("%%%%%", netB.getConnectedPeerCount()); - - await netA.subscribeGossipCoreTopics(); - await netB.subscribeGossipCoreTopics(); - - // Wait to have a peer connected to a topic - while (!netA.closed) { - await sleep(500); - if (await hasSomeMeshPeer(netA)) { - break; - } - } - - const voluntaryExit = ssz.phase0.SignedVoluntaryExit.defaultValue(); - voluntaryExit.message.epoch = config.ALTAIR_FORK_EPOCH; - await netA.publishVoluntaryExit(voluntaryExit); - - await onVoluntaryExitPromise; - - while (afterEachCallbacks.length > 0) { - const callback = afterEachCallbacks.pop(); - if (callback) await callback(); - } -} - -async function hasSomeMeshPeer(net: Network): Promise { - return Object.values(await net.dumpMeshPeers()).some((peers) => peers.length > 0); -} From 7e4082255e79663b6014787c742091da3550c111 Mon Sep 17 00:00:00 2001 From: Nazar Hussain Date: Tue, 19 Sep 2023 11:15:10 +0200 Subject: [PATCH 11/28] Revert changes to an e2e test file --- .../test/e2e/api/impl/lightclient/endpoint.test.ts | 9 +++++---- 1 file changed, 5 insertions(+), 4 deletions(-) diff --git a/packages/beacon-node/test/e2e/api/impl/lightclient/endpoint.test.ts b/packages/beacon-node/test/e2e/api/impl/lightclient/endpoint.test.ts index c0a91096f25b..716c4d196367 100644 --- a/packages/beacon-node/test/e2e/api/impl/lightclient/endpoint.test.ts +++ b/packages/beacon-node/test/e2e/api/impl/lightclient/endpoint.test.ts @@ -31,7 +31,7 @@ describe("lightclient api", function () { let validators: Validator[]; const afterEachCallbacks: (() => Promise | void)[] = []; - before(async () => { + this.beforeEach(async () => { bn = await getDevBeaconNode({ params: chainConfig, options: { @@ -41,7 +41,7 @@ describe("lightclient api", function () { rest: { enabled: true, port: restPort, - // api: ["lightclient"], + api: ["lightclient"], }, }, chain: {blsVerifyAllMainThread: true}, @@ -64,7 +64,7 @@ describe("lightclient api", function () { afterEachCallbacks.push(() => Promise.all(validators.map((validator) => validator.close()))); }); - after(async () => { + afterEach(async () => { while (afterEachCallbacks.length > 0) { const callback = afterEachCallbacks.pop(); if (callback) await callback(); @@ -120,9 +120,10 @@ describe("lightclient api", function () { it("getCommitteeRoot() for the 1st period", async function () { await waitForBestUpdate(); - const {lightclient, beacon: client} = getClient({baseUrl: `http://127.0.0.1:${restPort}`}, {config}); + const lightclient = getClient({baseUrl: `http://127.0.0.1:${restPort}`}, {config}).lightclient; const committeeRes = await lightclient.getCommitteeRoot(0, 1); ApiError.assert(committeeRes); + const client = getClient({baseUrl: `http://127.0.0.1:${restPort}`}, {config}).beacon; const validatorResponse = await client.getStateValidators("head"); ApiError.assert(validatorResponse); const pubkeys = validatorResponse.response.data.map((v) => v.validator.pubkey); From ef8ed66586224b53db213341fc015406c6ba3405 Mon Sep 17 00:00:00 2001 From: Nazar Hussain Date: Tue, 19 Sep 2023 12:09:59 +0200 Subject: [PATCH 12/28] Reduce the genesis delay --- packages/beacon-node/test/e2e/chain/lightclient.test.ts | 2 +- packages/beacon-node/test/e2e/sync/unknownBlockSync.test.ts | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/packages/beacon-node/test/e2e/chain/lightclient.test.ts b/packages/beacon-node/test/e2e/chain/lightclient.test.ts index f83a658b9565..1a9edbefc432 100644 --- a/packages/beacon-node/test/e2e/chain/lightclient.test.ts +++ b/packages/beacon-node/test/e2e/chain/lightclient.test.ts @@ -54,7 +54,7 @@ describe("chain / lightclient", function () { // delay a bit so regular sync sees it's up to date and sync is completed from the beginning // also delay to allow bls workers to be transpiled/initialized - const genesisSlotsDelay = 16; + const genesisSlotsDelay = 7; const genesisTime = Math.floor(Date.now() / 1000) + genesisSlotsDelay * testParams.SECONDS_PER_SLOT; const testLoggerOpts: TestLoggerOpts = { diff --git a/packages/beacon-node/test/e2e/sync/unknownBlockSync.test.ts b/packages/beacon-node/test/e2e/sync/unknownBlockSync.test.ts index 97d4b45c7558..95ebcaa955fb 100644 --- a/packages/beacon-node/test/e2e/sync/unknownBlockSync.test.ts +++ b/packages/beacon-node/test/e2e/sync/unknownBlockSync.test.ts @@ -47,7 +47,7 @@ describe("sync / unknown block sync", function () { this.timeout("10 min"); // the node needs time to transpile/initialize bls worker threads - const genesisSlotsDelay = 16; + const genesisSlotsDelay = 7; const genesisTime = Math.floor(Date.now() / 1000) + genesisSlotsDelay * testParams.SECONDS_PER_SLOT; const testLoggerOpts: TestLoggerOpts = { level: LogLevel.info, From b5476acdf950e75cebe09cd49bc3e7951a1651e9 Mon Sep 17 00:00:00 2001 From: Nazar Hussain Date: Tue, 19 Sep 2023 12:48:28 +0200 Subject: [PATCH 13/28] Refactor workflow jobs --- .github/workflows/test-browser.yml | 65 -------- .github/workflows/test-e2e.yml | 79 --------- .github/workflows/test-spec.yml | 70 -------- .github/workflows/test.yml | 258 +++++++++++++++++++++++++---- 4 files changed, 229 insertions(+), 243 deletions(-) delete mode 100644 .github/workflows/test-browser.yml delete mode 100644 .github/workflows/test-e2e.yml delete mode 100644 .github/workflows/test-spec.yml diff --git a/.github/workflows/test-browser.yml b/.github/workflows/test-browser.yml deleted file mode 100644 index 28b5d65e4684..000000000000 --- a/.github/workflows/test-browser.yml +++ /dev/null @@ -1,65 +0,0 @@ -name: Browser tests - -concurrency: - # If PR, cancel prev commits. head_ref = source branch name on pull_request, null if push - group: ${{ github.workflow }}-${{ github.head_ref || github.run_id }} - cancel-in-progress: true - -on: - push: - # We intentionally don't run push on feature branches. See PR for rational. - branches: [unstable, stable] - pull_request: - workflow_dispatch: - -jobs: - tests-main: - name: Tests - runs-on: buildjet-4vcpu-ubuntu-2204 - strategy: - fail-fast: false - matrix: - node: [20] - steps: - # - Uses YAML anchors in the future - - uses: actions/checkout@v3 - - uses: browser-actions/setup-firefox@latest - with: - firefox-version: "latest" - - uses: actions/setup-node@v3 - with: - node-version: ${{matrix.node}} - check-latest: true - cache: yarn - - name: Node.js version - id: node - run: echo "v8CppApiVersion=$(node --print "process.versions.modules")" >> $GITHUB_OUTPUT - - name: Restore dependencies - uses: actions/cache@master - id: cache-deps - with: - path: | - node_modules - packages/*/node_modules - key: ${{ runner.os }}-${{ steps.node.outputs.v8CppApiVersion }}-${{ hashFiles('**/yarn.lock', '**/package.json') }} - - name: Install & build - if: steps.cache-deps.outputs.cache-hit != 'true' - run: yarn install --frozen-lockfile && yarn build - - name: Build - run: yarn build - if: steps.cache-deps.outputs.cache-hit == 'true' - # - - # Misc sanity checks - - name: Test root binary exists - run: ./lodestar --version - - name: Reject yarn.lock changes - run: .github/workflows/scripts/reject_yarn_lock_changes.sh - # Run only on forks - if: ${{ github.event_name == 'pull_request' && github.event.pull_request.head.repo.full_name != github.repository }} - - - name: Browser tests - run: | - export DISPLAY=':99.0' - Xvfb :99 -screen 0 1024x768x24 > /dev/null 2>&1 & - yarn test:browsers diff --git a/.github/workflows/test-e2e.yml b/.github/workflows/test-e2e.yml deleted file mode 100644 index d8e467e6caf5..000000000000 --- a/.github/workflows/test-e2e.yml +++ /dev/null @@ -1,79 +0,0 @@ -name: E2E tests - -concurrency: - # If PR, cancel prev commits. head_ref = source branch name on pull_request, null if push - group: ${{ github.workflow }}-${{ github.head_ref || github.run_id }} - cancel-in-progress: true - -on: - push: - # We intentionally don't run push on feature branches. See PR for rational. - branches: [unstable, stable] - pull_request: - workflow_dispatch: - -env: - GOERLI_RPC_DEFAULT_URL: https://goerli.infura.io/v3/84842078b09946638c03157f83405213 - GETH_DOCKER_IMAGE: ethereum/client-go:v1.11.6 - NETHERMIND_DOCKER_IMAGE: nethermind/nethermind:1.18.0 - -jobs: - e2e-tests: - name: E2E Tests - runs-on: buildjet-4vcpu-ubuntu-2204 - strategy: - fail-fast: false - matrix: - node: [20] - steps: - # - Uses YAML anchors in the future - - uses: actions/checkout@v3 - - uses: actions/setup-node@v3 - with: - node-version: ${{matrix.node}} - check-latest: true - cache: yarn - - name: Node.js version - id: node - run: echo "v8CppApiVersion=$(node --print "process.versions.modules")" >> $GITHUB_OUTPUT - - name: Restore dependencies - uses: actions/cache@master - id: cache-deps - with: - path: | - node_modules - packages/*/node_modules - key: ${{ runner.os }}-${{ steps.node.outputs.v8CppApiVersion }}-${{ hashFiles('**/yarn.lock', '**/package.json') }} - - name: Install & build - if: steps.cache-deps.outputs.cache-hit != 'true' - run: yarn install --frozen-lockfile && yarn build - - name: Build - run: yarn build - if: steps.cache-deps.outputs.cache-hit == 'true' - # - - # Misc sanity checks - - name: Test root binary exists - run: ./lodestar --version - - name: Reject yarn.lock changes - run: .github/workflows/scripts/reject_yarn_lock_changes.sh - # Run only on forks - if: ${{ github.event_name == 'pull_request' && github.event.pull_request.head.repo.full_name != github.repository }} - - - name: Run the e2e test environment - run: scripts/run_e2e_env.sh start - - - name: E2E tests - run: yarn test:e2e - env: - GOERLI_RPC_URL: ${{ secrets.GOERLI_RPC_URL!=0 && secrets.GOERLI_RPC_URL || env.GOERLI_RPC_DEFAULT_URL }} - - - name: Stop the e2e test environment - run: scripts/run_e2e_env.sh stop - - - name: Upload debug log test for test env - if: ${{ always() }} - uses: actions/upload-artifact@v2 - with: - name: debug-e2e-test-logs - path: test-logs/e2e-test-env diff --git a/.github/workflows/test-spec.yml b/.github/workflows/test-spec.yml deleted file mode 100644 index 21063b924092..000000000000 --- a/.github/workflows/test-spec.yml +++ /dev/null @@ -1,70 +0,0 @@ -name: Spec tests - -concurrency: - # If PR, cancel prev commits. head_ref = source branch name on pull_request, null if push - group: ${{ github.workflow }}-${{ github.head_ref || github.run_id }} - cancel-in-progress: true - -on: - push: - # We intentionally don't run push on feature branches. See PR for rational. - branches: [unstable, stable] - pull_request: - workflow_dispatch: - -jobs: - tests-spec: - name: Spec tests - runs-on: buildjet-4vcpu-ubuntu-2204 - steps: - # As of October 2020, runner has +8GB of free space w/out this script (takes 1m30s to run) - # - run: ./scripts/free-disk-space.sh - - # - Uses YAML anchors in the future - - uses: actions/checkout@v3 - - uses: actions/setup-node@v3 - with: - node-version: 20 - check-latest: true - cache: yarn - - name: Node.js version - id: node - run: echo "v8CppApiVersion=$(node --print "process.versions.modules")" >> $GITHUB_OUTPUT - - name: Restore dependencies - uses: actions/cache@master - id: cache-deps - with: - path: | - node_modules - packages/*/node_modules - key: ${{ runner.os }}-${{ steps.node.outputs.v8CppApiVersion }}-${{ hashFiles('**/yarn.lock', '**/package.json') }} - - name: Install & build - if: steps.cache-deps.outputs.cache-hit != 'true' - run: yarn install --frozen-lockfile && yarn build - - name: Build - run: yarn build - if: steps.cache-deps.outputs.cache-hit == 'true' - # - - # Download spec tests with cache - - name: Restore spec tests cache - uses: actions/cache@master - with: - path: packages/beacon-node/spec-tests - key: spec-test-data-${{ hashFiles('packages/beacon-node/test/spec/specTestVersioning.ts') }} - - name: Download spec tests - run: yarn download-spec-tests - working-directory: packages/beacon-node - - # Run them in different steps to quickly identifying which command failed - # Otherwise just doing `yarn test:spec` you can't tell which specific suite failed - # many of the suites have identical names for minimal and mainnet - - name: Spec tests bls-general - run: yarn test:spec-bls-general - working-directory: packages/beacon-node - - name: Spec tests minimal - run: yarn test:spec-minimal - working-directory: packages/beacon-node - - name: Spec tests mainnet - run: NODE_OPTIONS='--max-old-space-size=4096' yarn test:spec-mainnet - working-directory: packages/beacon-node diff --git a/.github/workflows/test.yml b/.github/workflows/test.yml index 549fc5b72ac1..f173a292272e 100644 --- a/.github/workflows/test.yml +++ b/.github/workflows/test.yml @@ -13,8 +13,8 @@ on: workflow_dispatch: jobs: - unit-tests: - name: Unit Tests + build: + name: Build runs-on: buildjet-4vcpu-ubuntu-2204 strategy: fail-fast: false @@ -27,61 +27,261 @@ jobs: with: node-version: ${{matrix.node}} check-latest: true - cache: yarn + cache: yarn - name: Node.js version id: node run: echo "v8CppApiVersion=$(node --print "process.versions.modules")" >> $GITHUB_OUTPUT - - name: Restore dependencies + - name: Restore build uses: actions/cache@master - id: cache-deps + id: cache-build-restore with: path: | node_modules packages/*/node_modules - key: ${{ runner.os }}-${{ steps.node.outputs.v8CppApiVersion }}-${{ hashFiles('**/yarn.lock', '**/package.json') }} + lib/ + packages/*/lib + key: ${{ runner.os }}-${{ matrix.node }}-${{ github.event.pull_request.head.sha }} - name: Install & build - if: steps.cache-deps.outputs.cache-hit != 'true' + if: steps.cache-build-restore.outputs.cache-hit != 'true' run: yarn install --frozen-lockfile && yarn build - name: Build run: yarn build - if: steps.cache-deps.outputs.cache-hit == 'true' - # - - # Cache validator slashing protection data tests - - name: Restore spec tests cache - uses: actions/cache@master - with: - path: packages/validator/spec-tests - key: spec-test-data-${{ hashFiles('packages/validator/test/spec/params.ts') }} - - - name: Assert yarn prints no warnings - run: scripts/assert_no_yarn_warnings.sh - - # Misc sanity checks - - name: Lint Grafana dashboards - run: scripts/validate-grafana-dashboards.sh + if: steps.cache-build-restore.outputs.cache-hit == 'true' + - name: Check Build + run: yarn check-build - name: Test root binary exists - run: ./lodestar --version + run: ./lodestar --version - name: Reject yarn.lock changes run: .github/workflows/scripts/reject_yarn_lock_changes.sh # Run only on forks if: ${{ github.event_name == 'pull_request' && github.event.pull_request.head.repo.full_name != github.repository }} + - name: Cache build artifacts + uses: actions/cache@master + id: cache-build + with: + path: | + node_modules + packages/*/node_modules + lib/ + packages/*/lib + key: ${{ runner.os }}-${{ matrix.node }}-${{ github.event.pull_request.head.sha }} + + lint: + name: Lint + needs: build + runs-on: 'ubuntu-latest' + steps: + - uses: actions/checkout@v3 + - uses: actions/setup-node@v3 + with: + node-version: 20 + check-latest: true + cache: yarn + - name: Restore build cache + id: cache-primes-restore + uses: actions/cache/restore@v3 + with: + path: | + node_modules + packages/*/node_modules + lib/ + packages/*/lib + key: ${{ runner.os }}-20-${{ github.event.pull_request.head.sha }} + - name: Assert yarn prints no warnings + run: scripts/assert_no_yarn_warnings.sh + - name: Lint Code + run: yarn lint + - name: Lint Grafana dashboards + run: scripts/validate-grafana-dashboards.sh - name: Assert ESM module exports run: node scripts/assert_exports.mjs - name: Assert eslintrc rules sorted run: scripts/assert_eslintrc_sorted.mjs + type-checks: + name: Type Checks + needs: build + runs-on: 'ubuntu-latest' + steps: + - uses: actions/checkout@v3 + - uses: actions/setup-node@v3 + with: + node-version: 20 + check-latest: true + cache: yarn + - name: Restore build cache + id: cache-primes-restore + uses: actions/cache/restore@v3 + with: + path: | + node_modules + packages/*/node_modules + lib/ + packages/*/lib + key: ${{ runner.os }}-20-${{ github.event.pull_request.head.sha }} + - name: Check Types run: yarn check-types - + - name: README check run: yarn check-readme + + unit-tests: + name: Unit Tests + needs: type-checks + runs-on: buildjet-4vcpu-ubuntu-2204 + strategy: + fail-fast: false + matrix: + node: [20] + steps: + - uses: actions/checkout@v3 + - uses: actions/setup-node@v3 + with: + node-version: ${{matrix.node}} + check-latest: true + cache: yarn + - name: Restore build cache + id: cache-primes-restore + uses: actions/cache/restore@v3 + with: + path: | + node_modules + packages/*/node_modules + lib/ + packages/*/lib + key: ${{ runner.os }}-${{ matrix.node }}-${{ github.event.pull_request.head.sha }} + # Cache validator slashing protection data tests + - name: Restore spec tests cache + uses: actions/cache@master + with: + path: packages/validator/spec-tests + key: spec-test-data-${{ hashFiles('packages/validator/test/spec/params.ts') }} - - name: Lint - run: yarn lint - - name: Check Build - run: yarn check-build - name: Unit tests run: yarn test:unit - name: Upload coverage data run: yarn coverage + + e2e-tests: + name: E2E Tests + runs-on: buildjet-4vcpu-ubuntu-2204 + needs: build + strategy: + fail-fast: false + matrix: + node: [20] + steps: + # - Uses YAML anchors in the future + - uses: actions/checkout@v3 + - uses: actions/setup-node@v3 + with: + node-version: ${{matrix.node}} + check-latest: true + cache: yarn + - name: Restore build cache + id: cache-primes-restore + uses: actions/cache/restore@v3 + with: + path: | + node_modules + packages/*/node_modules + lib/ + packages/*/lib + key: ${{ runner.os }}-${{ matrix.node }}-${{ github.event.pull_request.head.sha }} + + - name: Run the e2e test environment + run: scripts/run_e2e_env.sh start + + - name: E2E tests + run: yarn test:e2e + env: + GOERLI_RPC_URL: ${{ secrets.GOERLI_RPC_URL!=0 && secrets.GOERLI_RPC_URL || env.GOERLI_RPC_DEFAULT_URL }} + + - name: Stop the e2e test environment + run: scripts/run_e2e_env.sh stop + + - name: Upload debug log test for test env + if: ${{ always() }} + uses: actions/upload-artifact@v2 + with: + name: debug-e2e-test-logs + path: test-logs/e2e-test-env + + browser-tests: + name: Browser Tests + runs-on: buildjet-4vcpu-ubuntu-2204 + needs: build + strategy: + fail-fast: false + matrix: + node: [20] + steps: + # - Uses YAML anchors in the future + - uses: actions/checkout@v3 + - uses: actions/setup-node@v3 + with: + node-version: ${{matrix.node}} + check-latest: true + cache: yarn + - name: Restore build cache + id: cache-primes-restore + uses: actions/cache/restore@v3 + with: + path: | + node_modules + packages/*/node_modules + lib/ + packages/*/lib + key: ${{ runner.os }}-${{ matrix.node }}-${{ github.event.pull_request.head.sha }} + + - name: Browser tests + run: | + export DISPLAY=':99.0' + Xvfb :99 -screen 0 1024x768x24 > /dev/null 2>&1 & + yarn test:browsers + + spec-tests: + name: Spec tests + needs: type-checks + runs-on: buildjet-4vcpu-ubuntu-2204 + strategy: + fail-fast: false + matrix: + node: [20] + steps: + - uses: actions/checkout@v3 + - uses: actions/setup-node@v3 + with: + node-version: ${{matrix.node}} + check-latest: true + cache: yarn + - name: Restore build cache + id: cache-primes-restore + uses: actions/cache/restore@v3 + with: + path: | + node_modules + packages/*/node_modules + lib/ + packages/*/lib + key: ${{ runner.os }}-${{ matrix.node }}-${{ github.event.pull_request.head.sha }} + # Download spec tests with cache + - name: Restore spec tests cache + uses: actions/cache@master + with: + path: packages/beacon-node/spec-tests + key: spec-test-data-${{ hashFiles('packages/beacon-node/test/spec/specTestVersioning.ts') }} + + # Run them in different steps to quickly identifying which command failed + # Otherwise just doing `yarn test:spec` you can't tell which specific suite failed + # many of the suites have identical names for minimal and mainnet + - name: Spec tests bls-general + run: yarn test:spec-bls-general + working-directory: packages/beacon-node + - name: Spec tests minimal + run: yarn test:spec-minimal + working-directory: packages/beacon-node + - name: Spec tests mainnet + run: NODE_OPTIONS='--max-old-space-size=4096' yarn test:spec-mainnet + working-directory: packages/beacon-node From 1399df19238b79c5afe471eea98afd52f73f4248 Mon Sep 17 00:00:00 2001 From: Nazar Hussain Date: Tue, 19 Sep 2023 14:10:46 +0200 Subject: [PATCH 14/28] Add .git-data to build cache --- .github/workflows/test.yml | 12 ++++++++++-- 1 file changed, 10 insertions(+), 2 deletions(-) diff --git a/.github/workflows/test.yml b/.github/workflows/test.yml index f173a292272e..0ea0d168bec5 100644 --- a/.github/workflows/test.yml +++ b/.github/workflows/test.yml @@ -32,7 +32,7 @@ jobs: id: node run: echo "v8CppApiVersion=$(node --print "process.versions.modules")" >> $GITHUB_OUTPUT - name: Restore build - uses: actions/cache@master + uses: actions/cache/restore@v3 id: cache-build-restore with: path: | @@ -40,6 +40,7 @@ jobs: packages/*/node_modules lib/ packages/*/lib + packages/*/.git-data.json key: ${{ runner.os }}-${{ matrix.node }}-${{ github.event.pull_request.head.sha }} - name: Install & build if: steps.cache-build-restore.outputs.cache-hit != 'true' @@ -64,6 +65,7 @@ jobs: packages/*/node_modules lib/ packages/*/lib + packages/*/.git-data.json key: ${{ runner.os }}-${{ matrix.node }}-${{ github.event.pull_request.head.sha }} lint: @@ -86,6 +88,7 @@ jobs: packages/*/node_modules lib/ packages/*/lib + packages/*/.git-data.json key: ${{ runner.os }}-20-${{ github.event.pull_request.head.sha }} - name: Assert yarn prints no warnings run: scripts/assert_no_yarn_warnings.sh @@ -118,6 +121,7 @@ jobs: packages/*/node_modules lib/ packages/*/lib + packages/*/.git-data.json key: ${{ runner.os }}-20-${{ github.event.pull_request.head.sha }} - name: Check Types @@ -150,6 +154,7 @@ jobs: packages/*/node_modules lib/ packages/*/lib + packages/*/.git-data.json key: ${{ runner.os }}-${{ matrix.node }}-${{ github.event.pull_request.head.sha }} # Cache validator slashing protection data tests - name: Restore spec tests cache @@ -188,6 +193,7 @@ jobs: packages/*/node_modules lib/ packages/*/lib + packages/*/.git-data.json key: ${{ runner.os }}-${{ matrix.node }}-${{ github.event.pull_request.head.sha }} - name: Run the e2e test environment @@ -233,6 +239,7 @@ jobs: packages/*/node_modules lib/ packages/*/lib + packages/*/.git-data.json key: ${{ runner.os }}-${{ matrix.node }}-${{ github.event.pull_request.head.sha }} - name: Browser tests @@ -243,7 +250,7 @@ jobs: spec-tests: name: Spec tests - needs: type-checks + needs: build runs-on: buildjet-4vcpu-ubuntu-2204 strategy: fail-fast: false @@ -265,6 +272,7 @@ jobs: packages/*/node_modules lib/ packages/*/lib + packages/*/.git-data.json key: ${{ runner.os }}-${{ matrix.node }}-${{ github.event.pull_request.head.sha }} # Download spec tests with cache - name: Restore spec tests cache From 477b03878d8dab5119abb86c82bf52a4b780bece Mon Sep 17 00:00:00 2001 From: Nazar Hussain Date: Tue, 19 Sep 2023 14:14:33 +0200 Subject: [PATCH 15/28] Fix spec tests option --- .github/workflows/test.yml | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/.github/workflows/test.yml b/.github/workflows/test.yml index 0ea0d168bec5..29e5a69e4345 100644 --- a/.github/workflows/test.yml +++ b/.github/workflows/test.yml @@ -280,7 +280,9 @@ jobs: with: path: packages/beacon-node/spec-tests key: spec-test-data-${{ hashFiles('packages/beacon-node/test/spec/specTestVersioning.ts') }} - + - name: Download spec tests + run: yarn download-spec-tests + working-directory: packages/beacon-node # Run them in different steps to quickly identifying which command failed # Otherwise just doing `yarn test:spec` you can't tell which specific suite failed # many of the suites have identical names for minimal and mainnet From 502e0249fd8cd8e4d69a134a7d061749591e9a7c Mon Sep 17 00:00:00 2001 From: Nazar Hussain Date: Tue, 19 Sep 2023 14:23:59 +0200 Subject: [PATCH 16/28] Upgrade the github action version --- .github/workflows/test-sim-merge.yml | 4 ++-- .github/workflows/test.yml | 2 +- 2 files changed, 3 insertions(+), 3 deletions(-) diff --git a/.github/workflows/test-sim-merge.yml b/.github/workflows/test-sim-merge.yml index e9aeb09f4607..268df5620559 100644 --- a/.github/workflows/test-sim-merge.yml +++ b/.github/workflows/test-sim-merge.yml @@ -92,7 +92,7 @@ jobs: - name: Upload debug log test files if: ${{ always() }} - uses: actions/upload-artifact@v2 + uses: actions/upload-artifact@v3 with: name: debug-test-logs path: packages/beacon-node/test-logs @@ -144,7 +144,7 @@ jobs: - name: Upload debug log test files if: ${{ always() }} - uses: actions/upload-artifact@v2 + uses: actions/upload-artifact@v3 with: name: debug-test-logs path: packages/beacon-node/test-logs diff --git a/.github/workflows/test.yml b/.github/workflows/test.yml index 29e5a69e4345..c818cee27995 100644 --- a/.github/workflows/test.yml +++ b/.github/workflows/test.yml @@ -209,7 +209,7 @@ jobs: - name: Upload debug log test for test env if: ${{ always() }} - uses: actions/upload-artifact@v2 + uses: actions/upload-artifact@v3 with: name: debug-e2e-test-logs path: test-logs/e2e-test-env From 66e6c589d4ddb5978c0d4886a38606622c91a378 Mon Sep 17 00:00:00 2001 From: Nazar Hussain Date: Tue, 19 Sep 2023 15:12:21 +0200 Subject: [PATCH 17/28] Add a package dev dependency --- package.json | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/package.json b/package.json index 6353104811c3..3c14dfbe7d72 100644 --- a/package.json +++ b/package.json @@ -93,7 +93,8 @@ "ts-node": "^10.9.1", "typescript": "^5.1.6", "typescript-docs-verifier": "^2.5.0", - "webpack": "^5.88.1" + "webpack": "^5.88.1", + "wait-port": "^1.0.4" }, "resolutions": { "dns-over-http-resolver": "^2.1.1" From 1c627823867e3901cd65a82e006cbebb4574568e Mon Sep 17 00:00:00 2001 From: Nazar Hussain Date: Tue, 19 Sep 2023 15:14:21 +0200 Subject: [PATCH 18/28] Add artifact name --- .github/workflows/test.yml | 2 +- yarn.lock | 14 ++++++++++++++ 2 files changed, 15 insertions(+), 1 deletion(-) diff --git a/.github/workflows/test.yml b/.github/workflows/test.yml index c818cee27995..ff4530d9aa5f 100644 --- a/.github/workflows/test.yml +++ b/.github/workflows/test.yml @@ -211,7 +211,7 @@ jobs: if: ${{ always() }} uses: actions/upload-artifact@v3 with: - name: debug-e2e-test-logs + name: debug-e2e-test-logs-node-${{matrix.node}} path: test-logs/e2e-test-env browser-tests: diff --git a/yarn.lock b/yarn.lock index 8d6155b15fec..8b1a108000a0 100644 --- a/yarn.lock +++ b/yarn.lock @@ -5019,6 +5019,11 @@ commander@^2.20.0: resolved "https://registry.yarnpkg.com/commander/-/commander-2.20.3.tgz#fd485e84c03eb4881c20722ba48035e8531aeb33" integrity sha512-GpVkmM8vF2vQUkj2LvZmD35JxeJOLCwJ9cUkugyk2nuhbv3+mJvpLYYt+0+USMxE+oj+ey/lJEnhZw75x/OMcQ== +commander@^9.3.0: + version "9.5.0" + resolved "https://registry.yarnpkg.com/commander/-/commander-9.5.0.tgz#bc08d1eb5cedf7ccb797a96199d41c7bc3e60d30" + integrity sha512-KRs7WVDKg86PWiuAqhDrAQnTXZKraVcCc6vFdL14qrZ/DcWwuRo7VoiYXalXO7S5GKpqYiVEwCbgFDfxNHKJBQ== + commander@~2.9.0: version "2.9.0" resolved "https://registry.yarnpkg.com/commander/-/commander-2.9.0.tgz#9c99094176e12240cb22d6c5146098400fe0f7d4" @@ -13801,6 +13806,15 @@ void-elements@^2.0.0: resolved "https://registry.yarnpkg.com/void-elements/-/void-elements-2.0.1.tgz#c066afb582bb1cb4128d60ea92392e94d5e9dbec" integrity sha512-qZKX4RnBzH2ugr8Lxa7x+0V6XD9Sb/ouARtiasEQCHB1EVU4NXtmHsDDrx1dO4ne5fc3J6EW05BP1Dl0z0iung== +wait-port@^1.0.4: + version "1.0.4" + resolved "https://registry.yarnpkg.com/wait-port/-/wait-port-1.0.4.tgz#6f9474645ddbf7701ac100ab6762438edf6e5689" + integrity sha512-w8Ftna3h6XSFWWc2JC5gZEgp64nz8bnaTp5cvzbJSZ53j+omktWTDdwXxEF0jM8YveviLgFWvNGrSvRHnkyHyw== + dependencies: + chalk "^4.1.2" + commander "^9.3.0" + debug "^4.3.4" + walk-up-path@^1.0.0: version "1.0.0" resolved "https://registry.yarnpkg.com/walk-up-path/-/walk-up-path-1.0.0.tgz#d4745e893dd5fd0dbb58dd0a4c6a33d9c9fec53e" From 6dc4d12b3a4b918c3923d6f4f99aafdbd1dc8ce2 Mon Sep 17 00:00:00 2001 From: Nazar Hussain Date: Tue, 19 Sep 2023 15:43:54 +0200 Subject: [PATCH 19/28] Update the workflow to add env variables --- .github/workflows/test.yml | 5 ++++- 1 file changed, 4 insertions(+), 1 deletion(-) diff --git a/.github/workflows/test.yml b/.github/workflows/test.yml index ff4530d9aa5f..dea334e0d6a9 100644 --- a/.github/workflows/test.yml +++ b/.github/workflows/test.yml @@ -11,7 +11,10 @@ on: branches: [unstable, stable] pull_request: workflow_dispatch: - + +env: + GETH_DOCKER_IMAGE: ethereum/client-go:v1.11.6 + jobs: build: name: Build From 65f47f476e4295c00e6364aa3b19af1d9f07f18f Mon Sep 17 00:00:00 2001 From: Nazar Hussain Date: Tue, 19 Sep 2023 16:23:51 +0200 Subject: [PATCH 20/28] Update the workflow to add env variables --- .github/workflows/test.yml | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/.github/workflows/test.yml b/.github/workflows/test.yml index dea334e0d6a9..37b4f6b8e554 100644 --- a/.github/workflows/test.yml +++ b/.github/workflows/test.yml @@ -14,7 +14,8 @@ on: env: GETH_DOCKER_IMAGE: ethereum/client-go:v1.11.6 - + NETHERMIND_DOCKER_IMAGE: nethermind/nethermind:1.18.0 + jobs: build: name: Build From 97862b70f2d77b6e70619bcef2af6bf9b080b5c4 Mon Sep 17 00:00:00 2001 From: Nazar Hussain Date: Tue, 19 Sep 2023 16:24:09 +0200 Subject: [PATCH 21/28] Add tsnode option --- packages/beacon-node/package.json | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/packages/beacon-node/package.json b/packages/beacon-node/package.json index d0728418c1d8..ceb4e63527d1 100644 --- a/packages/beacon-node/package.json +++ b/packages/beacon-node/package.json @@ -88,9 +88,9 @@ "test:sim:blobs": "mocha 'test/sim/4844-interop.test.ts'", "download-spec-tests": "node --loader=ts-node/esm test/spec/downloadTests.ts", "check-spec-tests": "mocha test/spec/checkCoverage.ts", - "test:spec-bls-general": "mocha --config .mocharc.spec.cjs 'test/spec/bls/**/*.test.ts' 'test/spec/general/**/*.test.ts'", - "test:spec-minimal": "LODESTAR_PRESET=minimal mocha --config .mocharc.spec.cjs 'test/spec/presets/**/*.test.ts'", - "test:spec-mainnet": "LODESTAR_PRESET=mainnet mocha --config .mocharc.spec.cjs 'test/spec/presets/**/*.test.ts'", + "test:spec-bls-general": "TS_NODE_TRANSPILE_ONLY=true mocha --config .mocharc.spec.cjs 'test/spec/bls/**/*.test.ts' 'test/spec/general/**/*.test.ts'", + "test:spec-minimal": "TS_NODE_TRANSPILE_ONLY=true LODESTAR_PRESET=minimal mocha --config .mocharc.spec.cjs 'test/spec/presets/**/*.test.ts'", + "test:spec-mainnet": "TS_NODE_TRANSPILE_ONLY=true LODESTAR_PRESET=mainnet mocha --config .mocharc.spec.cjs 'test/spec/presets/**/*.test.ts'", "test:spec": "yarn test:spec-bls-general && yarn test:spec-minimal && yarn test:spec-mainnet", "check-readme": "typescript-docs-verifier" }, From e50a1cfac033a39cbae0cce7de5f67cc75ff2d98 Mon Sep 17 00:00:00 2001 From: Nazar Hussain Date: Wed, 20 Sep 2023 17:10:02 +0200 Subject: [PATCH 22/28] Parallelize the spec tests --- packages/beacon-node/.mocharc.spec.cjs | 3 +- ...processing.ts => epoch_processing.test.ts} | 20 ++++- .../presets/{finality.ts => finality.test.ts} | 13 ++- .../spec/presets/{fork.ts => fork.test.ts} | 13 ++- .../{fork_choice.ts => fork_choice.test.ts} | 14 +++- .../presets/{genesis.ts => genesis.test.ts} | 12 ++- .../test/spec/presets/index.test.ts | 79 ------------------- .../light_client/{index.ts => index.test.ts} | 12 ++- .../presets/{merkle.ts => merkle.test.ts} | 12 ++- .../{operations.ts => operations.test.ts} | 13 ++- .../presets/{rewards.ts => rewards.test.ts} | 12 ++- .../presets/{sanity.ts => sanity.test.ts} | 16 +++- .../{shuffling.ts => shuffling.test.ts} | 12 ++- .../{ssz_static.ts => ssz_static.test.ts} | 13 ++- .../{transition.ts => transition.test.ts} | 18 ++++- .../test/spec/utils/specTestIterator.ts | 62 ++++++++++++++- 16 files changed, 208 insertions(+), 116 deletions(-) rename packages/beacon-node/test/spec/presets/{epoch_processing.ts => epoch_processing.test.ts} (81%) rename packages/beacon-node/test/spec/presets/{finality.ts => finality.test.ts} (83%) rename packages/beacon-node/test/spec/presets/{fork.ts => fork.test.ts} (82%) rename packages/beacon-node/test/spec/presets/{fork_choice.ts => fork_choice.test.ts} (96%) rename packages/beacon-node/test/spec/presets/{genesis.ts => genesis.test.ts} (91%) delete mode 100644 packages/beacon-node/test/spec/presets/index.test.ts rename packages/beacon-node/test/spec/presets/light_client/{index.ts => index.test.ts} (51%) rename packages/beacon-node/test/spec/presets/{merkle.ts => merkle.test.ts} (80%) rename packages/beacon-node/test/spec/presets/{operations.ts => operations.test.ts} (90%) rename packages/beacon-node/test/spec/presets/{rewards.ts => rewards.test.ts} (87%) rename packages/beacon-node/test/spec/presets/{sanity.ts => sanity.test.ts} (85%) rename packages/beacon-node/test/spec/presets/{shuffling.ts => shuffling.test.ts} (62%) rename packages/beacon-node/test/spec/presets/{ssz_static.ts => ssz_static.test.ts} (85%) rename packages/beacon-node/test/spec/presets/{transition.ts => transition.test.ts} (89%) diff --git a/packages/beacon-node/.mocharc.spec.cjs b/packages/beacon-node/.mocharc.spec.cjs index 61fbf9430fe4..1a160c2d6131 100644 --- a/packages/beacon-node/.mocharc.spec.cjs +++ b/packages/beacon-node/.mocharc.spec.cjs @@ -3,6 +3,5 @@ module.exports = { require: ["./test/setupPreset.ts", "./test/setup.ts"], "node-option": ["loader=ts-node/esm"], timeout: 60_000, - // Do not run tests through workers, it's not proven to be faster than with `jobs: 2` - parallel: false, + parallel: true }; diff --git a/packages/beacon-node/test/spec/presets/epoch_processing.ts b/packages/beacon-node/test/spec/presets/epoch_processing.test.ts similarity index 81% rename from packages/beacon-node/test/spec/presets/epoch_processing.ts rename to packages/beacon-node/test/spec/presets/epoch_processing.test.ts index f804062f56a0..554001bfbde8 100644 --- a/packages/beacon-node/test/spec/presets/epoch_processing.ts +++ b/packages/beacon-node/test/spec/presets/epoch_processing.test.ts @@ -1,3 +1,4 @@ +import path from "node:path"; import {expect} from "chai"; import { CachedBeaconStateAllForks, @@ -7,11 +8,14 @@ import { } from "@lodestar/state-transition"; import * as epochFns from "@lodestar/state-transition/epoch"; import {ssz} from "@lodestar/types"; +import {ACTIVE_PRESET} from "@lodestar/params"; import {createCachedBeaconStateTest} from "../../utils/cachedBeaconState.js"; import {expectEqualBeaconState, inputTypeSszTreeViewDU} from "../utils/expectEqualBeaconState.js"; import {getConfig} from "../../utils/config.js"; -import {TestRunnerFn} from "../utils/types.js"; +import {RunnerType, TestRunnerFn} from "../utils/types.js"; import {assertCorrectProgressiveBalances} from "../config.js"; +import {ethereumConsensusSpecsTests} from "../specTestVersioning.js"; +import {specTestIterator} from "../utils/specTestIterator.js"; export type EpochTransitionFn = (state: CachedBeaconStateAllForks, epochTransitionCache: EpochTransitionCache) => void; @@ -47,7 +51,7 @@ type EpochTransitionCacheingTestCase = { * @param fork * @param epochTransitionFns Describe with which function to run each directory of tests */ -export const epochProcessing = +const epochProcessing = (skipTestNames?: string[]): TestRunnerFn => (fork, testName) => { const config = getConfig(fork); @@ -92,3 +96,15 @@ export const epochProcessing = }, }; }; + +specTestIterator(path.join(ethereumConsensusSpecsTests.outputDir, "tests", ACTIVE_PRESET), { + epoch_processing: { + type: RunnerType.default, + fn: epochProcessing([ + // TODO: invalid_large_withdrawable_epoch asserts an overflow on a u64 for its exit epoch. + // Currently unable to reproduce in Lodestar, skipping for now + // https://github.com/ethereum/consensus-specs/blob/3212c419f6335e80ed825b4855a071f76bef70c3/tests/core/pyspec/eth2spec/test/phase0/epoch_processing/test_process_registry_updates.py#L349 + "invalid_large_withdrawable_epoch", + ]), + }, +}); diff --git a/packages/beacon-node/test/spec/presets/finality.ts b/packages/beacon-node/test/spec/presets/finality.test.ts similarity index 83% rename from packages/beacon-node/test/spec/presets/finality.ts rename to packages/beacon-node/test/spec/presets/finality.test.ts index 132318083f3d..5bfd32ea6a7e 100644 --- a/packages/beacon-node/test/spec/presets/finality.ts +++ b/packages/beacon-node/test/spec/presets/finality.test.ts @@ -1,3 +1,4 @@ +import path from "node:path"; import { BeaconStateAllForks, DataAvailableStatus, @@ -5,16 +6,18 @@ import { stateTransition, } from "@lodestar/state-transition"; import {altair, bellatrix, ssz} from "@lodestar/types"; -import {ForkName} from "@lodestar/params"; +import {ACTIVE_PRESET, ForkName} from "@lodestar/params"; import {createCachedBeaconStateTest} from "../../utils/cachedBeaconState.js"; import {expectEqualBeaconState, inputTypeSszTreeViewDU} from "../utils/expectEqualBeaconState.js"; -import {shouldVerify, TestRunnerFn} from "../utils/types.js"; +import {RunnerType, shouldVerify, TestRunnerFn} from "../utils/types.js"; import {getConfig} from "../../utils/config.js"; import {assertCorrectProgressiveBalances} from "../config.js"; +import {ethereumConsensusSpecsTests} from "../specTestVersioning.js"; +import {specTestIterator} from "../utils/specTestIterator.js"; /* eslint-disable @typescript-eslint/naming-convention */ -export const finality: TestRunnerFn = (fork) => { +const finality: TestRunnerFn = (fork) => { return { testFunction: (testcase) => { let state = createCachedBeaconStateTest(testcase.pre, getConfig(fork)); @@ -80,3 +83,7 @@ type FinalityTestCase = { pre: BeaconStateAllForks; post?: BeaconStateAllForks; }; + +specTestIterator(path.join(ethereumConsensusSpecsTests.outputDir, "tests", ACTIVE_PRESET), { + finality: {type: RunnerType.default, fn: finality}, +}); diff --git a/packages/beacon-node/test/spec/presets/fork.ts b/packages/beacon-node/test/spec/presets/fork.test.ts similarity index 82% rename from packages/beacon-node/test/spec/presets/fork.ts rename to packages/beacon-node/test/spec/presets/fork.test.ts index 5fb241c26e89..228ab6a38935 100644 --- a/packages/beacon-node/test/spec/presets/fork.ts +++ b/packages/beacon-node/test/spec/presets/fork.test.ts @@ -1,3 +1,4 @@ +import path from "node:path"; import { BeaconStateAllForks, CachedBeaconStateBellatrix, @@ -7,13 +8,15 @@ import { } from "@lodestar/state-transition"; import * as slotFns from "@lodestar/state-transition/slot"; import {phase0, ssz} from "@lodestar/types"; -import {ForkName} from "@lodestar/params"; +import {ACTIVE_PRESET, ForkName} from "@lodestar/params"; import {createChainForkConfig, ChainForkConfig} from "@lodestar/config"; import {expectEqualBeaconState, inputTypeSszTreeViewDU} from "../utils/expectEqualBeaconState.js"; import {createCachedBeaconStateTest} from "../../utils/cachedBeaconState.js"; -import {TestRunnerFn} from "../utils/types.js"; +import {RunnerType, TestRunnerFn} from "../utils/types.js"; +import {ethereumConsensusSpecsTests} from "../specTestVersioning.js"; +import {specTestIterator} from "../utils/specTestIterator.js"; -export const fork: TestRunnerFn = (forkNext) => { +const fork: TestRunnerFn = (forkNext) => { const config = createChainForkConfig({}); const forkPrev = getPreviousFork(config, forkNext); @@ -66,3 +69,7 @@ export function getPreviousFork(config: ChainForkConfig, fork: ForkName): ForkNa } return config.forksAscendingEpochOrder[forkIndex - 1].name; } + +specTestIterator(path.join(ethereumConsensusSpecsTests.outputDir, "tests", ACTIVE_PRESET), { + fork: {type: RunnerType.default, fn: fork}, +}); diff --git a/packages/beacon-node/test/spec/presets/fork_choice.ts b/packages/beacon-node/test/spec/presets/fork_choice.test.ts similarity index 96% rename from packages/beacon-node/test/spec/presets/fork_choice.ts rename to packages/beacon-node/test/spec/presets/fork_choice.test.ts index 10bbac4a19bc..7b2dca6e4ede 100644 --- a/packages/beacon-node/test/spec/presets/fork_choice.ts +++ b/packages/beacon-node/test/spec/presets/fork_choice.test.ts @@ -1,3 +1,4 @@ +import path from "node:path"; import {expect} from "chai"; import {toHexString} from "@chainsafe/ssz"; import {BeaconStateAllForks, isExecutionStateType} from "@lodestar/state-transition"; @@ -6,13 +7,13 @@ import {CheckpointWithHex, ForkChoice} from "@lodestar/fork-choice"; import {phase0, allForks, bellatrix, ssz, RootHex} from "@lodestar/types"; import {bnToNum} from "@lodestar/utils"; import {createBeaconConfig} from "@lodestar/config"; -import {ForkSeq, isForkBlobs} from "@lodestar/params"; +import {ACTIVE_PRESET, ForkSeq, isForkBlobs} from "@lodestar/params"; import {BeaconChain} from "../../../src/chain/index.js"; import {ClockEvent} from "../../../src/util/clock.js"; import {createCachedBeaconStateTest} from "../../utils/cachedBeaconState.js"; import {testLogger} from "../../utils/logger.js"; import {getConfig} from "../../utils/config.js"; -import {TestRunnerFn} from "../utils/types.js"; +import {RunnerType, TestRunnerFn} from "../utils/types.js"; import {Eth1ForBlockProductionDisabled} from "../../../src/eth1/index.js"; import {getExecutionEngineFromBackend} from "../../../src/execution/index.js"; import {ExecutionPayloadStatus} from "../../../src/execution/engine/interface.js"; @@ -25,6 +26,8 @@ import {ZERO_HASH_HEX} from "../../../src/constants/constants.js"; import {PowMergeBlock} from "../../../src/eth1/interface.js"; import {assertCorrectProgressiveBalances} from "../config.js"; import {initCKZG, loadEthereumTrustedSetup} from "../../../src/util/kzg.js"; +import {ethereumConsensusSpecsTests} from "../specTestVersioning.js"; +import {specTestIterator} from "../utils/specTestIterator.js"; /* eslint-disable @typescript-eslint/naming-convention */ @@ -37,7 +40,7 @@ const ATTESTER_SLASHING_FILE_NAME = "^(attester_slashing)_([0-9a-zA-Z])+$"; const logger = testLogger("spec-test"); -export const forkChoiceTest = +const forkChoiceTest = (opts: {onlyPredefinedResponses: boolean}): TestRunnerFn => (fork) => { return { @@ -460,3 +463,8 @@ class Eth1ForBlockProductionMock extends Eth1ForBlockProductionDisabled { }); } } + +specTestIterator(path.join(ethereumConsensusSpecsTests.outputDir, "tests", ACTIVE_PRESET), { + fork_choice: {type: RunnerType.default, fn: forkChoiceTest({onlyPredefinedResponses: false})}, + sync: {type: RunnerType.default, fn: forkChoiceTest({onlyPredefinedResponses: true})}, +}); diff --git a/packages/beacon-node/test/spec/presets/genesis.ts b/packages/beacon-node/test/spec/presets/genesis.test.ts similarity index 91% rename from packages/beacon-node/test/spec/presets/genesis.ts rename to packages/beacon-node/test/spec/presets/genesis.test.ts index d80b56dbe65f..ef3006bd6221 100644 --- a/packages/beacon-node/test/spec/presets/genesis.ts +++ b/packages/beacon-node/test/spec/presets/genesis.test.ts @@ -1,3 +1,4 @@ +import path from "node:path"; import {expect} from "chai"; import {phase0, Root, ssz, TimeSeconds, allForks, deneb} from "@lodestar/types"; import {InputType} from "@lodestar/spec-test-util"; @@ -10,15 +11,20 @@ import { import {bnToNum} from "@lodestar/utils"; import {ForkName} from "@lodestar/params"; +import {ACTIVE_PRESET} from "@lodestar/params"; import {expectEqualBeaconState} from "../utils/expectEqualBeaconState.js"; import {TestRunnerFn} from "../utils/types.js"; import {getConfig} from "../../utils/config.js"; + +import {RunnerType} from "../utils/types.js"; +import {specTestIterator} from "../utils/specTestIterator.js"; +import {ethereumConsensusSpecsTests} from "../specTestVersioning.js"; // The aim of the genesis tests is to provide a baseline to test genesis-state initialization and test if the // proposed genesis-validity conditions are working. /* eslint-disable @typescript-eslint/naming-convention */ -export const genesis: TestRunnerFn = (fork, testName, testSuite) => { +const genesis: TestRunnerFn = (fork, testName, testSuite) => { const testFn = genesisTestFns[testName]; if (testFn === undefined) { throw Error(`Unknown genesis test ${testName}`); @@ -145,3 +151,7 @@ type GenesisInitCase = { }; type ExecutionFork = Exclude; + +specTestIterator(path.join(ethereumConsensusSpecsTests.outputDir, "tests", ACTIVE_PRESET), { + genesis: {type: RunnerType.default, fn: genesis}, +}); diff --git a/packages/beacon-node/test/spec/presets/index.test.ts b/packages/beacon-node/test/spec/presets/index.test.ts deleted file mode 100644 index c45f859ec1e5..000000000000 --- a/packages/beacon-node/test/spec/presets/index.test.ts +++ /dev/null @@ -1,79 +0,0 @@ -import path from "node:path"; -import {ACTIVE_PRESET} from "@lodestar/params"; - -import {RunnerType} from "../utils/types.js"; -import {SkipOpts, specTestIterator} from "../utils/specTestIterator.js"; -import {ethereumConsensusSpecsTests} from "../specTestVersioning.js"; -import {epochProcessing} from "./epoch_processing.js"; -import {finality} from "./finality.js"; -import {fork} from "./fork.js"; -import {forkChoiceTest} from "./fork_choice.js"; -import {genesis} from "./genesis.js"; -import {lightClient} from "./light_client/index.js"; -import {merkle} from "./merkle.js"; -import {operations} from "./operations.js"; -import {rewards} from "./rewards.js"; -import {sanity, sanityBlocks} from "./sanity.js"; -import {shuffling} from "./shuffling.js"; -import {sszStatic} from "./ssz_static.js"; -import {transition} from "./transition.js"; - -// NOTE: You MUST always provide a detailed reason of why a spec test is skipped plus link -// to an issue marking it as pending to re-enable and an aproximate timeline of when it will -// be fixed. -// NOTE: Comment the minimum set of test necessary to unblock PRs: For example, instead of -// skipping all `bls_to_execution_change` tests, just skip for a fork setting: -// ``` -// skippedPrefixes: [ -// // Skipped since this only test that withdrawals are de-activated -// "eip4844/operations/bls_to_execution_change", -// ], -// ``` -const skipOpts: SkipOpts = { - skippedForks: ["eip6110"], - // TODO: capella - // BeaconBlockBody proof in lightclient is the new addition in v1.3.0-rc.2-hotfix - // Skip them for now to enable subsequently - skippedPrefixes: [ - "capella/light_client/single_merkle_proof/BeaconBlockBody", - "deneb/light_client/single_merkle_proof/BeaconBlockBody", - ], -}; - -/* eslint-disable @typescript-eslint/naming-convention */ - -specTestIterator( - path.join(ethereumConsensusSpecsTests.outputDir, "tests", ACTIVE_PRESET), - { - epoch_processing: { - type: RunnerType.default, - fn: epochProcessing([ - // TODO: invalid_large_withdrawable_epoch asserts an overflow on a u64 for its exit epoch. - // Currently unable to reproduce in Lodestar, skipping for now - // https://github.com/ethereum/consensus-specs/blob/3212c419f6335e80ed825b4855a071f76bef70c3/tests/core/pyspec/eth2spec/test/phase0/epoch_processing/test_process_registry_updates.py#L349 - "invalid_large_withdrawable_epoch", - ]), - }, - finality: {type: RunnerType.default, fn: finality}, - fork: {type: RunnerType.default, fn: fork}, - fork_choice: {type: RunnerType.default, fn: forkChoiceTest({onlyPredefinedResponses: false})}, - genesis: {type: RunnerType.default, fn: genesis}, - light_client: {type: RunnerType.default, fn: lightClient}, - merkle: {type: RunnerType.default, fn: merkle}, - operations: {type: RunnerType.default, fn: operations}, - random: {type: RunnerType.default, fn: sanityBlocks}, - rewards: {type: RunnerType.default, fn: rewards}, - sanity: {type: RunnerType.default, fn: sanity}, - shuffling: {type: RunnerType.default, fn: shuffling}, - ssz_static: { - type: RunnerType.custom, - fn: sszStatic(), - }, - sync: {type: RunnerType.default, fn: forkChoiceTest({onlyPredefinedResponses: true})}, - transition: { - type: RunnerType.default, - fn: transition(), - }, - }, - skipOpts -); diff --git a/packages/beacon-node/test/spec/presets/light_client/index.ts b/packages/beacon-node/test/spec/presets/light_client/index.test.ts similarity index 51% rename from packages/beacon-node/test/spec/presets/light_client/index.ts rename to packages/beacon-node/test/spec/presets/light_client/index.test.ts index ce2a0ab5a8fd..0a44772cab4b 100644 --- a/packages/beacon-node/test/spec/presets/light_client/index.ts +++ b/packages/beacon-node/test/spec/presets/light_client/index.test.ts @@ -1,11 +1,15 @@ -import {TestRunnerFn} from "../../utils/types.js"; +import path from "node:path"; +import {ACTIVE_PRESET} from "@lodestar/params"; +import {ethereumConsensusSpecsTests} from "../../specTestVersioning.js"; +import {specTestIterator} from "../../utils/specTestIterator.js"; +import {RunnerType, TestRunnerFn} from "../../utils/types.js"; import {singleMerkleProof} from "./single_merkle_proof.js"; import {sync} from "./sync.js"; import {updateRanking} from "./update_ranking.js"; /* eslint-disable @typescript-eslint/naming-convention */ -export const lightClient: TestRunnerFn = (fork, testName, testSuite) => { +const lightClient: TestRunnerFn = (fork, testName, testSuite) => { const testFn = lightclientTestFns[testName]; if (testFn === undefined) { throw Error(`Unknown lightclient test ${testName}`); @@ -19,3 +23,7 @@ const lightclientTestFns: Record> = { sync: sync, update_ranking: updateRanking, }; + +specTestIterator(path.join(ethereumConsensusSpecsTests.outputDir, "tests", ACTIVE_PRESET), { + light_client: {type: RunnerType.default, fn: lightClient}, +}); diff --git a/packages/beacon-node/test/spec/presets/merkle.ts b/packages/beacon-node/test/spec/presets/merkle.test.ts similarity index 80% rename from packages/beacon-node/test/spec/presets/merkle.ts rename to packages/beacon-node/test/spec/presets/merkle.test.ts index 8570e1ca4663..089ffcec97b3 100644 --- a/packages/beacon-node/test/spec/presets/merkle.ts +++ b/packages/beacon-node/test/spec/presets/merkle.test.ts @@ -1,3 +1,4 @@ +import path from "node:path"; import {expect} from "chai"; import {ProofType, SingleProof, Tree} from "@chainsafe/persistent-merkle-tree"; import {fromHexString, toHexString} from "@chainsafe/ssz"; @@ -5,11 +6,14 @@ import {ssz} from "@lodestar/types"; import {BeaconStateAllForks} from "@lodestar/state-transition"; import {InputType} from "@lodestar/spec-test-util"; import {verifyMerkleBranch} from "@lodestar/utils"; -import {TestRunnerFn} from "../utils/types.js"; +import {ACTIVE_PRESET} from "@lodestar/params"; +import {RunnerType, TestRunnerFn} from "../utils/types.js"; +import {ethereumConsensusSpecsTests} from "../specTestVersioning.js"; +import {specTestIterator} from "../utils/specTestIterator.js"; /* eslint-disable @typescript-eslint/naming-convention */ -export const merkle: TestRunnerFn = (fork) => { +const merkle: TestRunnerFn = (fork) => { return { testFunction: (testcase) => { const {proof: specTestProof, state} = testcase; @@ -62,3 +66,7 @@ interface IProof { leaf_index: bigint; branch: string[]; } + +specTestIterator(path.join(ethereumConsensusSpecsTests.outputDir, "tests", ACTIVE_PRESET), { + merkle: {type: RunnerType.default, fn: merkle}, +}); diff --git a/packages/beacon-node/test/spec/presets/operations.ts b/packages/beacon-node/test/spec/presets/operations.test.ts similarity index 90% rename from packages/beacon-node/test/spec/presets/operations.ts rename to packages/beacon-node/test/spec/presets/operations.test.ts index 0dc9739e31b3..cb1b5a0df3f0 100644 --- a/packages/beacon-node/test/spec/presets/operations.ts +++ b/packages/beacon-node/test/spec/presets/operations.test.ts @@ -1,3 +1,4 @@ +import path from "node:path"; import { BeaconStateAllForks, CachedBeaconStateAllForks, @@ -10,12 +11,14 @@ import { import * as blockFns from "@lodestar/state-transition/block"; import {ssz, phase0, altair, bellatrix, capella} from "@lodestar/types"; import {InputType} from "@lodestar/spec-test-util"; -import {ForkName} from "@lodestar/params"; +import {ACTIVE_PRESET, ForkName} from "@lodestar/params"; import {createCachedBeaconStateTest} from "../../utils/cachedBeaconState.js"; import {expectEqualBeaconState, inputTypeSszTreeViewDU} from "../utils/expectEqualBeaconState.js"; import {getConfig} from "../../utils/config.js"; -import {BaseSpecTest, shouldVerify, TestRunnerFn} from "../utils/types.js"; +import {BaseSpecTest, RunnerType, shouldVerify, TestRunnerFn} from "../utils/types.js"; +import {ethereumConsensusSpecsTests} from "../specTestVersioning.js"; +import {specTestIterator} from "../utils/specTestIterator.js"; /* eslint-disable @typescript-eslint/naming-convention */ @@ -95,7 +98,7 @@ export type OperationsTestCase = { execution: {execution_valid: boolean}; }; -export const operations: TestRunnerFn = (fork, testName) => { +const operations: TestRunnerFn = (fork, testName) => { const operationFn = operationFns[testName]; if (operationFn === undefined) { throw Error(`No operationFn for ${testName}`); @@ -144,3 +147,7 @@ export const operations: TestRunnerFn = }; type ExecutionFork = Exclude; + +specTestIterator(path.join(ethereumConsensusSpecsTests.outputDir, "tests", ACTIVE_PRESET), { + operations: {type: RunnerType.default, fn: operations}, +}); diff --git a/packages/beacon-node/test/spec/presets/rewards.ts b/packages/beacon-node/test/spec/presets/rewards.test.ts similarity index 87% rename from packages/beacon-node/test/spec/presets/rewards.ts rename to packages/beacon-node/test/spec/presets/rewards.test.ts index 9352b10a7737..086dab797c13 100644 --- a/packages/beacon-node/test/spec/presets/rewards.ts +++ b/packages/beacon-node/test/spec/presets/rewards.test.ts @@ -1,19 +1,23 @@ +import path from "node:path"; import {expect} from "chai"; import {VectorCompositeType} from "@chainsafe/ssz"; import {BeaconStateAllForks, beforeProcessEpoch} from "@lodestar/state-transition"; import {getRewardsAndPenalties} from "@lodestar/state-transition/epoch"; import {ssz} from "@lodestar/types"; +import {ACTIVE_PRESET} from "@lodestar/params"; import {createCachedBeaconStateTest} from "../../utils/cachedBeaconState.js"; import {inputTypeSszTreeViewDU} from "../utils/expectEqualBeaconState.js"; import {getConfig} from "../../utils/config.js"; -import {TestRunnerFn} from "../utils/types.js"; +import {RunnerType, TestRunnerFn} from "../utils/types.js"; import {assertCorrectProgressiveBalances} from "../config.js"; +import {ethereumConsensusSpecsTests} from "../specTestVersioning.js"; +import {specTestIterator} from "../utils/specTestIterator.js"; /* eslint-disable @typescript-eslint/naming-convention */ const deltasType = new VectorCompositeType(ssz.phase0.Balances, 2); -export const rewards: TestRunnerFn = (fork) => { +const rewards: TestRunnerFn = (fork) => { return { testFunction: (testcase) => { const config = getConfig(fork); @@ -85,3 +89,7 @@ function sumDeltas(deltasArr: Deltas[]): Deltas { } return totalDeltas; } + +specTestIterator(path.join(ethereumConsensusSpecsTests.outputDir, "tests", ACTIVE_PRESET), { + rewards: {type: RunnerType.default, fn: rewards}, +}); diff --git a/packages/beacon-node/test/spec/presets/sanity.ts b/packages/beacon-node/test/spec/presets/sanity.test.ts similarity index 85% rename from packages/beacon-node/test/spec/presets/sanity.ts rename to packages/beacon-node/test/spec/presets/sanity.test.ts index b57f509211b9..91836f67ccf8 100644 --- a/packages/beacon-node/test/spec/presets/sanity.ts +++ b/packages/beacon-node/test/spec/presets/sanity.test.ts @@ -1,3 +1,4 @@ +import path from "node:path"; import {InputType} from "@lodestar/spec-test-util"; import { BeaconStateAllForks, @@ -7,17 +8,19 @@ import { stateTransition, } from "@lodestar/state-transition"; import {allForks, deneb, ssz} from "@lodestar/types"; -import {ForkName} from "@lodestar/params"; +import {ACTIVE_PRESET, ForkName} from "@lodestar/params"; import {bnToNum} from "@lodestar/utils"; import {createCachedBeaconStateTest} from "../../utils/cachedBeaconState.js"; import {expectEqualBeaconState, inputTypeSszTreeViewDU} from "../utils/expectEqualBeaconState.js"; -import {shouldVerify, TestRunnerFn} from "../utils/types.js"; +import {RunnerType, shouldVerify, TestRunnerFn} from "../utils/types.js"; import {getConfig} from "../../utils/config.js"; import {assertCorrectProgressiveBalances} from "../config.js"; +import {ethereumConsensusSpecsTests} from "../specTestVersioning.js"; +import {specTestIterator} from "../utils/specTestIterator.js"; /* eslint-disable @typescript-eslint/naming-convention */ -export const sanity: TestRunnerFn = (fork, testName, testSuite) => { +const sanity: TestRunnerFn = (fork, testName, testSuite) => { switch (testName) { case "slots": return sanitySlots(fork, testName, testSuite); @@ -55,7 +58,7 @@ const sanitySlots: TestRunnerFn = (for }; }; -export const sanityBlocks: TestRunnerFn = (fork) => { +const sanityBlocks: TestRunnerFn = (fork) => { return { testFunction: (testcase) => { const stateTB = testcase.pre; @@ -119,3 +122,8 @@ type SanitySlotsTestCase = { post?: BeaconStateAllForks; slots: bigint; }; + +specTestIterator(path.join(ethereumConsensusSpecsTests.outputDir, "tests", ACTIVE_PRESET), { + sanity: {type: RunnerType.default, fn: sanity}, + random: {type: RunnerType.default, fn: sanityBlocks}, +}); diff --git a/packages/beacon-node/test/spec/presets/shuffling.ts b/packages/beacon-node/test/spec/presets/shuffling.test.ts similarity index 62% rename from packages/beacon-node/test/spec/presets/shuffling.ts rename to packages/beacon-node/test/spec/presets/shuffling.test.ts index d487c71072f2..06e7d4717d06 100644 --- a/packages/beacon-node/test/spec/presets/shuffling.ts +++ b/packages/beacon-node/test/spec/presets/shuffling.test.ts @@ -1,9 +1,13 @@ +import path from "node:path"; import {unshuffleList} from "@lodestar/state-transition"; import {InputType} from "@lodestar/spec-test-util"; import {bnToNum, fromHex} from "@lodestar/utils"; -import {TestRunnerFn} from "../utils/types.js"; +import {ACTIVE_PRESET} from "@lodestar/params"; +import {RunnerType, TestRunnerFn} from "../utils/types.js"; +import {ethereumConsensusSpecsTests} from "../specTestVersioning.js"; +import {specTestIterator} from "../utils/specTestIterator.js"; -export const shuffling: TestRunnerFn = () => { +const shuffling: TestRunnerFn = () => { return { testFunction: (testcase) => { const seed = fromHex(testcase.mapping.seed); @@ -28,3 +32,7 @@ type ShufflingTestCase = { mapping: bigint[]; }; }; + +specTestIterator(path.join(ethereumConsensusSpecsTests.outputDir, "tests", ACTIVE_PRESET), { + shuffling: {type: RunnerType.default, fn: shuffling}, +}); diff --git a/packages/beacon-node/test/spec/presets/ssz_static.ts b/packages/beacon-node/test/spec/presets/ssz_static.test.ts similarity index 85% rename from packages/beacon-node/test/spec/presets/ssz_static.ts rename to packages/beacon-node/test/spec/presets/ssz_static.test.ts index 014e7d6293e0..55587f6e9375 100644 --- a/packages/beacon-node/test/spec/presets/ssz_static.ts +++ b/packages/beacon-node/test/spec/presets/ssz_static.test.ts @@ -6,6 +6,9 @@ import {ACTIVE_PRESET, ForkName, ForkLightClient} from "@lodestar/params"; import {replaceUintTypeWithUintBigintType} from "../utils/replaceUintTypeWithUintBigintType.js"; import {parseSszStaticTestcase} from "../utils/sszTestCaseParser.js"; import {runValidSszTest} from "../utils/runValidSszTest.js"; +import {ethereumConsensusSpecsTests} from "../specTestVersioning.js"; +import {specTestIterator} from "../utils/specTestIterator.js"; +import {RunnerType} from "../utils/types.js"; // ssz_static // | Attestation @@ -26,7 +29,7 @@ type Types = Record>; // tests / mainnet / altair / ssz_static / Validator / ssz_random / case_0/roots.yaml // -export const sszStatic = +const sszStatic = (skippedTypes?: string[]) => (fork: ForkName, typeName: string, testSuite: string, testSuiteDirpath: string): void => { // Do not manually skip tests here, do it in packages/beacon-node/test/spec/presets/index.test.ts @@ -63,3 +66,11 @@ export const sszStatic = }); } }; + +specTestIterator(path.join(ethereumConsensusSpecsTests.outputDir, "tests", ACTIVE_PRESET), { + // eslint-disable-next-line @typescript-eslint/naming-convention + ssz_static: { + type: RunnerType.custom, + fn: sszStatic(), + }, +}); diff --git a/packages/beacon-node/test/spec/presets/transition.ts b/packages/beacon-node/test/spec/presets/transition.test.ts similarity index 89% rename from packages/beacon-node/test/spec/presets/transition.ts rename to packages/beacon-node/test/spec/presets/transition.test.ts index 323b8bea7a5b..3124116b2f4d 100644 --- a/packages/beacon-node/test/spec/presets/transition.ts +++ b/packages/beacon-node/test/spec/presets/transition.test.ts @@ -1,3 +1,4 @@ +import path from "node:path"; import { BeaconStateAllForks, DataAvailableStatus, @@ -6,16 +7,18 @@ import { } from "@lodestar/state-transition"; import {allForks, ssz} from "@lodestar/types"; import {createChainForkConfig, ChainConfig} from "@lodestar/config"; -import {ForkName} from "@lodestar/params"; +import {ACTIVE_PRESET, ForkName} from "@lodestar/params"; import {bnToNum} from "@lodestar/utils"; import {config} from "@lodestar/config/default"; import {expectEqualBeaconState, inputTypeSszTreeViewDU} from "../utils/expectEqualBeaconState.js"; import {createCachedBeaconStateTest} from "../../utils/cachedBeaconState.js"; -import {TestRunnerFn} from "../utils/types.js"; +import {RunnerType, TestRunnerFn} from "../utils/types.js"; import {assertCorrectProgressiveBalances} from "../config.js"; -import {getPreviousFork} from "./fork.js"; +import {ethereumConsensusSpecsTests} from "../specTestVersioning.js"; +import {specTestIterator} from "../utils/specTestIterator.js"; +import {getPreviousFork} from "./fork.test.js"; -export const transition = +const transition = (skipTestNames?: string[]): TestRunnerFn => (forkNext) => { if (forkNext === ForkName.phase0) { @@ -116,3 +119,10 @@ type TransitionTestCase = { pre: BeaconStateAllForks; post: BeaconStateAllForks; }; + +specTestIterator(path.join(ethereumConsensusSpecsTests.outputDir, "tests", ACTIVE_PRESET), { + transition: { + type: RunnerType.default, + fn: transition(), + }, +}); diff --git a/packages/beacon-node/test/spec/utils/specTestIterator.ts b/packages/beacon-node/test/spec/utils/specTestIterator.ts index d03e34dfe64a..a9310d53ac81 100644 --- a/packages/beacon-node/test/spec/utils/specTestIterator.ts +++ b/packages/beacon-node/test/spec/utils/specTestIterator.ts @@ -19,6 +19,53 @@ export interface SkipOpts { skippedHandlers?: string[]; } +/** + * Because we want to execute the spec tests in parallel so one or two runners will be executed + * in isolation at a time and would not be available how many runners are there in total. + * This list is curated manually and should be updated when new runners are added. + * It will make sure if specs introduce new runner, we should cover in our spec tests. + */ +const coveredTestRunners = [ + "light_client", + "epoch_processing", + "finality", + "fork", + "fork_choice", + "sync", + "fork", + "genesis", + "merkle", + "operations", + "rewards", + "sanity", + "random", + "shuffling", + "ssz_static", + "transition", +]; + +// NOTE: You MUST always provide a detailed reason of why a spec test is skipped plus link +// to an issue marking it as pending to re-enable and an aproximate timeline of when it will +// be fixed. +// NOTE: Comment the minimum set of test necessary to unblock PRs: For example, instead of +// skipping all `bls_to_execution_change` tests, just skip for a fork setting: +// ``` +// skippedPrefixes: [ +// // Skipped since this only test that withdrawals are de-activated +// "eip4844/operations/bls_to_execution_change", +// ], +// ``` +export const defaultSkipOpts: SkipOpts = { + skippedForks: ["eip6110"], + // TODO: capella + // BeaconBlockBody proof in lightclient is the new addition in v1.3.0-rc.2-hotfix + // Skip them for now to enable subsequently + skippedPrefixes: [ + "capella/light_client/single_merkle_proof/BeaconBlockBody", + "deneb/light_client/single_merkle_proof/BeaconBlockBody", + ], +}; + /** * This helper ensures that strictly all tests are run. There's no hardcoded value beyond "config". * Any additional unknown fork, testRunner, testHandler, or testSuite will result in an error. @@ -48,7 +95,7 @@ export interface SkipOpts { export function specTestIterator( configDirpath: string, testRunners: Record, - opts?: SkipOpts + opts: SkipOpts = defaultSkipOpts ): void { for (const forkStr of readdirSyncSpec(configDirpath)) { if (opts?.skippedForks?.includes(forkStr)) { @@ -65,6 +112,17 @@ export function specTestIterator( const testRunnerDirpath = path.join(forkDirpath, testRunnerName); const testRunner = testRunners[testRunnerName]; + if (testRunner === undefined && coveredTestRunners.includes(testRunnerName)) { + // That runner is not part of the current call to specTestIterator + continue; + } + + if (testRunner === undefined && !coveredTestRunners.includes(testRunnerName)) { + throw new Error( + `No test runner for ${testRunnerName}. Please make sure it is covered in "coveredTestRunners" if you added new runner.` + ); + } + for (const testHandler of readdirSyncSpec(testRunnerDirpath)) { if (opts?.skippedHandlers?.includes(testHandler)) { continue; @@ -78,8 +136,6 @@ export function specTestIterator( displaySkipTest(testId); } else if (fork === undefined) { displayFailTest(testId, `Unknown fork ${forkStr}`); - } else if (testRunner === undefined) { - displayFailTest(testId, `No test runner for ${testRunnerName}`); } else { const testSuiteDirpath = path.join(testHandlerDirpath, testSuite); // Specific logic for ssz_static since it has one extra level of directories From e991c1e15935fef807dfaf467352d70cd5db475f Mon Sep 17 00:00:00 2001 From: Nazar Hussain Date: Wed, 20 Sep 2023 17:34:00 +0200 Subject: [PATCH 23/28] Add the ts-node configuration --- packages/api/package.json | 2 +- packages/beacon-node/package.json | 10 +++++----- packages/cli/package.json | 4 ++-- packages/config/package.json | 2 +- packages/db/package.json | 2 +- packages/flare/package.json | 2 +- packages/fork-choice/package.json | 2 +- packages/light-client/package.json | 2 +- packages/logger/package.json | 4 ++-- packages/params/package.json | 4 ++-- packages/prover/package.json | 4 ++-- packages/reqresp/package.json | 2 +- packages/state-transition/package.json | 2 +- packages/types/package.json | 2 +- packages/utils/package.json | 2 +- packages/validator/package.json | 4 ++-- tsconfig.json | 3 +++ 17 files changed, 28 insertions(+), 25 deletions(-) diff --git a/packages/api/package.json b/packages/api/package.json index 2f93b00646c4..f87de28f0882 100644 --- a/packages/api/package.json +++ b/packages/api/package.json @@ -65,7 +65,7 @@ "lint:fix": "yarn run lint --fix", "pretest": "yarn run check-types", "test": "yarn test:unit && yarn test:e2e", - "test:unit": "TS_NODE_TRANSPILE_ONLY=true nyc --cache-dir .nyc_output/.cache -e .ts mocha 'test/unit/**/*.test.ts'", + "test:unit": "nyc --cache-dir .nyc_output/.cache -e .ts mocha 'test/unit/**/*.test.ts'", "check-readme": "typescript-docs-verifier" }, "dependencies": { diff --git a/packages/beacon-node/package.json b/packages/beacon-node/package.json index ceb4e63527d1..35638fa67109 100644 --- a/packages/beacon-node/package.json +++ b/packages/beacon-node/package.json @@ -79,8 +79,8 @@ "test": "yarn test:unit && yarn test:e2e", "test:unit:minimal": "nyc --cache-dir .nyc_output/.cache -e .ts mocha 'test/unit/**/*.test.ts'", "test:unit:mainnet": "LODESTAR_PRESET=mainnet nyc --cache-dir .nyc_output/.cache -e .ts mocha 'test/unit-mainnet/**/*.test.ts'", - "test:unit": "TS_NODE_TRANSPILE_ONLY=true yarn test:unit:minimal && yarn test:unit:mainnet", - "test:e2e": "TS_NODE_TRANSPILE_ONLY=true LODESTAR_PRESET=minimal mocha 'test/e2e/**/*.test.ts'", + "test:unit": "yarn test:unit:minimal && yarn test:unit:mainnet", + "test:e2e": "LODESTAR_PRESET=minimal mocha 'test/e2e/**/*.test.ts'", "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'", @@ -88,9 +88,9 @@ "test:sim:blobs": "mocha 'test/sim/4844-interop.test.ts'", "download-spec-tests": "node --loader=ts-node/esm test/spec/downloadTests.ts", "check-spec-tests": "mocha test/spec/checkCoverage.ts", - "test:spec-bls-general": "TS_NODE_TRANSPILE_ONLY=true mocha --config .mocharc.spec.cjs 'test/spec/bls/**/*.test.ts' 'test/spec/general/**/*.test.ts'", - "test:spec-minimal": "TS_NODE_TRANSPILE_ONLY=true LODESTAR_PRESET=minimal mocha --config .mocharc.spec.cjs 'test/spec/presets/**/*.test.ts'", - "test:spec-mainnet": "TS_NODE_TRANSPILE_ONLY=true LODESTAR_PRESET=mainnet mocha --config .mocharc.spec.cjs 'test/spec/presets/**/*.test.ts'", + "test:spec-bls-general": "mocha --config .mocharc.spec.cjs 'test/spec/bls/**/*.test.ts' 'test/spec/general/**/*.test.ts'", + "test:spec-minimal": "LODESTAR_PRESET=minimal mocha --config .mocharc.spec.cjs 'test/spec/presets/**/*.test.ts'", + "test:spec-mainnet": "LODESTAR_PRESET=mainnet mocha --config .mocharc.spec.cjs 'test/spec/presets/**/*.test.ts'", "test:spec": "yarn test:spec-bls-general && yarn test:spec-minimal && yarn test:spec-mainnet", "check-readme": "typescript-docs-verifier" }, diff --git a/packages/cli/package.json b/packages/cli/package.json index b0e7320359cb..496f29a964e3 100644 --- a/packages/cli/package.json +++ b/packages/cli/package.json @@ -31,8 +31,8 @@ "lint": "eslint --color --ext .ts src/ test/", "lint:fix": "yarn run lint --fix", "pretest": "yarn run check-types", - "test:unit": "TS_NODE_TRANSPILE_ONLY=true nyc --cache-dir .nyc_output/.cache -e .ts mocha 'test/unit/**/*.test.ts'", - "test:e2e": "TS_NODE_TRANSPILE_ONLY=true LODESTAR_PRESET=minimal mocha --timeout 30000 'test/e2e/**/*.test.ts'", + "test:unit": "nyc --cache-dir .nyc_output/.cache -e .ts mocha 'test/unit/**/*.test.ts'", + "test:e2e": "LODESTAR_PRESET=minimal mocha --timeout 30000 'test/e2e/**/*.test.ts'", "test:sim:multifork": "LODESTAR_PRESET=minimal node --loader ts-node/esm test/sim/multi_fork.test.ts", "test:sim:mixedclient": "LODESTAR_PRESET=minimal node --loader ts-node/esm test/sim/mixed_client.test.ts", "test:sim:endpoints": "LODESTAR_PRESET=minimal node --loader ts-node/esm test/sim/endpoints.test.ts", diff --git a/packages/config/package.json b/packages/config/package.json index 0047ae507e85..8fd9bd835b5c 100644 --- a/packages/config/package.json +++ b/packages/config/package.json @@ -50,7 +50,7 @@ "lint": "eslint --color --ext .ts src/", "lint:fix": "yarn run lint --fix", "pretest": "yarn run check-types", - "test:unit": "TS_NODE_TRANSPILE_ONLY=true nyc --cache-dir .nyc_output/.cache -e .ts mocha 'test/unit/**/*.test.ts'", + "test:unit": "nyc --cache-dir .nyc_output/.cache -e .ts mocha 'test/unit/**/*.test.ts'", "check-readme": "typescript-docs-verifier" }, "repository": { diff --git a/packages/db/package.json b/packages/db/package.json index d5d0e686bf0b..f9227668e829 100644 --- a/packages/db/package.json +++ b/packages/db/package.json @@ -33,7 +33,7 @@ "lint:fix": "yarn run lint --fix", "pretest": "yarn run check-types", "test": "yarn test:unit", - "test:unit": "TS_NODE_TRANSPILE_ONLY=true mocha 'test/unit/**/*.test.ts'", + "test:unit": "mocha 'test/unit/**/*.test.ts'", "check-readme": "typescript-docs-verifier" }, "dependencies": { diff --git a/packages/flare/package.json b/packages/flare/package.json index 8a41d0aedb72..05f6094f3a16 100644 --- a/packages/flare/package.json +++ b/packages/flare/package.json @@ -44,7 +44,7 @@ "lint": "eslint --color --ext .ts src/", "lint:fix": "yarn run lint --fix", "pretest": "yarn run check-types", - "test:unit": "TS_NODE_TRANSPILE_ONLY=true nyc --cache-dir .nyc_output/.cache -e .ts mocha 'test/unit/**/*.test.ts'", + "test:unit": "nyc --cache-dir .nyc_output/.cache -e .ts mocha 'test/unit/**/*.test.ts'", "check-readme": "typescript-docs-verifier" }, "repository": { diff --git a/packages/fork-choice/package.json b/packages/fork-choice/package.json index 31572791896d..0e8de6bf52f5 100644 --- a/packages/fork-choice/package.json +++ b/packages/fork-choice/package.json @@ -34,7 +34,7 @@ "lint:fix": "yarn run lint --fix", "pretest": "yarn run check-types", "test": "yarn test:unit", - "test:unit": "TS_NODE_TRANSPILE_ONLY=true mocha --colors -r ts-node/register 'test/unit/**/*.test.ts'", + "test:unit": "mocha --colors -r ts-node/register 'test/unit/**/*.test.ts'", "check-readme": "typescript-docs-verifier" }, "dependencies": { diff --git a/packages/light-client/package.json b/packages/light-client/package.json index 69f4c6a2eead..95bca9e36b29 100644 --- a/packages/light-client/package.json +++ b/packages/light-client/package.json @@ -60,7 +60,7 @@ "pretest": "yarn run check-types", "test": "yarn test:unit && yarn test:e2e", "test:browsers": "yarn karma start karma.config.cjs", - "test:unit": "TS_NODE_TRANSPILE_ONLY=true LODESTAR_PRESET=minimal nyc --cache-dir .nyc_output/.cache -e .ts mocha 'test/unit/**/*.test.ts'", + "test:unit": "LODESTAR_PRESET=minimal nyc --cache-dir .nyc_output/.cache -e .ts mocha 'test/unit/**/*.test.ts'", "check-readme": "typescript-docs-verifier" }, "dependencies": { diff --git a/packages/logger/package.json b/packages/logger/package.json index 6b1fb1fce23a..79ac91120f99 100644 --- a/packages/logger/package.json +++ b/packages/logger/package.json @@ -56,9 +56,9 @@ "lint": "eslint --color --ext .ts src/ test/", "lint:fix": "yarn run lint --fix", "pretest": "yarn run check-types", - "test:unit": "TS_NODE_TRANSPILE_ONLY=true mocha 'test/unit/**/*.test.ts'", + "test:unit": "mocha 'test/unit/**/*.test.ts'", "test:browsers": "yarn karma start karma.config.cjs", - "test:e2e": "TS_NODE_TRANSPILE_ONLY=true LODESTAR_PRESET=minimal mocha 'test/e2e/**/*.test.ts'", + "test:e2e": "LODESTAR_PRESET=minimal mocha 'test/e2e/**/*.test.ts'", "check-readme": "typescript-docs-verifier" }, "types": "lib/index.d.ts", diff --git a/packages/params/package.json b/packages/params/package.json index 95fa6d859a23..abaa37d87894 100644 --- a/packages/params/package.json +++ b/packages/params/package.json @@ -53,9 +53,9 @@ "lint": "eslint --color --ext .ts src/ test/", "lint:fix": "yarn run lint --fix", "test": "yarn run check-types", - "test:unit": "TS_NODE_TRANSPILE_ONLY=true mocha 'test/unit/**/*.test.ts'", + "test:unit": "mocha 'test/unit/**/*.test.ts'", "test:browsers": "yarn karma start karma.config.cjs", - "test:e2e": "TS_NODE_TRANSPILE_ONLY=true LODESTAR_PRESET=minimal mocha 'test/e2e/**/*.test.ts'", + "test:e2e": "LODESTAR_PRESET=minimal mocha 'test/e2e/**/*.test.ts'", "check-readme": "typescript-docs-verifier" }, "repository": { diff --git a/packages/prover/package.json b/packages/prover/package.json index 6f577327ff24..9822b25cf60e 100644 --- a/packages/prover/package.json +++ b/packages/prover/package.json @@ -53,9 +53,9 @@ "lint:fix": "yarn run lint --fix", "pretest": "yarn run check-types", "test": "yarn test:unit && yarn test:e2e", - "test:unit": "TS_NODE_TRANSPILE_ONLY=true nyc --cache-dir .nyc_output/.cache -e .ts mocha 'test/unit/**/*.test.ts'", + "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": "TS_NODE_TRANSPILE_ONLY=true LODESTAR_PRESET=minimal mocha 'test/e2e/**/*.test.ts'", + "test:e2e": "LODESTAR_PRESET=minimal mocha 'test/e2e/**/*.test.ts'", "check-readme": "typescript-docs-verifier", "generate-fixtures": "node --loader ts-node/esm scripts/generate_fixtures.ts" }, diff --git a/packages/reqresp/package.json b/packages/reqresp/package.json index b81735d700ce..42ebf3ea29a5 100644 --- a/packages/reqresp/package.json +++ b/packages/reqresp/package.json @@ -50,7 +50,7 @@ "lint:fix": "yarn run lint --fix", "pretest": "yarn run check-types", "test": "yarn test:unit", - "test:unit": "TS_NODE_TRANSPILE_ONLY=true nyc --cache-dir .nyc_output/.cache -e .ts mocha 'test/unit/**/*.test.ts'", + "test:unit": "nyc --cache-dir .nyc_output/.cache -e .ts mocha 'test/unit/**/*.test.ts'", "check-readme": "typescript-docs-verifier" }, "dependencies": { diff --git a/packages/state-transition/package.json b/packages/state-transition/package.json index 417f0f1d8983..133e149188b7 100644 --- a/packages/state-transition/package.json +++ b/packages/state-transition/package.json @@ -52,7 +52,7 @@ "check-types": "tsc", "lint": "eslint --color --ext .ts src/ test/", "lint:fix": "yarn run lint --fix", - "test:unit": "TS_NODE_TRANSPILE_ONLY=true mocha 'test/unit/**/*.test.ts'", + "test:unit": "mocha 'test/unit/**/*.test.ts'", "check-readme": "typescript-docs-verifier" }, "types": "lib/index.d.ts", diff --git a/packages/types/package.json b/packages/types/package.json index c350161eb118..45676cc616f0 100644 --- a/packages/types/package.json +++ b/packages/types/package.json @@ -61,7 +61,7 @@ "check-types": "tsc", "lint": "eslint --color --ext .ts src/ test/", "lint:fix": "yarn run lint --fix", - "test:unit": "TS_NODE_TRANSPILE_ONLY=true mocha 'test/**/*.test.ts'", + "test:unit": "mocha 'test/**/*.test.ts'", "test:browsers": "yarn karma start karma.config.cjs", "check-readme": "typescript-docs-verifier" }, diff --git a/packages/utils/package.json b/packages/utils/package.json index 18dca134347b..6e2bc4ab50fa 100644 --- a/packages/utils/package.json +++ b/packages/utils/package.json @@ -31,7 +31,7 @@ "lint": "eslint --color --ext .ts src/ test/", "lint:fix": "yarn run lint --fix", "pretest": "yarn run check-types", - "test:unit": "TS_NODE_TRANSPILE_ONLY=true mocha 'test/**/*.test.ts'", + "test:unit": "mocha 'test/**/*.test.ts'", "test:browsers": "yarn karma start karma.config.cjs", "check-readme": "typescript-docs-verifier" }, diff --git a/packages/validator/package.json b/packages/validator/package.json index e1cb35298c69..862962a6e02a 100644 --- a/packages/validator/package.json +++ b/packages/validator/package.json @@ -31,8 +31,8 @@ "test:unit": "nyc --cache-dir .nyc_output/.cache -e .ts mocha 'test/unit/**/*.test.ts'", "test": "yarn test:unit", "test:e2e:only": "mocha 'test/e2e/**/*.test.ts'", - "test:spec": "TS_NODE_TRANSPILE_ONLY=true mocha 'test/spec/**/*.test.ts'", - "test:e2e": "TS_NODE_TRANSPILE_ONLY=true LODESTAR_PRESET=minimal yarn run download-spec-tests && yarn test:spec && yarn test:e2e:only", + "test:spec": "mocha 'test/spec/**/*.test.ts'", + "test:e2e": "LODESTAR_PRESET=minimal yarn run download-spec-tests && yarn test:spec && yarn test:e2e:only", "download-spec-tests": "node --loader=ts-node/esm test/spec/downloadTests.ts", "coverage": "codecov -F lodestar-validator", "check-readme": "typescript-docs-verifier" diff --git a/tsconfig.json b/tsconfig.json index 2b57da687efe..069ba3ccd122 100644 --- a/tsconfig.json +++ b/tsconfig.json @@ -8,5 +8,8 @@ "noEmit": true, // To be used in the test fixtures "resolveJsonModule": true + }, + "ts-node": { + "transpileOnly": true } } From 5041b8553d51df6d69a344643bca3bd1d35c4c6e Mon Sep 17 00:00:00 2001 From: Nazar Hussain Date: Wed, 20 Sep 2023 17:35:46 +0200 Subject: [PATCH 24/28] Update tsconfig for the e2e tests --- tsconfig.e2e.json | 3 +++ 1 file changed, 3 insertions(+) diff --git a/tsconfig.e2e.json b/tsconfig.e2e.json index 1432f2311d41..14cdc4bf044b 100644 --- a/tsconfig.e2e.json +++ b/tsconfig.e2e.json @@ -24,5 +24,8 @@ "declarationMap": true, "incremental": true, "preserveWatchOutput": true + }, + "ts-node": { + "transpileOnly": true } } From 7f4b9604e7930e289d4bcf313995e9cd376d4b64 Mon Sep 17 00:00:00 2001 From: Nazar Hussain Date: Wed, 20 Sep 2023 17:40:11 +0200 Subject: [PATCH 25/28] Update the tsconfig for the project --- tsconfig.json | 7 ++++++- 1 file changed, 6 insertions(+), 1 deletion(-) diff --git a/tsconfig.json b/tsconfig.json index 069ba3ccd122..c2cf3e5f258a 100644 --- a/tsconfig.json +++ b/tsconfig.json @@ -7,7 +7,12 @@ "typeRoots": ["node_modules/@types", "./types"], "noEmit": true, // To be used in the test fixtures - "resolveJsonModule": true + "resolveJsonModule": true, + + // We want to speed up the CI run for all tests, which require us to use the + // `transpileOnly` mode for the `ts-node`. This change requires to treat types for each module + // independently, which is done by setting the `isolatedModules` flag to `true`. + "isolatedModules": true, }, "ts-node": { "transpileOnly": true From dd955965c4cd70f0bb5ef2a2a6047c8dcc33a042 Mon Sep 17 00:00:00 2001 From: Nazar Hussain Date: Wed, 20 Sep 2023 18:29:12 +0200 Subject: [PATCH 26/28] Fix the types issue --- packages/api/src/beacon/server/index.ts | 2 +- packages/api/src/builder/index.ts | 2 +- packages/api/src/keymanager/index.ts | 14 ++------------ packages/beacon-node/src/chain/emitter.ts | 2 +- packages/beacon-node/src/util/clock.ts | 2 +- packages/test-utils/src/mocha.ts | 2 +- 6 files changed, 7 insertions(+), 17 deletions(-) diff --git a/packages/api/src/beacon/server/index.ts b/packages/api/src/beacon/server/index.ts index 6c1cc9c16a4b..b1129394ee78 100644 --- a/packages/api/src/beacon/server/index.ts +++ b/packages/api/src/beacon/server/index.ts @@ -17,7 +17,7 @@ import * as validator from "./validator.js"; export {ApiError}; // Re-export for convenience -export {RouteConfig}; +export type {RouteConfig}; export function registerRoutes( server: ServerInstance, diff --git a/packages/api/src/builder/index.ts b/packages/api/src/builder/index.ts index 5d995484ffb6..76100fba2057 100644 --- a/packages/api/src/builder/index.ts +++ b/packages/api/src/builder/index.ts @@ -5,7 +5,7 @@ import * as builder from "./client.js"; // NOTE: Don't export server here so it's not bundled to all consumers -export {Api}; +export type {Api}; // Note: build API does not have namespaces as routes are declared at the "root" namespace diff --git a/packages/api/src/keymanager/index.ts b/packages/api/src/keymanager/index.ts index 4f6b3c1b9985..3232876e2657 100644 --- a/packages/api/src/keymanager/index.ts +++ b/packages/api/src/keymanager/index.ts @@ -6,18 +6,8 @@ import * as keymanager from "./client.js"; // NOTE: Don't export server here so it's not bundled to all consumers -export { - ImportStatus, - DeletionStatus, - ImportRemoteKeyStatus, - DeleteRemoteKeyStatus, - ResponseStatus, - SignerDefinition, - KeystoreStr, - SlashingProtectionData, - PubkeyHex, - Api, -} from "./routes.js"; +export {ImportStatus, DeletionStatus, ImportRemoteKeyStatus, DeleteRemoteKeyStatus} from "./routes.js"; +export type {ResponseStatus, SignerDefinition, KeystoreStr, SlashingProtectionData, PubkeyHex, Api} from "./routes.js"; type ClientModules = HttpClientModules & { config: ChainForkConfig; diff --git a/packages/beacon-node/src/chain/emitter.ts b/packages/beacon-node/src/chain/emitter.ts index 81c38331c84e..8c02064b4a92 100644 --- a/packages/beacon-node/src/chain/emitter.ts +++ b/packages/beacon-node/src/chain/emitter.ts @@ -14,7 +14,7 @@ import {CachedBeaconStateAllForks} from "@lodestar/state-transition"; * - Fork Choice: the chain's fork choice is updated * - Checkpointing: the chain processes epoch boundaries */ -export const enum ChainEvent { +export enum ChainEvent { /** * This event signals that the chain has processed (or reprocessed) a checkpoint. * diff --git a/packages/beacon-node/src/util/clock.ts b/packages/beacon-node/src/util/clock.ts index 2f19a5a8ca6b..82fc04aac727 100644 --- a/packages/beacon-node/src/util/clock.ts +++ b/packages/beacon-node/src/util/clock.ts @@ -6,7 +6,7 @@ import {ErrorAborted} from "@lodestar/utils"; import {computeEpochAtSlot, computeTimeAtSlot, getCurrentSlot} from "@lodestar/state-transition"; import {MAXIMUM_GOSSIP_CLOCK_DISPARITY} from "../constants/constants.js"; -export const enum ClockEvent { +export enum ClockEvent { /** * This event signals the start of a new slot, and that subsequent calls to `clock.currentSlot` will equal `slot`. * This event is guaranteed to be emitted every `SECONDS_PER_SLOT` seconds. diff --git a/packages/test-utils/src/mocha.ts b/packages/test-utils/src/mocha.ts index a469cd373afa..edf8053a60df 100644 --- a/packages/test-utils/src/mocha.ts +++ b/packages/test-utils/src/mocha.ts @@ -1,7 +1,7 @@ import type {Suite} from "mocha"; import {Logger} from "@lodestar/utils"; import {TestContext} from "./interfaces.js"; -export {TestContext} from "./interfaces.js"; +export type {TestContext} from "./interfaces.js"; /** * Create a Mocha context object that can be used to register callbacks that will be executed From b23d74bff543fa7370c8ff871ed91922cf96bd66 Mon Sep 17 00:00:00 2001 From: Nazar Hussain Date: Thu, 21 Sep 2023 16:45:08 +0200 Subject: [PATCH 27/28] Remove unused file --- packages/cli/test/tsconfig.json | 6 ------ 1 file changed, 6 deletions(-) delete mode 100644 packages/cli/test/tsconfig.json diff --git a/packages/cli/test/tsconfig.json b/packages/cli/test/tsconfig.json deleted file mode 100644 index 484405d0e8b8..000000000000 --- a/packages/cli/test/tsconfig.json +++ /dev/null @@ -1,6 +0,0 @@ -{ - "extends": "../tsconfig.json", - "ts-node": { - "transpileOnly": true - } -} From 39afebc9efcca6d4dc7861ae215660350410fe32 Mon Sep 17 00:00:00 2001 From: Nazar Hussain Date: Thu, 21 Sep 2023 18:15:26 +0200 Subject: [PATCH 28/28] Increase the retries for one unstable test --- packages/beacon-node/test/e2e/network/gossipsub.test.ts | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/packages/beacon-node/test/e2e/network/gossipsub.test.ts b/packages/beacon-node/test/e2e/network/gossipsub.test.ts index 49ba6c42d90e..eed9f68cd4ce 100644 --- a/packages/beacon-node/test/e2e/network/gossipsub.test.ts +++ b/packages/beacon-node/test/e2e/network/gossipsub.test.ts @@ -19,7 +19,7 @@ describe("gossipsub / worker", function () { function runTests(this: Mocha.Suite, {useWorker}: {useWorker: boolean}): void { if (this.timeout() < 20 * 1000) this.timeout(150 * 1000); - this.retries(0); // This test fail sometimes, with a 5% rate. + this.retries(2); // This test fail sometimes, with a 5% rate. const afterEachCallbacks: (() => Promise | void)[] = []; afterEach(async () => {