From 7b7c3d84ffeb22985994c49619e2d725a3f0e263 Mon Sep 17 00:00:00 2001 From: Nazar Hussain Date: Wed, 7 Feb 2024 10:58:38 +0100 Subject: [PATCH 01/36] Variables using .env file --- .github/actions/dotenv/action.yml | 5 +++++ .github/actions/dotenv/index.js | 26 ++++++++++++++++++++++++++ .github/workflows/test-sim.yml | 4 +++- test.env | 4 ++++ 4 files changed, 38 insertions(+), 1 deletion(-) create mode 100644 .github/actions/dotenv/action.yml create mode 100644 .github/actions/dotenv/index.js create mode 100644 test.env diff --git a/.github/actions/dotenv/action.yml b/.github/actions/dotenv/action.yml new file mode 100644 index 000000000000..870a8d612d3c --- /dev/null +++ b/.github/actions/dotenv/action.yml @@ -0,0 +1,5 @@ +name: "Setup env variables using .env file" +description: "Load .env file from root of repo and setup for git runner" +runs: + using: "node20" + main: index.js \ No newline at end of file diff --git a/.github/actions/dotenv/index.js b/.github/actions/dotenv/index.js new file mode 100644 index 000000000000..222ddab7a59c --- /dev/null +++ b/.github/actions/dotenv/index.js @@ -0,0 +1,26 @@ +const fs = require("fs"); +const core = require("@actions/core"); +const dotEnv = require("dotenv"); +const envFile = "test.env"; + +if (!fs.existsSync(envFile)) { + core.setFailed("File .env not found"); +} + +const result = dotEnv.config({path: envFile}); +if (result.error) { + core.setFailed(result.error.message); +} else { + core.setOutput("env", result.parsed); + core.info("Env file loaded"); + core.info("Populating env variables}"); + + for (const key in result.parsed) { + const value = result.parsed[key]; + core.setOutput(key, value); + + if (exportVariables) { + core.exportVariable(key, value); + } + } +} diff --git a/.github/workflows/test-sim.yml b/.github/workflows/test-sim.yml index 20eee3d11e77..115b66725f2f 100644 --- a/.github/workflows/test-sim.yml +++ b/.github/workflows/test-sim.yml @@ -24,7 +24,7 @@ on: env: GETH_DOCKER_IMAGE: ethereum/client-go:v1.13.11 - LIGHTHOUSE_DOCKER_IMAGE: sigp/lighthouse:latest-amd64-modern-dev + LIGHTHOUSE_DOCKER_IMAGE: sigp/lighthouse:v4.6.0-amd64-modern-dev NETHERMIND_DOCKER_IMAGE: nethermind/nethermind:1.25.3 jobs: @@ -32,6 +32,8 @@ jobs: name: Sim tests runs-on: buildjet-4vcpu-ubuntu-2204 steps: + - name: Load env variables + uses: ./.github/actions/dotenv # - Uses YAML anchors in the future - uses: actions/checkout@v3 - uses: actions/setup-node@v3 diff --git a/test.env b/test.env new file mode 100644 index 000000000000..4f1937ee7793 --- /dev/null +++ b/test.env @@ -0,0 +1,4 @@ +# We use these images during sim and e2e tests +GETH_DOCKER_IMAGE=ethereum/client-go:v1.13.11 +LIGHTHOUSE_DOCKER_IMAGE=sigp/lighthouse:v4.6.0-amd64-modern-dev +NETHERMIND_DOCKER_IMAGE=nethermind/nethermind:1.25.3 \ No newline at end of file From f31b8a0027f9af008ddd9e868476d103c5df0480 Mon Sep 17 00:00:00 2001 From: Nazar Hussain Date: Wed, 7 Feb 2024 11:02:18 +0100 Subject: [PATCH 02/36] Add env variable support to normal tests --- .github/actions/dotenv/action.yml | 3 ++- .github/workflows/test.yml | 8 +++----- 2 files changed, 5 insertions(+), 6 deletions(-) diff --git a/.github/actions/dotenv/action.yml b/.github/actions/dotenv/action.yml index 870a8d612d3c..5200e41e3e7e 100644 --- a/.github/actions/dotenv/action.yml +++ b/.github/actions/dotenv/action.yml @@ -2,4 +2,5 @@ name: "Setup env variables using .env file" description: "Load .env file from root of repo and setup for git runner" runs: using: "node20" - main: index.js \ No newline at end of file + main: index.js + \ No newline at end of file diff --git a/.github/workflows/test.yml b/.github/workflows/test.yml index d865045c4f3a..45f3eafe9a29 100644 --- a/.github/workflows/test.yml +++ b/.github/workflows/test.yml @@ -11,11 +11,7 @@ on: branches: [unstable, stable] pull_request: workflow_dispatch: - -env: - GETH_DOCKER_IMAGE: ethereum/client-go:v1.11.6 - NETHERMIND_DOCKER_IMAGE: nethermind/nethermind:1.18.0 - + jobs: build: name: Build @@ -25,6 +21,8 @@ jobs: matrix: node: [20] steps: + - name: Load env variables + uses: ./.github/actions/dotenv # - Uses YAML anchors in the future - uses: actions/checkout@v3 - uses: actions/setup-node@v3 From f5f2d07061ed0e469bf6065e30c6e929358e5a15 Mon Sep 17 00:00:00 2001 From: Nazar Hussain Date: Wed, 7 Feb 2024 11:04:02 +0100 Subject: [PATCH 03/36] Fix the order of variables --- .github/workflows/test-sim.yml | 4 ++-- .github/workflows/test.yml | 6 +++--- 2 files changed, 5 insertions(+), 5 deletions(-) diff --git a/.github/workflows/test-sim.yml b/.github/workflows/test-sim.yml index 115b66725f2f..2aab159465ef 100644 --- a/.github/workflows/test-sim.yml +++ b/.github/workflows/test-sim.yml @@ -32,10 +32,10 @@ jobs: name: Sim tests runs-on: buildjet-4vcpu-ubuntu-2204 steps: - - name: Load env variables - uses: ./.github/actions/dotenv # - Uses YAML anchors in the future - uses: actions/checkout@v3 + - name: Load env variables + uses: ./.github/actions/dotenv - uses: actions/setup-node@v3 with: node-version: 20 diff --git a/.github/workflows/test.yml b/.github/workflows/test.yml index 45f3eafe9a29..30ebaef7848f 100644 --- a/.github/workflows/test.yml +++ b/.github/workflows/test.yml @@ -11,7 +11,7 @@ on: branches: [unstable, stable] pull_request: workflow_dispatch: - + jobs: build: name: Build @@ -21,10 +21,10 @@ jobs: matrix: node: [20] steps: - - name: Load env variables - uses: ./.github/actions/dotenv # - Uses YAML anchors in the future - uses: actions/checkout@v3 + - name: Load env variables + uses: ./.github/actions/dotenv - uses: actions/setup-node@v3 with: node-version: ${{matrix.node}} From 9f5e95285159eec18e6ff7fce0c7ecb3684d0585 Mon Sep 17 00:00:00 2001 From: Nazar Hussain Date: Wed, 7 Feb 2024 11:08:59 +0100 Subject: [PATCH 04/36] Update the order of jobs --- .github/workflows/test-sim.yml | 5 +++-- .github/workflows/test.yml | 5 +++-- package.json | 1 + yarn.lock | 8 ++++++++ 4 files changed, 15 insertions(+), 4 deletions(-) diff --git a/.github/workflows/test-sim.yml b/.github/workflows/test-sim.yml index 2aab159465ef..42e61adf4aef 100644 --- a/.github/workflows/test-sim.yml +++ b/.github/workflows/test-sim.yml @@ -34,8 +34,6 @@ jobs: steps: # - Uses YAML anchors in the future - uses: actions/checkout@v3 - - name: Load env variables - uses: ./.github/actions/dotenv - uses: actions/setup-node@v3 with: node-version: 20 @@ -60,6 +58,9 @@ jobs: if: steps.cache-deps.outputs.cache-hit == 'true' # + - name: Load env variables + uses: ./.github/actions/dotenv + - name: Download required docker images before running tests run: | docker pull ${{env.GETH_DOCKER_IMAGE}} diff --git a/.github/workflows/test.yml b/.github/workflows/test.yml index 30ebaef7848f..da5d894f5aae 100644 --- a/.github/workflows/test.yml +++ b/.github/workflows/test.yml @@ -23,8 +23,6 @@ jobs: steps: # - Uses YAML anchors in the future - uses: actions/checkout@v3 - - name: Load env variables - uses: ./.github/actions/dotenv - uses: actions/setup-node@v3 with: node-version: ${{matrix.node}} @@ -223,6 +221,9 @@ jobs: key: ${{ runner.os }}-node-${{ matrix.node }}-${{ github.sha }} fail-on-cache-miss: true + - name: Load env variables + uses: ./.github/actions/dotenv + - name: Run the e2e test environment run: scripts/run_e2e_env.sh start diff --git a/package.json b/package.json index 5d7a90f27e6f..ca54817dead1 100644 --- a/package.json +++ b/package.json @@ -46,6 +46,7 @@ "release:publish": "lerna publish from-package --yes --no-verify-access" }, "devDependencies": { + "@actions/core": "^1.10.1", "@chainsafe/eslint-plugin-node": "^11.2.3", "@dapplion/benchmark": "^0.2.4", "@types/mocha": "^10.0.6", diff --git a/yarn.lock b/yarn.lock index e4059083f9e9..50c7a3ea6c57 100644 --- a/yarn.lock +++ b/yarn.lock @@ -22,6 +22,14 @@ semver "^6.1.0" uuid "^3.3.3" +"@actions/core@^1.10.1": + version "1.10.1" + resolved "https://registry.yarnpkg.com/@actions/core/-/core-1.10.1.tgz#61108e7ac40acae95ee36da074fa5850ca4ced8a" + integrity sha512-3lBR9EDAY+iYIpTnTIXmWcNbX3T2kCkAEQGIQx4NVQ0575nk2k3GRZDTPQG+vVtS2izSLmINlxXf0uLtnrTP+g== + dependencies: + "@actions/http-client" "^2.0.1" + uuid "^8.3.2" + "@actions/core@^1.2.6": version "1.10.0" resolved "https://registry.yarnpkg.com/@actions/core/-/core-1.10.0.tgz#44551c3c71163949a2f06e94d9ca2157a0cfac4f" From 74bff3949c1a12ad0df2f8d7c5083c714d5b8397 Mon Sep 17 00:00:00 2001 From: Nazar Hussain Date: Wed, 7 Feb 2024 11:16:12 +0100 Subject: [PATCH 05/36] Export the varible using actions toolkit --- .github/actions/dotenv/index.js | 5 +---- 1 file changed, 1 insertion(+), 4 deletions(-) diff --git a/.github/actions/dotenv/index.js b/.github/actions/dotenv/index.js index 222ddab7a59c..15426c23192f 100644 --- a/.github/actions/dotenv/index.js +++ b/.github/actions/dotenv/index.js @@ -18,9 +18,6 @@ if (result.error) { for (const key in result.parsed) { const value = result.parsed[key]; core.setOutput(key, value); - - if (exportVariables) { - core.exportVariable(key, value); - } + core.exportVariable(key, value); } } From 960857f106a1b034490485163d0cf5a012403d89 Mon Sep 17 00:00:00 2001 From: Nazar Hussain Date: Wed, 7 Feb 2024 11:24:30 +0100 Subject: [PATCH 06/36] Update the workflow tasks --- .github/actions/dotenv/index.js | 10 ++++++++-- .github/workflows/test-sim.yml | 2 +- 2 files changed, 9 insertions(+), 3 deletions(-) diff --git a/.github/actions/dotenv/index.js b/.github/actions/dotenv/index.js index 15426c23192f..2ae6205c96cf 100644 --- a/.github/actions/dotenv/index.js +++ b/.github/actions/dotenv/index.js @@ -13,11 +13,17 @@ if (result.error) { } else { core.setOutput("env", result.parsed); core.info("Env file loaded"); - core.info("Populating env variables}"); + core.info("Populating env variables..."); for (const key in result.parsed) { const value = result.parsed[key]; - core.setOutput(key, value); + core.info(`${key}=${value}`); + + // Export variable core.exportVariable(key, value); + + // Set to output so it can be used in as the input for the next job/step + core.setOutput(key, value); + } } diff --git a/.github/workflows/test-sim.yml b/.github/workflows/test-sim.yml index 42e61adf4aef..631625b25b04 100644 --- a/.github/workflows/test-sim.yml +++ b/.github/workflows/test-sim.yml @@ -60,7 +60,7 @@ jobs: - name: Load env variables uses: ./.github/actions/dotenv - + - name: Download required docker images before running tests run: | docker pull ${{env.GETH_DOCKER_IMAGE}} From a9cff167d14c086540014585d5b0db2f83ce304b Mon Sep 17 00:00:00 2001 From: Nazar Hussain Date: Wed, 7 Feb 2024 11:31:52 +0100 Subject: [PATCH 07/36] Fix the sim workflow --- .github/workflows/test-sim.yml | 5 ----- 1 file changed, 5 deletions(-) diff --git a/.github/workflows/test-sim.yml b/.github/workflows/test-sim.yml index 631625b25b04..7e0a2aa56a73 100644 --- a/.github/workflows/test-sim.yml +++ b/.github/workflows/test-sim.yml @@ -22,11 +22,6 @@ on: type: number default: 40 -env: - GETH_DOCKER_IMAGE: ethereum/client-go:v1.13.11 - LIGHTHOUSE_DOCKER_IMAGE: sigp/lighthouse:v4.6.0-amd64-modern-dev - NETHERMIND_DOCKER_IMAGE: nethermind/nethermind:1.25.3 - jobs: tests-sim: name: Sim tests From df430e5eff90c4ac67f8f3a4b7dd9927437051f5 Mon Sep 17 00:00:00 2001 From: Nazar Hussain Date: Wed, 7 Feb 2024 18:08:47 +0100 Subject: [PATCH 08/36] Add .env.test file support to tests --- test.env => .env.test | 2 ++ .github/actions/dotenv/index.js | 2 +- CONTRIBUTING.md | 2 +- .../pages/contribution/testing/simulation-tests.md | 14 ++++---------- package.json | 1 + packages/cli/package.json | 10 +++++----- .../utils/simulation/execution_clients/geth.ts | 2 +- scripts/run_e2e_env.sh | 1 + scripts/vitest/{ => setupFiles}/customMatchers.ts | 0 scripts/vitest/setupFiles/dotenv.ts | 7 +++++++ vitest.base.unit.config.ts | 7 +++++-- yarn.lock | 5 +++++ 12 files changed, 33 insertions(+), 20 deletions(-) rename test.env => .env.test (75%) rename scripts/vitest/{ => setupFiles}/customMatchers.ts (100%) create mode 100644 scripts/vitest/setupFiles/dotenv.ts diff --git a/test.env b/.env.test similarity index 75% rename from test.env rename to .env.test index 4f1937ee7793..01282ec50dbc 100644 --- a/test.env +++ b/.env.test @@ -1,4 +1,6 @@ # We use these images during sim and e2e tests GETH_DOCKER_IMAGE=ethereum/client-go:v1.13.11 +# Use either image or local binary for the testing +GETH_BINARY_DIR= LIGHTHOUSE_DOCKER_IMAGE=sigp/lighthouse:v4.6.0-amd64-modern-dev NETHERMIND_DOCKER_IMAGE=nethermind/nethermind:1.25.3 \ No newline at end of file diff --git a/.github/actions/dotenv/index.js b/.github/actions/dotenv/index.js index 2ae6205c96cf..fd7ce8ec2527 100644 --- a/.github/actions/dotenv/index.js +++ b/.github/actions/dotenv/index.js @@ -1,7 +1,7 @@ const fs = require("fs"); const core = require("@actions/core"); const dotEnv = require("dotenv"); -const envFile = "test.env"; +const envFile = ".env.test"; if (!fs.existsSync(envFile)) { core.setFailed("File .env not found"); diff --git a/CONTRIBUTING.md b/CONTRIBUTING.md index 7e567ab517fc..cb4519d51377 100644 --- a/CONTRIBUTING.md +++ b/CONTRIBUTING.md @@ -35,7 +35,7 @@ To run tests: Note that to run `test:e2e`, first ensure that the environment is correctly setup by running the `run_e2e_env.sh` script. ```sh -GETH_DOCKER_IMAGE=ethereum/client-go:v1.11.6 NETHERMIND_DOCKER_IMAGE=nethermind/nethermind:1.18.0 ./scripts/run_e2e_env.sh start +./scripts/run_e2e_env.sh start ``` Similarly, run `yarn download-spec-tests` before running `yarn test:spec`. diff --git a/docs/pages/contribution/testing/simulation-tests.md b/docs/pages/contribution/testing/simulation-tests.md index c1059e5c4177..e8e26ad83468 100644 --- a/docs/pages/contribution/testing/simulation-tests.md +++ b/docs/pages/contribution/testing/simulation-tests.md @@ -12,7 +12,7 @@ There are a number of sim tests that are available and each has a slightly diffe ### Environment Variables -To see what typical values for these are check out the `test-sim.yaml` workflow file in the `.github/workflows` directory. +To see what typical values for these are check out the `.env.test` file in the root directory. - `GETH_DOCKER_IMAGE`: The geth docker image that will be used - `NETHERMIND_IMAGE`: The nethermind docker image that will be used @@ -23,10 +23,7 @@ To see what typical values for these are check out the `test-sim.yaml` workflow The multi-fork sim test checks most of the functionality Lodestar provides. Is verifies that Lodestar is capable of peering, moving through all of the forks and using various sync methods in a testnet environment. Lodestar is tested with both Geth and Nethermind as the execution client. It also checks a Lighthouse/Geth node for cross client compatibility. ```sh -GETH_DOCKER_IMAGE=ethereum/client-go:v1.11.6 \ - LIGHTHOUSE_DOCKER_IMAGE=sigp/lighthouse:latest-amd64-modern-dev \ - NETHERMIND_DOCKER_IMAGE=nethermind/nethermind:1.18.0 \ - yarn workspace @chainsafe/lodestar test:sim:multifork +yarn workspace @chainsafe/lodestar test:sim:multifork ``` ### `test:sim:endpoints` @@ -34,8 +31,7 @@ GETH_DOCKER_IMAGE=ethereum/client-go:v1.11.6 \ This tests that various endpoints of the beacon node and validator client are working as expected. ```sh -GETH_DOCKER_IMAGE=ethereum/client-go:v1.11.6 \ - yarn workspace @chainsafe/lodestar test:sim:endpoints +yarn workspace @chainsafe/lodestar test:sim:endpoints ``` ### `test:sim:deneb` @@ -47,9 +43,7 @@ This test is still included in our CI but is no longer as important as it once w Checks that Lodestar is compatible with other consensus validators and vice-versa. All tests use Geth as the EL. ```sh -GETH_DOCKER_IMAGE=ethereum/client-go:v1.11.6 \ - LIGHTHOUSE_DOCKER_IMAGE=sigp/lighthouse:latest-amd64-modern-dev \ - yarn workspace @chainsafe/lodestar test:sim:mixedclient +yarn workspace @chainsafe/lodestar test:sim:mixedclient ``` ## Sim Test Infrastructure diff --git a/package.json b/package.json index ca54817dead1..15e0469f7223 100644 --- a/package.json +++ b/package.json @@ -57,6 +57,7 @@ "@vitest/browser": "^1.2.1", "codecov": "^3.8.3", "crypto-browserify": "^3.12.0", + "dotenv": "^16.4.1", "electron": "^26.2.2", "eslint": "^8.50.0", "eslint-import-resolver-typescript": "^3.6.1", diff --git a/packages/cli/package.json b/packages/cli/package.json index 1b172087b180..d60fb652bfce 100644 --- a/packages/cli/package.json +++ b/packages/cli/package.json @@ -32,11 +32,11 @@ "lint:fix": "yarn run lint --fix", "test:unit": "vitest --run --dir test/unit/", "test:e2e": "vitest --run --config vitest.e2e.config.ts --dir test/e2e/", - "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", - "test:sim:deneb": "LODESTAR_PRESET=minimal node --loader ts-node/esm test/sim/deneb.test.ts", - "test:sim:backup_eth_provider": "LODESTAR_PRESET=minimal node --loader ts-node/esm test/sim/backup_eth_provider.test.ts", + "test:sim:multifork": "DOTENV_CONFIG_PATH=../../.env.test LODESTAR_PRESET=minimal node -r dotenv/config --loader ts-node/esm test/sim/multi_fork.test.ts", + "test:sim:mixedclient": "DOTENV_CONFIG_PATH=../../.env.test LODESTAR_PRESET=minimal node -r dotenv/config --loader ts-node/esm test/sim/mixed_client.test.ts", + "test:sim:endpoints": "DOTENV_CONFIG_PATH=../../.env.test LODESTAR_PRESET=minimal node -r dotenv/config --loader ts-node/esm test/sim/endpoints.test.ts", + "test:sim:deneb": "DOTENV_CONFIG_PATH=../../.env.test LODESTAR_PRESET=minimal node -r dotenv/config --loader ts-node/esm test/sim/deneb.test.ts", + "test:sim:backup_eth_provider": "DOTENV_CONFIG_PATH=../../.env.test LODESTAR_PRESET=minimal node -r dotenv/config --loader ts-node/esm test/sim/backup_eth_provider.test.ts", "test": "yarn test:unit && yarn test:e2e", "coverage": "codecov -F lodestar", "check-readme": "typescript-docs-verifier" diff --git a/packages/cli/test/utils/simulation/execution_clients/geth.ts b/packages/cli/test/utils/simulation/execution_clients/geth.ts index bb17d1698330..f1ce8fcae384 100644 --- a/packages/cli/test/utils/simulation/execution_clients/geth.ts +++ b/packages/cli/test/utils/simulation/execution_clients/geth.ts @@ -21,7 +21,7 @@ export const generateGethNode: ExecutionNodeGenerator = (o const {id, mode, ttd, address, mining, clientOptions, nodeIndex} = opts; const ports = getNodePorts(nodeIndex); - const isDocker = process.env.GETH_DOCKER_IMAGE !== undefined; + const isDocker = !process.env.GETH_DOCKER_IMAGE; const binaryPath = isDocker ? "" : `${process.env.GETH_BINARY_DIR}/geth`; const {rootDir, rootDirMounted, genesisFilePathMounted, logFilePath, jwtsecretFilePathMounted} = getNodeMountedPaths( opts.paths, diff --git a/scripts/run_e2e_env.sh b/scripts/run_e2e_env.sh index e22b44ae6c00..35dd3b376536 100755 --- a/scripts/run_e2e_env.sh +++ b/scripts/run_e2e_env.sh @@ -3,6 +3,7 @@ function start_app() { mkdir -p test-logs/e2e-test-env export LODESTAR_PRESET=minimal + source ../.env.test nohup node --loader ts-node/esm packages/cli/test/scripts/e2e_test_env.ts > test-logs/e2e-test-env/simulation.out 2>&1 & echo $! > test-logs/e2e-test-env/simulation.pid echo "Wait for the node to be ready" diff --git a/scripts/vitest/customMatchers.ts b/scripts/vitest/setupFiles/customMatchers.ts similarity index 100% rename from scripts/vitest/customMatchers.ts rename to scripts/vitest/setupFiles/customMatchers.ts diff --git a/scripts/vitest/setupFiles/dotenv.ts b/scripts/vitest/setupFiles/dotenv.ts new file mode 100644 index 000000000000..1dafa3b7f8b1 --- /dev/null +++ b/scripts/vitest/setupFiles/dotenv.ts @@ -0,0 +1,7 @@ +import path from "node:path"; +// It's a dev dependency +// eslint-disable-next-line import/no-extraneous-dependencies +import {config} from "dotenv"; +const currentDir = new URL(".", import.meta.url).pathname; + +config({path: path.join(currentDir, "../../../.env.test"), debug: true}); diff --git a/vitest.base.unit.config.ts b/vitest.base.unit.config.ts index b087466fec12..c442c9f01f61 100644 --- a/vitest.base.unit.config.ts +++ b/vitest.base.unit.config.ts @@ -1,6 +1,6 @@ import path from "node:path"; import {defineConfig} from "vitest/config"; -const __dirname = new URL(".", import.meta.url).pathname; +const currentDir = new URL(".", import.meta.url).pathname; export default defineConfig({ test: { @@ -14,7 +14,10 @@ export default defineConfig({ "**/.{idea,git,cache,output,temp}/**", "**/{karma,rollup,webpack,vite,vitest,jest,ava,babel,nyc,cypress,tsup,build}.config.*", ], - setupFiles: [path.join(__dirname, "./scripts/vitest/customMatchers.ts")], + setupFiles: [ + path.join(currentDir, "./scripts/vitest/setupFiles/customMatchers.ts"), + path.join(currentDir, "./scripts/vitest/setupFiles/dotenv.ts"), + ], reporters: ["default", "hanging-process"], coverage: { enabled: process.env.CI === "true", diff --git a/yarn.lock b/yarn.lock index 50c7a3ea6c57..c81eb2e431ff 100644 --- a/yarn.lock +++ b/yarn.lock @@ -5625,6 +5625,11 @@ dotenv-expand@~10.0.0: resolved "https://registry.yarnpkg.com/dotenv-expand/-/dotenv-expand-10.0.0.tgz#12605d00fb0af6d0a592e6558585784032e4ef37" integrity sha512-GopVGCpVS1UKH75VKHGuQFqS1Gusej0z4FyQkPdwjil2gNIv+LNsqBlboOzpJFZKVT95GkCyWJbBSdFEFUWI2A== +dotenv@^16.4.1: + version "16.4.1" + resolved "https://registry.yarnpkg.com/dotenv/-/dotenv-16.4.1.tgz#1d9931f1d3e5d2959350d1250efab299561f7f11" + integrity sha512-CjA3y+Dr3FyFDOAMnxZEGtnW9KBR2M0JvvUtXNW+dYJL5ROWxP9DUHCwgFqpMk0OXCc0ljhaNTr2w/kutYIcHQ== + dotenv@~16.3.1: version "16.3.1" resolved "https://registry.yarnpkg.com/dotenv/-/dotenv-16.3.1.tgz#369034de7d7e5b120972693352a3bf112172cc3e" From 6df8db7fc41229ab85139111516cc593e6619502 Mon Sep 17 00:00:00 2001 From: Nazar Hussain Date: Wed, 7 Feb 2024 18:11:40 +0100 Subject: [PATCH 09/36] Fix the lint --- .env.test | 2 +- .github/actions/dotenv/action.yml | 1 - 2 files changed, 1 insertion(+), 2 deletions(-) diff --git a/.env.test b/.env.test index 01282ec50dbc..2ef552f11f48 100644 --- a/.env.test +++ b/.env.test @@ -3,4 +3,4 @@ GETH_DOCKER_IMAGE=ethereum/client-go:v1.13.11 # Use either image or local binary for the testing GETH_BINARY_DIR= LIGHTHOUSE_DOCKER_IMAGE=sigp/lighthouse:v4.6.0-amd64-modern-dev -NETHERMIND_DOCKER_IMAGE=nethermind/nethermind:1.25.3 \ No newline at end of file +NETHERMIND_DOCKER_IMAGE=nethermind/nethermind:1.25.3 diff --git a/.github/actions/dotenv/action.yml b/.github/actions/dotenv/action.yml index 5200e41e3e7e..5e8542a13ec1 100644 --- a/.github/actions/dotenv/action.yml +++ b/.github/actions/dotenv/action.yml @@ -3,4 +3,3 @@ description: "Load .env file from root of repo and setup for git runner" runs: using: "node20" main: index.js - \ No newline at end of file From b2ea491865f78354b9b6b07396b5e47c35f71ac1 Mon Sep 17 00:00:00 2001 From: Nazar Hussain Date: Thu, 8 Feb 2024 09:44:23 +0100 Subject: [PATCH 10/36] Update the task description --- .github/actions/dotenv/action.yml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/.github/actions/dotenv/action.yml b/.github/actions/dotenv/action.yml index 5e8542a13ec1..88c0f80b02d3 100644 --- a/.github/actions/dotenv/action.yml +++ b/.github/actions/dotenv/action.yml @@ -1,5 +1,5 @@ name: "Setup env variables using .env file" -description: "Load .env file from root of repo and setup for git runner" +description: "Load .env file from root of repo and setup for CI runner" runs: using: "node20" main: index.js From c69eb6a3065f4c8edb8f17fe1afd753d244ff7be Mon Sep 17 00:00:00 2001 From: Nazar Hussain Date: Thu, 8 Feb 2024 11:09:47 +0100 Subject: [PATCH 11/36] Move lodestar preset to env file --- .env.test | 1 + CONTRIBUTING.md | 2 +- packages/beacon-node/package.json | 4 ++-- packages/cli/package.json | 10 +++++----- packages/logger/package.json | 2 +- packages/params/package.json | 2 +- packages/prover/package.json | 2 +- packages/types/package.json | 2 +- scripts/run_e2e_env.sh | 1 - 9 files changed, 13 insertions(+), 13 deletions(-) diff --git a/.env.test b/.env.test index 2ef552f11f48..ddb917ec1b99 100644 --- a/.env.test +++ b/.env.test @@ -4,3 +4,4 @@ GETH_DOCKER_IMAGE=ethereum/client-go:v1.13.11 GETH_BINARY_DIR= LIGHTHOUSE_DOCKER_IMAGE=sigp/lighthouse:v4.6.0-amd64-modern-dev NETHERMIND_DOCKER_IMAGE=nethermind/nethermind:1.25.3 +LODESTAR_PRESET=minimal \ No newline at end of file diff --git a/CONTRIBUTING.md b/CONTRIBUTING.md index cb4519d51377..491ac4f55578 100644 --- a/CONTRIBUTING.md +++ b/CONTRIBUTING.md @@ -66,7 +66,7 @@ If you observe following error running any of the test files that means you are ```sh cd packages/beacon-node -LODESTAR_PRESET=minimal yarn vitest --run --bail 1 --config vitest.spec.config.ts test/spec/presets/sanity.test.ts -t attester_slashing +yarn vitest --run --bail 1 --config vitest.spec.config.ts test/spec/presets/sanity.test.ts -t attester_slashing ``` ## Docker diff --git a/packages/beacon-node/package.json b/packages/beacon-node/package.json index 60955b4c2259..3d91f6af735a 100644 --- a/packages/beacon-node/package.json +++ b/packages/beacon-node/package.json @@ -79,7 +79,7 @@ "test:unit:minimal": "vitest --run --segfaultRetry 3 --dir test/unit/", "test:unit:mainnet": "LODESTAR_PRESET=mainnet vitest --run --dir test/unit-mainnet", "test:unit": "wrapper() { yarn test:unit:minimal $@ && yarn test:unit:mainnet $@; }; wrapper", - "test:e2e": "LODESTAR_PRESET=minimal vitest --run --segfaultRetry 3 --config vitest.e2e.config.ts --dir test/e2e", + "test:e2e": "vitest --run --segfaultRetry 3 --config vitest.e2e.config.ts --dir test/e2e", "test:sim": "vitest --run test/sim/**/*.test.ts", "test:sim:merge-interop": "vitest --run test/sim/merge-interop.test.ts", "test:sim:mergemock": "vitest --run test/sim/mergemock.test.ts", @@ -88,7 +88,7 @@ "download-spec-tests": "node --loader=ts-node/esm test/spec/downloadTests.ts", "test:spec:bls": "vitest --run --config vitest.spec.config.ts --dir test/spec/bls/", "test:spec:general": "vitest --run --config vitest.spec.config.ts --dir test/spec/general/", - "test:spec:minimal": "LODESTAR_PRESET=minimal vitest --run --config vitest.spec.config.ts --dir test/spec/presets/", + "test:spec:minimal": "vitest --run --config vitest.spec.config.ts --dir test/spec/presets/", "test:spec:mainnet": "LODESTAR_PRESET=mainnet vitest --run --config vitest.spec.config.ts --dir test/spec/presets/", "test:spec": "yarn test:spec:bls && yarn test:spec: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 d60fb652bfce..8602ef1b5714 100644 --- a/packages/cli/package.json +++ b/packages/cli/package.json @@ -32,11 +32,11 @@ "lint:fix": "yarn run lint --fix", "test:unit": "vitest --run --dir test/unit/", "test:e2e": "vitest --run --config vitest.e2e.config.ts --dir test/e2e/", - "test:sim:multifork": "DOTENV_CONFIG_PATH=../../.env.test LODESTAR_PRESET=minimal node -r dotenv/config --loader ts-node/esm test/sim/multi_fork.test.ts", - "test:sim:mixedclient": "DOTENV_CONFIG_PATH=../../.env.test LODESTAR_PRESET=minimal node -r dotenv/config --loader ts-node/esm test/sim/mixed_client.test.ts", - "test:sim:endpoints": "DOTENV_CONFIG_PATH=../../.env.test LODESTAR_PRESET=minimal node -r dotenv/config --loader ts-node/esm test/sim/endpoints.test.ts", - "test:sim:deneb": "DOTENV_CONFIG_PATH=../../.env.test LODESTAR_PRESET=minimal node -r dotenv/config --loader ts-node/esm test/sim/deneb.test.ts", - "test:sim:backup_eth_provider": "DOTENV_CONFIG_PATH=../../.env.test LODESTAR_PRESET=minimal node -r dotenv/config --loader ts-node/esm test/sim/backup_eth_provider.test.ts", + "test:sim:multifork": "DOTENV_CONFIG_PATH=../../.env.test node -r dotenv/config --loader ts-node/esm test/sim/multi_fork.test.ts", + "test:sim:mixedclient": "DOTENV_CONFIG_PATH=../../.env.test node -r dotenv/config --loader ts-node/esm test/sim/mixed_client.test.ts", + "test:sim:endpoints": "DOTENV_CONFIG_PATH=../../.env.test node -r dotenv/config --loader ts-node/esm test/sim/endpoints.test.ts", + "test:sim:deneb": "DOTENV_CONFIG_PATH=../../.env.test node -r dotenv/config --loader ts-node/esm test/sim/deneb.test.ts", + "test:sim:backup_eth_provider": "DOTENV_CONFIG_PATH=../../.env.test node -r dotenv/config --loader ts-node/esm test/sim/backup_eth_provider.test.ts", "test": "yarn test:unit && yarn test:e2e", "coverage": "codecov -F lodestar", "check-readme": "typescript-docs-verifier" diff --git a/packages/logger/package.json b/packages/logger/package.json index e8d32622ae95..beba4312d56a 100644 --- a/packages/logger/package.json +++ b/packages/logger/package.json @@ -61,7 +61,7 @@ "test:browsers:chrome": "vitest --run --browser chrome --config ./vitest.browser.config.ts --dir test/unit", "test:browsers:firefox": "vitest --run --browser firefox --config ./vitest.browser.config.ts --dir test/unit", "test:browsers:electron": "echo 'Electron tests will be introduced back in the future as soon vitest supports electron.'", - "test:e2e": "LODESTAR_PRESET=minimal vitest --run --config vitest.e2e.config.ts --dir test/e2e", + "test:e2e": "vitest --run --config vitest.e2e.config.ts --dir test/e2e", "check-readme": "typescript-docs-verifier" }, "types": "lib/index.d.ts", diff --git a/packages/params/package.json b/packages/params/package.json index bd5259c4712d..b9aecd745e9b 100644 --- a/packages/params/package.json +++ b/packages/params/package.json @@ -58,7 +58,7 @@ "test:browsers:chrome": "vitest --run --browser chrome --config ./vitest.browser.config.ts --dir test/unit", "test:browsers:firefox": "vitest --run --browser firefox --config ./vitest.browser.config.ts --dir test/unit", "test:browsers:electron": "echo 'Electron tests will be introduced back in the future as soon vitest supports electron.'", - "test:e2e": "LODESTAR_PRESET=minimal vitest --run --config vitest.e2e.config.ts --dir test/e2e/", + "test:e2e": "vitest --run --config vitest.e2e.config.ts --dir test/e2e/", "check-readme": "typescript-docs-verifier" }, "repository": { diff --git a/packages/prover/package.json b/packages/prover/package.json index efeace5dfb65..93767e5f4f50 100644 --- a/packages/prover/package.json +++ b/packages/prover/package.json @@ -57,7 +57,7 @@ "test:browsers:chrome": "vitest --run --browser chrome --config ./vitest.browser.config.ts --dir test/unit", "test:browsers:firefox": "vitest --run --browser firefox --config ./vitest.browser.config.ts --dir test/unit", "test:browsers:electron": "echo 'Electron tests will be introduced back in the future as soon vitest supports electron.'", - "test:e2e": "LODESTAR_PRESET=minimal vitest --run --config vitest.e2e.config.ts --dir test/e2e", + "test:e2e": "vitest --run --config vitest.e2e.config.ts --dir test/e2e", "check-readme": "typescript-docs-verifier", "generate-fixtures": "node --loader ts-node/esm scripts/generate_fixtures.ts" }, diff --git a/packages/types/package.json b/packages/types/package.json index 51baccc89314..7076099fa8ab 100644 --- a/packages/types/package.json +++ b/packages/types/package.json @@ -62,7 +62,7 @@ "lint": "eslint --color --ext .ts src/ test/", "lint:fix": "yarn run lint --fix", "test": "yarn test:unit", - "test:constants:minimal": "LODESTAR_PRESET=minimal vitest --run --dir test/constants/", + "test:constants:minimal": "vitest --run --dir test/constants/", "test:constants:mainnet": "LODESTAR_PRESET=mainnet vitest --run --dir test/constants/", "test:unit": "wrapper() { yarn test:constants:minimal $@ && yarn test:constants:mainnet $@ && vitest --run --dir test/unit/ $@; }; wrapper", "test:browsers": "yarn test:browsers:chrome && yarn test:browsers:firefox && yarn test:browsers:electron", diff --git a/scripts/run_e2e_env.sh b/scripts/run_e2e_env.sh index 35dd3b376536..abbe53868df8 100755 --- a/scripts/run_e2e_env.sh +++ b/scripts/run_e2e_env.sh @@ -2,7 +2,6 @@ function start_app() { mkdir -p test-logs/e2e-test-env - export LODESTAR_PRESET=minimal source ../.env.test nohup node --loader ts-node/esm packages/cli/test/scripts/e2e_test_env.ts > test-logs/e2e-test-env/simulation.out 2>&1 & echo $! > test-logs/e2e-test-env/simulation.pid From b3972b640c5f7e7912d1affbf2be413ca7460cf2 Mon Sep 17 00:00:00 2001 From: Nazar Hussain Date: Thu, 8 Feb 2024 11:34:44 +0100 Subject: [PATCH 12/36] Fix the directory path --- scripts/vitest/setupFiles/dotenv.ts | 5 +++-- vitest.base.unit.config.ts | 6 +++--- 2 files changed, 6 insertions(+), 5 deletions(-) diff --git a/scripts/vitest/setupFiles/dotenv.ts b/scripts/vitest/setupFiles/dotenv.ts index 1dafa3b7f8b1..71364c7426bc 100644 --- a/scripts/vitest/setupFiles/dotenv.ts +++ b/scripts/vitest/setupFiles/dotenv.ts @@ -2,6 +2,7 @@ import path from "node:path"; // It's a dev dependency // eslint-disable-next-line import/no-extraneous-dependencies import {config} from "dotenv"; -const currentDir = new URL(".", import.meta.url).pathname; +// eslint-disable-next-line @typescript-eslint/naming-convention +const __dirname = new URL(".", import.meta.url).pathname; -config({path: path.join(currentDir, "../../../.env.test"), debug: true}); +config({path: path.join(__dirname, "../../../.env.test")}); diff --git a/vitest.base.unit.config.ts b/vitest.base.unit.config.ts index c442c9f01f61..293b29214239 100644 --- a/vitest.base.unit.config.ts +++ b/vitest.base.unit.config.ts @@ -1,6 +1,6 @@ import path from "node:path"; import {defineConfig} from "vitest/config"; -const currentDir = new URL(".", import.meta.url).pathname; +const __dirname = new URL(".", import.meta.url).pathname; export default defineConfig({ test: { @@ -15,8 +15,8 @@ export default defineConfig({ "**/{karma,rollup,webpack,vite,vitest,jest,ava,babel,nyc,cypress,tsup,build}.config.*", ], setupFiles: [ - path.join(currentDir, "./scripts/vitest/setupFiles/customMatchers.ts"), - path.join(currentDir, "./scripts/vitest/setupFiles/dotenv.ts"), + path.join(__dirname, "./scripts/vitest/setupFiles/customMatchers.ts"), + path.join(__dirname, "./scripts/vitest/setupFiles/dotenv.ts"), ], reporters: ["default", "hanging-process"], coverage: { From 13a6e40d451834638cc5fe316d6c6945fadfd18a Mon Sep 17 00:00:00 2001 From: Nico Flaig Date: Thu, 8 Feb 2024 11:39:42 +0100 Subject: [PATCH 13/36] newline --- .env.test | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/.env.test b/.env.test index ddb917ec1b99..91d77499d6fb 100644 --- a/.env.test +++ b/.env.test @@ -4,4 +4,4 @@ GETH_DOCKER_IMAGE=ethereum/client-go:v1.13.11 GETH_BINARY_DIR= LIGHTHOUSE_DOCKER_IMAGE=sigp/lighthouse:v4.6.0-amd64-modern-dev NETHERMIND_DOCKER_IMAGE=nethermind/nethermind:1.25.3 -LODESTAR_PRESET=minimal \ No newline at end of file +LODESTAR_PRESET=minimal From 3a2a2e3b3d700ffc416ac26f4d9483fc8e833f68 Mon Sep 17 00:00:00 2001 From: Nico Flaig Date: Thu, 8 Feb 2024 12:20:59 +0100 Subject: [PATCH 14/36] Update debugging spec tests section --- CONTRIBUTING.md | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/CONTRIBUTING.md b/CONTRIBUTING.md index 491ac4f55578..444ce33d0042 100644 --- a/CONTRIBUTING.md +++ b/CONTRIBUTING.md @@ -63,9 +63,9 @@ If you observe following error running any of the test files that means you are - Spec tests often compare full expected vs actual states in JSON format. - A single logical error can cause many spec tests to fail. To focus on a single test at a time you can use vitest's option `--bail 1` to stop at the first failed test - To then run only that failed test you can run against a specific file as use vitest's filters option `-t ` to run only one case +- Before running the tests, make sure to switch to the package directory (e.g. `packages/beacon-node`) to speed up test execution ```sh -cd packages/beacon-node yarn vitest --run --bail 1 --config vitest.spec.config.ts test/spec/presets/sanity.test.ts -t attester_slashing ``` From 254ab1ed14fdf639a83b21dfa11364f5aeb05e6d Mon Sep 17 00:00:00 2001 From: Nazar Hussain Date: Thu, 8 Feb 2024 12:34:46 +0100 Subject: [PATCH 15/36] Update the env variable for preset --- .env.test | 3 ++- package.json | 2 +- packages/beacon-node/package.json | 10 +++++----- packages/cli/package.json | 10 +++++----- packages/types/package.json | 6 +++--- packages/validator/package.json | 2 +- 6 files changed, 17 insertions(+), 16 deletions(-) diff --git a/.env.test b/.env.test index ddb917ec1b99..6b1f4957ca69 100644 --- a/.env.test +++ b/.env.test @@ -4,4 +4,5 @@ GETH_DOCKER_IMAGE=ethereum/client-go:v1.13.11 GETH_BINARY_DIR= LIGHTHOUSE_DOCKER_IMAGE=sigp/lighthouse:v4.6.0-amd64-modern-dev NETHERMIND_DOCKER_IMAGE=nethermind/nethermind:1.25.3 -LODESTAR_PRESET=minimal \ No newline at end of file +# We mostly use mainnet for unit testsing +LODESTAR_PRESET=mainnet \ No newline at end of file diff --git a/package.json b/package.json index 15e0469f7223..25e06ef9d3ac 100644 --- a/package.json +++ b/package.json @@ -39,7 +39,7 @@ "test-coverage:e2e-sim": "c8 --config .c8rc.json --report-dir coverage/e2e-sim/ --all npm run test:e2e:sim", "test-coverage:spec": "c8 --config .c8rc.json --report-dir coverage/spec/ --all npm run test:spec", "benchmark": "yarn benchmark:files 'packages/*/test/perf/**/*.test.ts'", - "benchmark:files": "LODESTAR_PRESET=mainnet NODE_OPTIONS='--max-old-space-size=4096 --loader=ts-node/esm' benchmark --config .benchrc.yaml --defaultBranch unstable", + "benchmark:files": "NODE_OPTIONS='--max-old-space-size=4096 --loader=ts-node/esm' benchmark --config .benchrc.yaml --defaultBranch unstable", "release:create-rc": "node scripts/release/create_rc.mjs", "release:tag-rc": "node scripts/release/tag_rc.mjs", "release:tag-stable": "node scripts/release/tag_stable.mjs", diff --git a/packages/beacon-node/package.json b/packages/beacon-node/package.json index 3d91f6af735a..401d3595148b 100644 --- a/packages/beacon-node/package.json +++ b/packages/beacon-node/package.json @@ -76,9 +76,9 @@ "lint": "eslint --color --ext .ts src/ test/", "lint:fix": "yarn run lint --fix", "test": "yarn test:unit && yarn test:e2e", - "test:unit:minimal": "vitest --run --segfaultRetry 3 --dir test/unit/", - "test:unit:mainnet": "LODESTAR_PRESET=mainnet vitest --run --dir test/unit-mainnet", - "test:unit": "wrapper() { yarn test:unit:minimal $@ && yarn test:unit:mainnet $@; }; wrapper", + "test:unit:minimal": "LODESTAR_PRESET=minimal vitest --run --segfaultRetry 3 --dir test/unit/", + "test:unit:mainnet": "vitest --run --segfaultRetry 3 --dir test/unit-mainnet", + "test:unit": "LODESTAR_PRESET=minimal yarn test:unit:minimal && LODESTAR_PRESET=mainnet yarn test:unit:mainnet", "test:e2e": "vitest --run --segfaultRetry 3 --config vitest.e2e.config.ts --dir test/e2e", "test:sim": "vitest --run test/sim/**/*.test.ts", "test:sim:merge-interop": "vitest --run test/sim/merge-interop.test.ts", @@ -88,8 +88,8 @@ "download-spec-tests": "node --loader=ts-node/esm test/spec/downloadTests.ts", "test:spec:bls": "vitest --run --config vitest.spec.config.ts --dir test/spec/bls/", "test:spec:general": "vitest --run --config vitest.spec.config.ts --dir test/spec/general/", - "test:spec:minimal": "vitest --run --config vitest.spec.config.ts --dir test/spec/presets/", - "test:spec:mainnet": "LODESTAR_PRESET=mainnet vitest --run --config vitest.spec.config.ts --dir test/spec/presets/", + "test:spec:minimal": "LODESTAR_PRESET=minimal vitest --run --config vitest.spec.config.ts --dir test/spec/presets/", + "test:spec:mainnet": "vitest --run --config vitest.spec.config.ts --dir test/spec/presets/", "test:spec": "yarn test:spec:bls && yarn test:spec: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 8602ef1b5714..78f2d8a37eca 100644 --- a/packages/cli/package.json +++ b/packages/cli/package.json @@ -32,11 +32,11 @@ "lint:fix": "yarn run lint --fix", "test:unit": "vitest --run --dir test/unit/", "test:e2e": "vitest --run --config vitest.e2e.config.ts --dir test/e2e/", - "test:sim:multifork": "DOTENV_CONFIG_PATH=../../.env.test node -r dotenv/config --loader ts-node/esm test/sim/multi_fork.test.ts", - "test:sim:mixedclient": "DOTENV_CONFIG_PATH=../../.env.test node -r dotenv/config --loader ts-node/esm test/sim/mixed_client.test.ts", - "test:sim:endpoints": "DOTENV_CONFIG_PATH=../../.env.test node -r dotenv/config --loader ts-node/esm test/sim/endpoints.test.ts", - "test:sim:deneb": "DOTENV_CONFIG_PATH=../../.env.test node -r dotenv/config --loader ts-node/esm test/sim/deneb.test.ts", - "test:sim:backup_eth_provider": "DOTENV_CONFIG_PATH=../../.env.test node -r dotenv/config --loader ts-node/esm test/sim/backup_eth_provider.test.ts", + "test:sim:multifork": "LODESTAR_PRESET=minimal DOTENV_CONFIG_PATH=../../.env.test node -r dotenv/config --loader ts-node/esm test/sim/multi_fork.test.ts", + "test:sim:mixedclient": "LODESTAR_PRESET=minimal DOTENV_CONFIG_PATH=../../.env.test node -r dotenv/config --loader ts-node/esm test/sim/mixed_client.test.ts", + "test:sim:endpoints": "LODESTAR_PRESET=minimal DOTENV_CONFIG_PATH=../../.env.test node -r dotenv/config --loader ts-node/esm test/sim/endpoints.test.ts", + "test:sim:deneb": "LODESTAR_PRESET=minimal DOTENV_CONFIG_PATH=../../.env.test node -r dotenv/config --loader ts-node/esm test/sim/deneb.test.ts", + "test:sim:backup_eth_provider": "LODESTAR_PRESET=minimal DOTENV_CONFIG_PATH=../../.env.test node -r dotenv/config --loader ts-node/esm test/sim/backup_eth_provider.test.ts", "test": "yarn test:unit && yarn test:e2e", "coverage": "codecov -F lodestar", "check-readme": "typescript-docs-verifier" diff --git a/packages/types/package.json b/packages/types/package.json index 7076099fa8ab..2423a4b96a2d 100644 --- a/packages/types/package.json +++ b/packages/types/package.json @@ -62,9 +62,9 @@ "lint": "eslint --color --ext .ts src/ test/", "lint:fix": "yarn run lint --fix", "test": "yarn test:unit", - "test:constants:minimal": "vitest --run --dir test/constants/", - "test:constants:mainnet": "LODESTAR_PRESET=mainnet vitest --run --dir test/constants/", - "test:unit": "wrapper() { yarn test:constants:minimal $@ && yarn test:constants:mainnet $@ && vitest --run --dir test/unit/ $@; }; wrapper", + "test:constants:minimal": "LODESTAR_PRESET=minimal vitest --run --dir test/constants/", + "test:constants:mainnet": "vitest --run --dir test/constants/", + "test:unit": "LODESTAR_PRESET=minimal yarn test:constants:minimal && yarn test:constants:mainnet && vitest --run --dir test/unit/", "test:browsers": "yarn test:browsers:chrome && yarn test:browsers:firefox && yarn test:browsers:electron", "test:browsers:chrome": "vitest --run --browser chrome --config ./vitest.browser.config.ts --dir test/unit", "test:browsers:firefox": "vitest --run --browser firefox --config ./vitest.browser.config.ts --dir test/unit", diff --git a/packages/validator/package.json b/packages/validator/package.json index 5b913ad84a63..1865001d0dc3 100644 --- a/packages/validator/package.json +++ b/packages/validator/package.json @@ -30,7 +30,7 @@ "test:unit": "vitest --run --dir test/unit/", "test": "yarn test:unit && yarn test:e2e", "test:spec": "vitest --run --config vitest.spec.config.ts --dir test/spec/", - "test:e2e": "LODESTAR_PRESET=mainnet vitest --run --config vitest.e2e.config.ts --dir test/e2e", + "test:e2e": "vitest --run --config vitest.e2e.config.ts --dir test/e2e", "download-spec-tests": "node --loader=ts-node/esm test/spec/downloadTests.ts", "coverage": "codecov -F lodestar-validator", "check-readme": "typescript-docs-verifier" From 1a3b46202b664ed7915c3bf27c44bc3ea45143d1 Mon Sep 17 00:00:00 2001 From: Nazar Hussain Date: Thu, 8 Feb 2024 12:50:22 +0100 Subject: [PATCH 16/36] Fix the path for setup files --- vitest.base.browser.config.ts | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/vitest.base.browser.config.ts b/vitest.base.browser.config.ts index 5559e0f77b9c..a07f4d842b06 100644 --- a/vitest.base.browser.config.ts +++ b/vitest.base.browser.config.ts @@ -24,7 +24,7 @@ export default defineConfig({ "**/.{idea,git,cache,output,temp}/**", "**/{karma,rollup,webpack,vite,vitest,jest,ava,babel,nyc,cypress,tsup,build}.config.*", ], - setupFiles: [path.join(__dirname, "./scripts/vitest/customMatchers.ts")], + setupFiles: [path.join(__dirname, "./scripts/vitest/setupFiles/customMatchers.ts")], reporters: ["default", "hanging-process"], coverage: { enabled: false, From 570073d2e55689333eca6bede899597a453f9d66 Mon Sep 17 00:00:00 2001 From: Nazar Hussain Date: Thu, 8 Feb 2024 14:23:40 +0100 Subject: [PATCH 17/36] Update code as per feedback --- .env.test | 2 +- packages/beacon-node/package.json | 2 +- packages/types/package.json | 2 +- 3 files changed, 3 insertions(+), 3 deletions(-) diff --git a/.env.test b/.env.test index e5ff99609bbe..d9e81a91f070 100644 --- a/.env.test +++ b/.env.test @@ -4,5 +4,5 @@ GETH_DOCKER_IMAGE=ethereum/client-go:v1.13.11 GETH_BINARY_DIR= LIGHTHOUSE_DOCKER_IMAGE=sigp/lighthouse:v4.6.0-amd64-modern-dev NETHERMIND_DOCKER_IMAGE=nethermind/nethermind:1.25.3 -# We mostly use mainnet for unit testsing +# We mostly use mainnet for unit testing LODESTAR_PRESET=mainnet diff --git a/packages/beacon-node/package.json b/packages/beacon-node/package.json index 401d3595148b..e0530edd136b 100644 --- a/packages/beacon-node/package.json +++ b/packages/beacon-node/package.json @@ -78,7 +78,7 @@ "test": "yarn test:unit && yarn test:e2e", "test:unit:minimal": "LODESTAR_PRESET=minimal vitest --run --segfaultRetry 3 --dir test/unit/", "test:unit:mainnet": "vitest --run --segfaultRetry 3 --dir test/unit-mainnet", - "test:unit": "LODESTAR_PRESET=minimal yarn test:unit:minimal && LODESTAR_PRESET=mainnet yarn test:unit:mainnet", + "test:unit": "wrapper() { LODESTAR_PRESET=minimal yarn test:unit:minimal $@ && LODESTAR_PRESET=mainnet yarn test:unit:mainnet $@; }; wrapper", "test:e2e": "vitest --run --segfaultRetry 3 --config vitest.e2e.config.ts --dir test/e2e", "test:sim": "vitest --run test/sim/**/*.test.ts", "test:sim:merge-interop": "vitest --run test/sim/merge-interop.test.ts", diff --git a/packages/types/package.json b/packages/types/package.json index 2423a4b96a2d..0c367fe6b245 100644 --- a/packages/types/package.json +++ b/packages/types/package.json @@ -64,7 +64,7 @@ "test": "yarn test:unit", "test:constants:minimal": "LODESTAR_PRESET=minimal vitest --run --dir test/constants/", "test:constants:mainnet": "vitest --run --dir test/constants/", - "test:unit": "LODESTAR_PRESET=minimal yarn test:constants:minimal && yarn test:constants:mainnet && vitest --run --dir test/unit/", + "test:unit": "wrapper() {LODESTAR_PRESET=minimal yarn test:constants:minimal $@ && LODESTAR_PRESET=mainnet yarn test:constants:mainnet $@ && LODESTAR_PRESET=mainnet vitest --run --dir test/unit/ $@; }; wrapper", "test:browsers": "yarn test:browsers:chrome && yarn test:browsers:firefox && yarn test:browsers:electron", "test:browsers:chrome": "vitest --run --browser chrome --config ./vitest.browser.config.ts --dir test/unit", "test:browsers:firefox": "vitest --run --browser firefox --config ./vitest.browser.config.ts --dir test/unit", From a652a8e20e871e8d91a03705eca89409f46f3264 Mon Sep 17 00:00:00 2001 From: Nazar Hussain Date: Thu, 8 Feb 2024 14:24:31 +0100 Subject: [PATCH 18/36] Fix the e2e variables --- scripts/run_e2e_env.sh | 1 + 1 file changed, 1 insertion(+) diff --git a/scripts/run_e2e_env.sh b/scripts/run_e2e_env.sh index abbe53868df8..2e472181da17 100755 --- a/scripts/run_e2e_env.sh +++ b/scripts/run_e2e_env.sh @@ -3,6 +3,7 @@ function start_app() { mkdir -p test-logs/e2e-test-env source ../.env.test + export LODESTAR_PRESET=minimal nohup node --loader ts-node/esm packages/cli/test/scripts/e2e_test_env.ts > test-logs/e2e-test-env/simulation.out 2>&1 & echo $! > test-logs/e2e-test-env/simulation.pid echo "Wait for the node to be ready" From 7b48e142899c44cf5fc5a5ea272fadbde7b1c0b5 Mon Sep 17 00:00:00 2001 From: Nazar Hussain Date: Thu, 8 Feb 2024 14:25:18 +0100 Subject: [PATCH 19/36] Update doc --- CONTRIBUTING.md | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/CONTRIBUTING.md b/CONTRIBUTING.md index 444ce33d0042..009eaa850367 100644 --- a/CONTRIBUTING.md +++ b/CONTRIBUTING.md @@ -66,7 +66,7 @@ If you observe following error running any of the test files that means you are - Before running the tests, make sure to switch to the package directory (e.g. `packages/beacon-node`) to speed up test execution ```sh -yarn vitest --run --bail 1 --config vitest.spec.config.ts test/spec/presets/sanity.test.ts -t attester_slashing +LODESTAR_PRESET=minimal yarn vitest --run --bail 1 --config vitest.spec.config.ts test/spec/presets/sanity.test.ts -t attester_slashing ``` ## Docker From e90f2fbb6934bd452bb3481b545136b9487d7ab5 Mon Sep 17 00:00:00 2001 From: Nazar Hussain Date: Thu, 8 Feb 2024 14:40:30 +0100 Subject: [PATCH 20/36] Fix the bash script --- packages/types/package.json | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/packages/types/package.json b/packages/types/package.json index 0c367fe6b245..8d2f15ba2e60 100644 --- a/packages/types/package.json +++ b/packages/types/package.json @@ -64,7 +64,7 @@ "test": "yarn test:unit", "test:constants:minimal": "LODESTAR_PRESET=minimal vitest --run --dir test/constants/", "test:constants:mainnet": "vitest --run --dir test/constants/", - "test:unit": "wrapper() {LODESTAR_PRESET=minimal yarn test:constants:minimal $@ && LODESTAR_PRESET=mainnet yarn test:constants:mainnet $@ && LODESTAR_PRESET=mainnet vitest --run --dir test/unit/ $@; }; wrapper", + "test:unit": "wrapper() { LODESTAR_PRESET=minimal yarn test:constants:minimal $@ && LODESTAR_PRESET=mainnet yarn test:constants:mainnet $@ && LODESTAR_PRESET=mainnet vitest --run --dir test/unit/ $@; }; wrapper", "test:browsers": "yarn test:browsers:chrome && yarn test:browsers:firefox && yarn test:browsers:electron", "test:browsers:chrome": "vitest --run --browser chrome --config ./vitest.browser.config.ts --dir test/unit", "test:browsers:firefox": "vitest --run --browser firefox --config ./vitest.browser.config.ts --dir test/unit", From 6feebc4e9e06ab18a71b05e3b3c1c9ca5d1ab824 Mon Sep 17 00:00:00 2001 From: Nazar Hussain Date: Thu, 8 Feb 2024 15:14:40 +0100 Subject: [PATCH 21/36] Fix sim geth runne --- packages/cli/test/utils/simulation/execution_clients/geth.ts | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/packages/cli/test/utils/simulation/execution_clients/geth.ts b/packages/cli/test/utils/simulation/execution_clients/geth.ts index f1ce8fcae384..2ed9a2a91e1c 100644 --- a/packages/cli/test/utils/simulation/execution_clients/geth.ts +++ b/packages/cli/test/utils/simulation/execution_clients/geth.ts @@ -21,7 +21,7 @@ export const generateGethNode: ExecutionNodeGenerator = (o const {id, mode, ttd, address, mining, clientOptions, nodeIndex} = opts; const ports = getNodePorts(nodeIndex); - const isDocker = !process.env.GETH_DOCKER_IMAGE; + const isDocker = !!process.env.GETH_DOCKER_IMAGE; const binaryPath = isDocker ? "" : `${process.env.GETH_BINARY_DIR}/geth`; const {rootDir, rootDirMounted, genesisFilePathMounted, logFilePath, jwtsecretFilePathMounted} = getNodeMountedPaths( opts.paths, From f1df354cafee8c9b10ce568505564671291c5a2c Mon Sep 17 00:00:00 2001 From: Nazar Hussain Date: Thu, 8 Feb 2024 15:25:04 +0100 Subject: [PATCH 22/36] Update the env file --- .env.test | 1 + 1 file changed, 1 insertion(+) diff --git a/.env.test b/.env.test index d9e81a91f070..12543c7a8954 100644 --- a/.env.test +++ b/.env.test @@ -5,4 +5,5 @@ GETH_BINARY_DIR= LIGHTHOUSE_DOCKER_IMAGE=sigp/lighthouse:v4.6.0-amd64-modern-dev NETHERMIND_DOCKER_IMAGE=nethermind/nethermind:1.25.3 # We mostly use mainnet for unit testing +# Changing this value may impact the tests which are written with mainnet in mind LODESTAR_PRESET=mainnet From ba14c9bf8249a8cf310bb69c787d940ec37d4948 Mon Sep 17 00:00:00 2001 From: Nazar Hussain Date: Thu, 8 Feb 2024 15:30:37 +0100 Subject: [PATCH 23/36] Fix e2e tests --- packages/params/test/e2e/overridePreset.test.ts | 3 +-- packages/params/test/e2e/setPreset.test.ts | 3 +-- 2 files changed, 2 insertions(+), 4 deletions(-) diff --git a/packages/params/test/e2e/overridePreset.test.ts b/packages/params/test/e2e/overridePreset.test.ts index 16f29f3c5c84..8aae85937eb4 100644 --- a/packages/params/test/e2e/overridePreset.test.ts +++ b/packages/params/test/e2e/overridePreset.test.ts @@ -21,8 +21,7 @@ describe("Override preset", function () { vi.setConfig({testTimeout: 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; + if (process.env.LODESTAR_PRESET) 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 aa1371fa2eea..b9fa71553e9a 100644 --- a/packages/params/test/e2e/setPreset.test.ts +++ b/packages/params/test/e2e/setPreset.test.ts @@ -21,8 +21,7 @@ describe("setPreset", function () { vi.setConfig({testTimeout: 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; + if (process.env.LODESTAR_PRESET) delete process.env.LODESTAR_PRESET; await exec(`node --loader ts-node/esm ${path.join(__dirname, scriptNames.ok)}`); }); From b8e6d312e2323994532b28da00cab7e9d96cab9f Mon Sep 17 00:00:00 2001 From: Nazar Hussain Date: Thu, 8 Feb 2024 15:41:30 +0100 Subject: [PATCH 24/36] Update the script tasks --- packages/beacon-node/package.json | 6 +++--- packages/types/package.json | 4 ++-- 2 files changed, 5 insertions(+), 5 deletions(-) diff --git a/packages/beacon-node/package.json b/packages/beacon-node/package.json index e0530edd136b..5c50e89ba591 100644 --- a/packages/beacon-node/package.json +++ b/packages/beacon-node/package.json @@ -77,8 +77,8 @@ "lint:fix": "yarn run lint --fix", "test": "yarn test:unit && yarn test:e2e", "test:unit:minimal": "LODESTAR_PRESET=minimal vitest --run --segfaultRetry 3 --dir test/unit/", - "test:unit:mainnet": "vitest --run --segfaultRetry 3 --dir test/unit-mainnet", - "test:unit": "wrapper() { LODESTAR_PRESET=minimal yarn test:unit:minimal $@ && LODESTAR_PRESET=mainnet yarn test:unit:mainnet $@; }; wrapper", + "test:unit:mainnet": "LODESTAR_PRESET=mainnet vitest --run --segfaultRetry 3 --dir test/unit-mainnet", + "test:unit": "wrapper() { yarn test:unit:minimal $@ && yarn test:unit:mainnet $@; }; wrapper", "test:e2e": "vitest --run --segfaultRetry 3 --config vitest.e2e.config.ts --dir test/e2e", "test:sim": "vitest --run test/sim/**/*.test.ts", "test:sim:merge-interop": "vitest --run test/sim/merge-interop.test.ts", @@ -89,7 +89,7 @@ "test:spec:bls": "vitest --run --config vitest.spec.config.ts --dir test/spec/bls/", "test:spec:general": "vitest --run --config vitest.spec.config.ts --dir test/spec/general/", "test:spec:minimal": "LODESTAR_PRESET=minimal vitest --run --config vitest.spec.config.ts --dir test/spec/presets/", - "test:spec:mainnet": "vitest --run --config vitest.spec.config.ts --dir test/spec/presets/", + "test:spec:mainnet": "LODESTAR_PRESET=mainnet vitest --run --config vitest.spec.config.ts --dir test/spec/presets/", "test:spec": "yarn test:spec:bls && yarn test:spec:general && yarn test:spec:minimal && yarn test:spec:mainnet", "check-readme": "typescript-docs-verifier" }, diff --git a/packages/types/package.json b/packages/types/package.json index 8d2f15ba2e60..51baccc89314 100644 --- a/packages/types/package.json +++ b/packages/types/package.json @@ -63,8 +63,8 @@ "lint:fix": "yarn run lint --fix", "test": "yarn test:unit", "test:constants:minimal": "LODESTAR_PRESET=minimal vitest --run --dir test/constants/", - "test:constants:mainnet": "vitest --run --dir test/constants/", - "test:unit": "wrapper() { LODESTAR_PRESET=minimal yarn test:constants:minimal $@ && LODESTAR_PRESET=mainnet yarn test:constants:mainnet $@ && LODESTAR_PRESET=mainnet vitest --run --dir test/unit/ $@; }; wrapper", + "test:constants:mainnet": "LODESTAR_PRESET=mainnet vitest --run --dir test/constants/", + "test:unit": "wrapper() { yarn test:constants:minimal $@ && yarn test:constants:mainnet $@ && vitest --run --dir test/unit/ $@; }; wrapper", "test:browsers": "yarn test:browsers:chrome && yarn test:browsers:firefox && yarn test:browsers:electron", "test:browsers:chrome": "vitest --run --browser chrome --config ./vitest.browser.config.ts --dir test/unit", "test:browsers:firefox": "vitest --run --browser firefox --config ./vitest.browser.config.ts --dir test/unit", From a9cc9c72ee23b6dba2d632e18c234f8c75ce5a24 Mon Sep 17 00:00:00 2001 From: Nazar Hussain Date: Thu, 8 Feb 2024 15:42:28 +0100 Subject: [PATCH 25/36] Update the script tasks --- packages/types/package.json | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/packages/types/package.json b/packages/types/package.json index 51baccc89314..f01b7a15a17a 100644 --- a/packages/types/package.json +++ b/packages/types/package.json @@ -64,7 +64,7 @@ "test": "yarn test:unit", "test:constants:minimal": "LODESTAR_PRESET=minimal vitest --run --dir test/constants/", "test:constants:mainnet": "LODESTAR_PRESET=mainnet vitest --run --dir test/constants/", - "test:unit": "wrapper() { yarn test:constants:minimal $@ && yarn test:constants:mainnet $@ && vitest --run --dir test/unit/ $@; }; wrapper", + "test:unit": "wrapper() { yarn test:constants:minimal $@ && yarn test:constants:mainnet $@ && LODESTAR_PRESET=mainnet vitest --run --dir test/unit/ $@; }; wrapper", "test:browsers": "yarn test:browsers:chrome && yarn test:browsers:firefox && yarn test:browsers:electron", "test:browsers:chrome": "vitest --run --browser chrome --config ./vitest.browser.config.ts --dir test/unit", "test:browsers:firefox": "vitest --run --browser firefox --config ./vitest.browser.config.ts --dir test/unit", From 6586b7da010ec51c7197695ff3ce625a3d8901b9 Mon Sep 17 00:00:00 2001 From: Nazar Hussain Date: Thu, 8 Feb 2024 16:57:34 +0100 Subject: [PATCH 26/36] Add minimal 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 5c50e89ba591..61e5fcd3df56 100644 --- a/packages/beacon-node/package.json +++ b/packages/beacon-node/package.json @@ -79,7 +79,7 @@ "test:unit:minimal": "LODESTAR_PRESET=minimal vitest --run --segfaultRetry 3 --dir test/unit/", "test:unit:mainnet": "LODESTAR_PRESET=mainnet vitest --run --segfaultRetry 3 --dir test/unit-mainnet", "test:unit": "wrapper() { yarn test:unit:minimal $@ && yarn test:unit:mainnet $@; }; wrapper", - "test:e2e": "vitest --run --segfaultRetry 3 --config vitest.e2e.config.ts --dir test/e2e", + "test:e2e": "LODESTAR_PRESET=minimal vitest --run --segfaultRetry 3 --config vitest.e2e.config.ts --dir test/e2e", "test:sim": "vitest --run test/sim/**/*.test.ts", "test:sim:merge-interop": "vitest --run test/sim/merge-interop.test.ts", "test:sim:mergemock": "vitest --run test/sim/mergemock.test.ts", From b7eff8529a8586ad7429478a291a416a44ce53cf Mon Sep 17 00:00:00 2001 From: Nazar Hussain Date: Thu, 8 Feb 2024 17:19:00 +0100 Subject: [PATCH 27/36] Add minimal for e2e tests --- packages/prover/package.json | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/packages/prover/package.json b/packages/prover/package.json index 93767e5f4f50..efeace5dfb65 100644 --- a/packages/prover/package.json +++ b/packages/prover/package.json @@ -57,7 +57,7 @@ "test:browsers:chrome": "vitest --run --browser chrome --config ./vitest.browser.config.ts --dir test/unit", "test:browsers:firefox": "vitest --run --browser firefox --config ./vitest.browser.config.ts --dir test/unit", "test:browsers:electron": "echo 'Electron tests will be introduced back in the future as soon vitest supports electron.'", - "test:e2e": "vitest --run --config vitest.e2e.config.ts --dir test/e2e", + "test:e2e": "LODESTAR_PRESET=minimal vitest --run --config vitest.e2e.config.ts --dir test/e2e", "check-readme": "typescript-docs-verifier", "generate-fixtures": "node --loader ts-node/esm scripts/generate_fixtures.ts" }, From 26a4c36ae16434f0cb16ce991116f567aa09a38d Mon Sep 17 00:00:00 2001 From: Nico Flaig Date: Fri, 9 Feb 2024 11:03:36 +0100 Subject: [PATCH 28/36] Update comments in preset tests --- packages/params/test/e2e/overridePreset.test.ts | 1 + packages/params/test/e2e/setPreset.test.ts | 1 + 2 files changed, 2 insertions(+) diff --git a/packages/params/test/e2e/overridePreset.test.ts b/packages/params/test/e2e/overridePreset.test.ts index 8aae85937eb4..24995cbaa042 100644 --- a/packages/params/test/e2e/overridePreset.test.ts +++ b/packages/params/test/e2e/overridePreset.test.ts @@ -21,6 +21,7 @@ describe("Override preset", function () { vi.setConfig({testTimeout: 30_000}); it("Should correctly override preset", async () => { + // `LODESTAR_PRESET` must not be set to properly test preset override if (process.env.LODESTAR_PRESET) 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 b9fa71553e9a..844239d56bab 100644 --- a/packages/params/test/e2e/setPreset.test.ts +++ b/packages/params/test/e2e/setPreset.test.ts @@ -21,6 +21,7 @@ describe("setPreset", function () { vi.setConfig({testTimeout: 30_000}); it("Should correctly set preset", async () => { + // `LODESTAR_PRESET` must not be set to properly test setting preset if (process.env.LODESTAR_PRESET) delete process.env.LODESTAR_PRESET; await exec(`node --loader ts-node/esm ${path.join(__dirname, scriptNames.ok)}`); From 8cf47b311b359adb96d653a6a4f4917b78a407a2 Mon Sep 17 00:00:00 2001 From: Nazar Hussain Date: Fri, 9 Feb 2024 20:44:54 +0100 Subject: [PATCH 29/36] Downgrade nethermind version --- .env.test | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/.env.test b/.env.test index 12543c7a8954..76a1cacf1449 100644 --- a/.env.test +++ b/.env.test @@ -3,7 +3,8 @@ GETH_DOCKER_IMAGE=ethereum/client-go:v1.13.11 # Use either image or local binary for the testing GETH_BINARY_DIR= LIGHTHOUSE_DOCKER_IMAGE=sigp/lighthouse:v4.6.0-amd64-modern-dev -NETHERMIND_DOCKER_IMAGE=nethermind/nethermind:1.25.3 +# We can't upgrade nethermind further due to genesis hash mismatch with the geth +NETHERMIND_DOCKER_IMAGE=nethermind/nethermind:1.18.2 # We mostly use mainnet for unit testing # Changing this value may impact the tests which are written with mainnet in mind LODESTAR_PRESET=mainnet From 8333ceac1e1c301e8b3dca9ea1dc9901d107513a Mon Sep 17 00:00:00 2001 From: Nazar Hussain Date: Fri, 9 Feb 2024 20:47:41 +0100 Subject: [PATCH 30/36] Load env file in e2e env --- packages/cli/test/scripts/e2e_test_env.ts | 1 + scripts/run_e2e_env.sh | 10 +++++----- 2 files changed, 6 insertions(+), 5 deletions(-) diff --git a/packages/cli/test/scripts/e2e_test_env.ts b/packages/cli/test/scripts/e2e_test_env.ts index b35b3524d8cf..b5fa48260194 100644 --- a/packages/cli/test/scripts/e2e_test_env.ts +++ b/packages/cli/test/scripts/e2e_test_env.ts @@ -14,6 +14,7 @@ const {forkConfig} = defineSimTestConfig({ BELLATRIX_FORK_EPOCH: bellatrixForkEpoch, CAPELLA_FORK_EPOCH: capellaForkEpoch, runTillEpoch: Infinity, + initialNodes: 2, }); const env = await SimulationEnvironment.initWithDefaults( diff --git a/scripts/run_e2e_env.sh b/scripts/run_e2e_env.sh index 2e472181da17..9d12ae449c2a 100755 --- a/scripts/run_e2e_env.sh +++ b/scripts/run_e2e_env.sh @@ -1,19 +1,19 @@ #!/bin/bash +DIR=$(dirname "$0") + function start_app() { mkdir -p test-logs/e2e-test-env - source ../.env.test export LODESTAR_PRESET=minimal - nohup node --loader ts-node/esm packages/cli/test/scripts/e2e_test_env.ts > test-logs/e2e-test-env/simulation.out 2>&1 & + export DOTENV_CONFIG_PATH="$DIR/../.env.test" + nohup node -r dotenv/config --loader ts-node/esm packages/cli/test/scripts/e2e_test_env.ts > test-logs/e2e-test-env/simulation.out 2>&1 & echo $! > test-logs/e2e-test-env/simulation.pid echo "Wait for the node to be ready" npx wait-port -t 120000 0.0.0.0:5001 } function stop_app() { - kill -9 $(cat test-logs/e2e-test-env/simulation.pid) - # Incase the process pid file is not present - kill -9 $(lsof -t -i:5001) + kill -s TERM $(cat test-logs/e2e-test-env/simulation.pid) } From 53c4a154b1f00d7d5a5d7544f8d63640ac3b0e25 Mon Sep 17 00:00:00 2001 From: Nazar Hussain Date: Sat, 10 Feb 2024 15:24:19 +0100 Subject: [PATCH 31/36] Add the issue link in env variable --- .env.test | 1 + 1 file changed, 1 insertion(+) diff --git a/.env.test b/.env.test index 76a1cacf1449..391fff4fdd4a 100644 --- a/.env.test +++ b/.env.test @@ -4,6 +4,7 @@ GETH_DOCKER_IMAGE=ethereum/client-go:v1.13.11 GETH_BINARY_DIR= LIGHTHOUSE_DOCKER_IMAGE=sigp/lighthouse:v4.6.0-amd64-modern-dev # We can't upgrade nethermind further due to genesis hash mismatch with the geth +# https://github.com/NethermindEth/nethermind/issues/6683 NETHERMIND_DOCKER_IMAGE=nethermind/nethermind:1.18.2 # We mostly use mainnet for unit testing # Changing this value may impact the tests which are written with mainnet in mind From b74d8a3e92ebfbf07f33dc3baf84b603f3a4efa0 Mon Sep 17 00:00:00 2001 From: Nazar Hussain Date: Sat, 10 Feb 2024 15:24:46 +0100 Subject: [PATCH 32/36] Update bash script for failsafe current dir --- scripts/run_e2e_env.sh | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/scripts/run_e2e_env.sh b/scripts/run_e2e_env.sh index 9d12ae449c2a..e81eb501f407 100755 --- a/scripts/run_e2e_env.sh +++ b/scripts/run_e2e_env.sh @@ -1,6 +1,6 @@ #!/bin/bash -DIR=$(dirname "$0") +DIR="$(CDPATH= cd "$(dirname "${BASH_SOURCE[0]}")" && pwd)" function start_app() { mkdir -p test-logs/e2e-test-env From 0d1416bec3f2301262febe4ecc0720217aabf43a Mon Sep 17 00:00:00 2001 From: Nazar Hussain Date: Sat, 10 Feb 2024 15:25:40 +0100 Subject: [PATCH 33/36] Fix the mistaken genesis extension for el nodes --- packages/cli/test/utils/simulation/utils/paths.ts | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/packages/cli/test/utils/simulation/utils/paths.ts b/packages/cli/test/utils/simulation/utils/paths.ts index 0a7ffb716dd1..9f0628e34656 100644 --- a/packages/cli/test/utils/simulation/utils/paths.ts +++ b/packages/cli/test/utils/simulation/utils/paths.ts @@ -23,7 +23,7 @@ export function getNodePaths< return { rootDir: executionRootDir, dataDir: path.join(executionRootDir, "data"), - genesisFilePath: path.join(executionRootDir, "genesis.ssz"), + genesisFilePath: path.join(executionRootDir, "genesis.json"), jwtsecretFilePath: path.join(executionRootDir, "jwtsecret.txt"), logFilePath: path.join(logsDir, `${id}-${client}.log`), } as R; From 76960f771899a0662cb6b236ecf3406c55bd2557 Mon Sep 17 00:00:00 2001 From: Nazar Hussain Date: Sat, 10 Feb 2024 15:27:00 +0100 Subject: [PATCH 34/36] Add missing capella wait for one test --- packages/prover/test/e2e/web3_batch_request.test.ts | 6 ++++-- 1 file changed, 4 insertions(+), 2 deletions(-) diff --git a/packages/prover/test/e2e/web3_batch_request.test.ts b/packages/prover/test/e2e/web3_batch_request.test.ts index afb995d088a0..89ac4a711b31 100644 --- a/packages/prover/test/e2e/web3_batch_request.test.ts +++ b/packages/prover/test/e2e/web3_batch_request.test.ts @@ -3,14 +3,16 @@ import {describe, it, expect, beforeAll} from "vitest"; import Web3 from "web3"; import {LCTransport} from "../../src/interfaces.js"; import {createVerifiedExecutionProvider} from "../../src/web3_provider.js"; -import {rpcUrl, beaconUrl, config} from "../utils/e2e_env.js"; +import {rpcUrl, beaconUrl, config, waitForCapellaFork} from "../utils/e2e_env.js"; import {getVerificationFailedMessage} from "../../src/utils/json_rpc.js"; /* prettier-ignore */ describe("web3_batch_requests", function () { let web3: Web3; - beforeAll(() => { + beforeAll(async () => { + await waitForCapellaFork(); + const {provider} = createVerifiedExecutionProvider(new Web3.providers.HttpProvider(rpcUrl), { transport: LCTransport.Rest, urls: [beaconUrl], From 6b3522dd1549f2a2c0c0c74c22bc5ad176426be6 Mon Sep 17 00:00:00 2001 From: Nazar Hussain Date: Mon, 12 Feb 2024 12:34:14 +0100 Subject: [PATCH 35/36] Downgrade the geth version --- .env.test | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/.env.test b/.env.test index 391fff4fdd4a..f37b0176180a 100644 --- a/.env.test +++ b/.env.test @@ -1,5 +1,7 @@ # We use these images during sim and e2e tests -GETH_DOCKER_IMAGE=ethereum/client-go:v1.13.11 +# TODO: Upgrade Geth once the Nethermind issue is reosolved else it's causing follorwing error +# Rejected peer id=134e2c1a76745626 addr=192.168.0.3:9052 conn=staticdial err="useless peer" +GETH_DOCKER_IMAGE=ethereum/client-go:v1.11.6 # Use either image or local binary for the testing GETH_BINARY_DIR= LIGHTHOUSE_DOCKER_IMAGE=sigp/lighthouse:v4.6.0-amd64-modern-dev From 3b2142e526ae188e7d0dcb76eebe2acc8841a9bf Mon Sep 17 00:00:00 2001 From: Nico Flaig Date: Mon, 12 Feb 2024 13:00:56 +0100 Subject: [PATCH 36/36] Update .env.test --- .env.test | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/.env.test b/.env.test index f37b0176180a..31222f7549cb 100644 --- a/.env.test +++ b/.env.test @@ -1,5 +1,5 @@ # We use these images during sim and e2e tests -# TODO: Upgrade Geth once the Nethermind issue is reosolved else it's causing follorwing error +# TODO: Upgrade Geth once the Nethermind issue is resolved else it's causing following error # Rejected peer id=134e2c1a76745626 addr=192.168.0.3:9052 conn=staticdial err="useless peer" GETH_DOCKER_IMAGE=ethereum/client-go:v1.11.6 # Use either image or local binary for the testing