Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

test: support .env.test to reuse env variables across the tests #6408

Merged
merged 38 commits into from
Feb 12, 2024
Merged
Show file tree
Hide file tree
Changes from 9 commits
Commits
Show all changes
38 commits
Select commit Hold shift + click to select a range
7b7c3d8
Variables using .env file
nazarhussain Feb 7, 2024
f31b8a0
Add env variable support to normal tests
nazarhussain Feb 7, 2024
f5f2d07
Fix the order of variables
nazarhussain Feb 7, 2024
9f5e952
Update the order of jobs
nazarhussain Feb 7, 2024
74bff39
Export the varible using actions toolkit
nazarhussain Feb 7, 2024
960857f
Update the workflow tasks
nazarhussain Feb 7, 2024
a9cff16
Fix the sim workflow
nazarhussain Feb 7, 2024
df430e5
Add .env.test file support to tests
nazarhussain Feb 7, 2024
6df8db7
Fix the lint
nazarhussain Feb 7, 2024
b2ea491
Update the task description
nazarhussain Feb 8, 2024
c69eb6a
Move lodestar preset to env file
nazarhussain Feb 8, 2024
b3972b6
Fix the directory path
nazarhussain Feb 8, 2024
13a6e40
newline
nflaig Feb 8, 2024
3a2a2e3
Update debugging spec tests section
nflaig Feb 8, 2024
254ab1e
Update the env variable for preset
nazarhussain Feb 8, 2024
d9f3e6c
Merge branch 'nh/share-env-variables' of github.com:ChainSafe/lodesta…
nazarhussain Feb 8, 2024
1a3b462
Fix the path for setup files
nazarhussain Feb 8, 2024
570073d
Update code as per feedback
nazarhussain Feb 8, 2024
a652a8e
Fix the e2e variables
nazarhussain Feb 8, 2024
7b48e14
Update doc
nazarhussain Feb 8, 2024
e90f2fb
Fix the bash script
nazarhussain Feb 8, 2024
6feebc4
Fix sim geth runne
nazarhussain Feb 8, 2024
f1df354
Update the env file
nazarhussain Feb 8, 2024
ba14c9b
Fix e2e tests
nazarhussain Feb 8, 2024
b8e6d31
Update the script tasks
nazarhussain Feb 8, 2024
a9cc9c7
Update the script tasks
nazarhussain Feb 8, 2024
6586b7d
Add minimal for e2e tests
nazarhussain Feb 8, 2024
b7eff85
Add minimal for e2e tests
nazarhussain Feb 8, 2024
26a4c36
Update comments in preset tests
nflaig Feb 9, 2024
8cf47b3
Downgrade nethermind version
nazarhussain Feb 9, 2024
c96a5f2
Merge branch 'nh/share-env-variables' of github.com:ChainSafe/lodesta…
nazarhussain Feb 9, 2024
8333cea
Load env file in e2e env
nazarhussain Feb 9, 2024
53c4a15
Add the issue link in env variable
nazarhussain Feb 10, 2024
b74d8a3
Update bash script for failsafe current dir
nazarhussain Feb 10, 2024
0d1416b
Fix the mistaken genesis extension for el nodes
nazarhussain Feb 10, 2024
76960f7
Add missing capella wait for one test
nazarhussain Feb 10, 2024
6b3522d
Downgrade the geth version
nazarhussain Feb 12, 2024
3b2142e
Update .env.test
nflaig Feb 12, 2024
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 6 additions & 0 deletions .env.test
Original file line number Diff line number Diff line change
@@ -0,0 +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
5 changes: 5 additions & 0 deletions .github/actions/dotenv/action.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
name: "Setup env variables using .env file"
description: "Load .env file from root of repo and setup for git runner"
nflaig marked this conversation as resolved.
Show resolved Hide resolved
runs:
using: "node20"
main: index.js
29 changes: 29 additions & 0 deletions .github/actions/dotenv/index.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,29 @@
const fs = require("fs");
const core = require("@actions/core");
const dotEnv = require("dotenv");
const envFile = ".env.test";

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.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);

}
}
8 changes: 3 additions & 5 deletions .github/workflows/test-sim.yml
Original file line number Diff line number Diff line change
Expand Up @@ -22,11 +22,6 @@ on:
type: number
default: 40

env:
GETH_DOCKER_IMAGE: ethereum/client-go:v1.13.11
LIGHTHOUSE_DOCKER_IMAGE: sigp/lighthouse:latest-amd64-modern-dev
NETHERMIND_DOCKER_IMAGE: nethermind/nethermind:1.25.3

jobs:
tests-sim:
name: Sim tests
Expand Down Expand Up @@ -58,6 +53,9 @@ jobs:
if: steps.cache-deps.outputs.cache-hit == 'true'
# </common-build>

- name: Load env variables
uses: ./.github/actions/dotenv

- name: Download required docker images before running tests
run: |
docker pull ${{env.GETH_DOCKER_IMAGE}}
Expand Down
7 changes: 3 additions & 4 deletions .github/workflows/test.yml
Original file line number Diff line number Diff line change
Expand Up @@ -12,10 +12,6 @@ on:
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
Expand Down Expand Up @@ -225,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

Expand Down
2 changes: 1 addition & 1 deletion CONTRIBUTING.md
Original file line number Diff line number Diff line change
Expand Up @@ -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`.
Expand Down
14 changes: 4 additions & 10 deletions docs/pages/contribution/testing/simulation-tests.md
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -23,19 +23,15 @@ 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`

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`
Expand All @@ -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
Expand Down
2 changes: 2 additions & 0 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -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",
Expand All @@ -56,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",
Expand Down
10 changes: 5 additions & 5 deletions packages/cli/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -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",
Copy link
Member

Choose a reason for hiding this comment

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

should LODESTAR_PRESET go into the .env?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Yes we can add that there as well. Need to check if any other test file depend on other preset.

Copy link
Member

Choose a reason for hiding this comment

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

Ok. Then let's definitely move that so we are using one pattern (ie and env file)

"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"
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@ export const generateGethNode: ExecutionNodeGenerator<ExecutionClient.Geth> = (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,
Expand Down
1 change: 1 addition & 0 deletions scripts/run_e2e_env.sh
Original file line number Diff line number Diff line change
Expand Up @@ -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"
Expand Down
7 changes: 7 additions & 0 deletions scripts/vitest/setupFiles/dotenv.ts
Original file line number Diff line number Diff line change
@@ -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});
7 changes: 5 additions & 2 deletions vitest.base.unit.config.ts
Original file line number Diff line number Diff line change
@@ -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;
Copy link
Member

@matthewkeil matthewkeil Feb 7, 2024

Choose a reason for hiding this comment

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

I’m partial to leaving this as __dirname. I dont feel strongly about it but it’s sort of the “node way” to name that

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Yes I had that initially as __dirname here and other places as well, but feel like a old pattern now.

Copy link
Member

Choose a reason for hiding this comment

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

For consistency with the rest of the codebase __dirname is better, but no strong opinion here


export default defineConfig({
test: {
Expand All @@ -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",
Expand Down
13 changes: 13 additions & 0 deletions yarn.lock
Original file line number Diff line number Diff line change
Expand Up @@ -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"
Expand Down Expand Up @@ -5617,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"
Expand Down
Loading