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

hardhat e2e for dsm v3 #266

Open
wants to merge 61 commits into
base: develop
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from 7 commits
Commits
Show all changes
61 commits
Select commit Hold shift + click to select a range
926a294
feat: use hardhat in v3 tests, kapi image
Amuhar Oct 3, 2024
1ed914f
fix: e2e chain agnostic
Amuhar Oct 25, 2024
709ed3c
fix: tests
Amuhar Oct 28, 2024
2531ce4
fix: tests work on mainnet
Amuhar Oct 29, 2024
177dc96
fix: remove unused constants
Amuhar Oct 30, 2024
eddc11b
Merge pull request #268 from lidofinance/feat/val-1135-e2e-chain-agno…
Amuhar Oct 30, 2024
9f39751
fix: refactoring
Amuhar Oct 31, 2024
e618a0f
fix: run containers with use of dockerode with dockerode
Amuhar Nov 5, 2024
d90a05a
fix: removed log
Amuhar Nov 6, 2024
a98da23
fix: config
Amuhar Nov 6, 2024
3e3b85e
fix: removed deps
Amuhar Nov 6, 2024
ef22721
fix: small refactoring
Amuhar Nov 7, 2024
28fd7d6
Merge branch 'develop' into feat/val-1135-e2e-impr
Amuhar Nov 7, 2024
f091e32
fix: node version up
Amuhar Nov 7, 2024
03efa46
fix: lint
Amuhar Nov 7, 2024
ffd7cae
fix: constants
Amuhar Nov 7, 2024
4e46fa1
fix: increase timeout
Amuhar Nov 7, 2024
5724340
fix: container waiting
Amuhar Nov 7, 2024
805677a
fix: pull images in workflow
Amuhar Nov 7, 2024
e398e53
fix: ip instead of host
Amuhar Nov 7, 2024
40ae678
fix: networkMode: host
Amuhar Nov 7, 2024
89245ca
fix: stdout of containers
Amuhar Nov 7, 2024
4d5709b
fix: chain id
Amuhar Nov 7, 2024
5344ecc
fix: host of psql
Amuhar Nov 7, 2024
9491894
fix: revert hosts
Amuhar Nov 7, 2024
d88a20b
fix: provider url
Amuhar Nov 7, 2024
01d0e72
fix: hardhat url
Amuhar Nov 7, 2024
3aa728e
fix: add ExtraHosts
Amuhar Nov 7, 2024
ed7b628
fix: add ExtraHosts
Amuhar Nov 7, 2024
66a62e9
fix: run hardhat on 0.0.0.0
eddort Nov 7, 2024
a5a97da
debug: network mode
eddort Nov 7, 2024
4d46abd
Merge pull request #272 from lidofinance/feat/val-1135-e2e-impr-ci
Amuhar Nov 7, 2024
39724a6
fix: timeout
Amuhar Nov 7, 2024
dd7ed7c
fix: add err
Amuhar Nov 8, 2024
c06274e
fix: kapi
Amuhar Nov 8, 2024
115ac94
fix: enable other duplicates tests
Amuhar Nov 8, 2024
002e9ea
fix: enable invalid-keys-v3 tests
Amuhar Nov 8, 2024
184599e
fix: add logs to hardhat
Amuhar Nov 8, 2024
d9324c1
fix: hardhat kill
Amuhar Nov 8, 2024
91c05e0
fix: check port
Amuhar Nov 8, 2024
0777e7b
fix: check port
Amuhar Nov 8, 2024
573c253
fix: check port
Amuhar Nov 8, 2024
7b9dc8b
fix: enable front-run tests
Amuhar Nov 8, 2024
0ac5029
fix: ebable front-run tests
Amuhar Nov 8, 2024
07b51ee
fix: read envs from config
Amuhar Nov 8, 2024
5d4a537
fix: read envs from config
Amuhar Nov 8, 2024
71f0ab7
feat: separated ci jobs
eddort Nov 8, 2024
95253ba
fix: chain config
eddort Nov 8, 2024
1d3d9ba
feat: run tests in parallel
eddort Nov 8, 2024
dd083d6
Merge pull request #273 from lidofinance/feat/val-1135-e2e-impr-ci-au…
Amuhar Nov 8, 2024
1703eaf
fix: enable tests
Amuhar Nov 11, 2024
6ae3d29
fix: local test run on macos
Amuhar Nov 25, 2024
e7be612
removes unnecessary code
Amuhar Nov 25, 2024
3324225
fix: data bus tests on hardhat
Amuhar Nov 26, 2024
ff4c269
fix: unit tests workflow
Amuhar Nov 26, 2024
c0e39ec
fix: add locator env for unit tests workflow
Amuhar Nov 26, 2024
17d72f7
fix: temp disable e2e
Amuhar Nov 26, 2024
3d115ed
fix: enable e2e workflow
Amuhar Nov 26, 2024
7efcc63
fix: connect to hardhat
Amuhar Nov 27, 2024
a768ee3
fix: removed unnecessary comments
Amuhar Nov 27, 2024
3d5c79f
fix: port name
Amuhar Nov 27, 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
12 changes: 12 additions & 0 deletions Dockerfile.hardhat.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
FROM node:18.14.2

WORKDIR /app

COPY hardhat.config.ts ./hardhat.config.ts
COPY package.json ./package.json
COPY yarn.lock ./yarn.lock

RUN npm install -g hardhat


CMD ["npx", "hardhat", "node"]
64 changes: 64 additions & 0 deletions docker-compose.e2e-v3.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,64 @@
version: '3.7'

services:
e2e_pgdb:
container_name: e2e_pgdb
image: postgres:14-alpine
restart: unless-stopped
environment:
- POSTGRES_DB=node_operator_keys_service_db
- POSTGRES_USER=postgres
- POSTGRES_PASSWORD=postgres
expose:
- "5432:5432"
ports:
- "5433:5432"
volumes:
- ./.volumes/pgdata-17000/:/var/lib/postgresql/data
healthcheck:
test: ["CMD-SHELL", "pg_isready -U postgres"]
interval: 5s
timeout: 5s
retries: 5

hardhat_node:
container_name: hardhat_node
build:
context: .
dockerfile: Dockerfile.hardhat.yml
ports:
- "8545:8545"
environment:
- FORK_URL=${FORK_URL}
- FORK_BLOCK=${FORK_BLOCK}
- WALLET_PRIVATE_KEY=${WALLET_PRIVATE_KEY}
volumes:
- .:/app
healthcheck:
test: ["CMD-SHELL", "curl -s http://127.0.0.1:8545 >/dev/null || exit 1"]
interval: 10s
retries: 10

e2e_keys_api:
container_name: e2e_keys_api
image: lidofinance/lido-keys-api:staging
platform: linux/amd64
environment:
- NODE_ENV=production
- DB_NAME=node_operator_keys_service_db
- DB_PORT=5432
- DB_HOST=e2e_pgdb
- DB_USER=postgres
- DB_PASSWORD=postgres
- PROVIDERS_URLS=http://hardhat_node:8545
- VALIDATOR_REGISTRY_ENABLE=false
- CHAIN_ID=${CHAIN_ID}
- CL_API_URLS=""
depends_on:
e2e_pgdb:
condition: service_healthy
ports:
- "3000:3000"

links:
- e2e_pgdb
30 changes: 30 additions & 0 deletions hardhat.config.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,30 @@
import { HardhatUserConfig } from 'hardhat/config';
import * as dotenv from 'dotenv';
dotenv.config();

// eslint-disable-next-line @typescript-eslint/no-non-null-assertion
const RPC_URL = process.env.FORK_URL!;
// eslint-disable-next-line @typescript-eslint/no-non-null-assertion
const secretKey = process.env.WALLET_PRIVATE_KEY!;
const CHAIN_ID = process.env.CHAIN_ID!;
// TODO: read chain from RPC_URL

const config: HardhatUserConfig = {
networks: {
hardhat: {
forking: {
url: RPC_URL,
},
chainId: Number(CHAIN_ID),
accounts: [
{
privateKey: secretKey,
balance: (BigInt(1e18) * BigInt(100)).toString(),
},
],
},
},
solidity: '0.8.4',
};

export default config;
9 changes: 8 additions & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -66,7 +66,9 @@
"@nestjs/cli": "^8.2.5",
"@nestjs/schematics": "^8.0.0",
"@nestjs/testing": "^8.0.11",
"@nomicfoundation/hardhat-ethers": "^3.0.6",
"@typechain/ethers-v5": "^7.1.2",
"@typechain/hardhat": "^9.1.0",
"@types/app-root-path": "^1.2.4",
"@types/cache-manager": "^3.4.3",
"@types/glob": "^8.1.0",
Expand All @@ -77,19 +79,24 @@
"@types/ws": "^8.5.3",
"@typescript-eslint/eslint-plugin": "^4.28.2",
"@typescript-eslint/parser": "^4.28.2",
"concurrently": "^9.0.1",
"docker-compose": "^1.1.0",
"eslint": "^7.30.0",
"eslint-config-prettier": "^8.3.0",
"eslint-plugin-prettier": "^3.4.0",
"ganache": "7.9.0",
"hardhat": "^2.22.14",
"jest": "^27.0.6",
"pg": "^8.13.0",
"prettier": "^2.3.2",
"supertest": "^6.1.3",
"ts-jest": "^27.0.3",
"ts-loader": "^9.2.3",
"ts-node": "^10.0.0",
"tsconfig-paths": "^3.10.1",
"typechain": "^5.1.2",
"typescript": "^4.3.5"
"typescript": "^4.3.5",
"wait-on": "^8.0.1"
},
"jest": {
"moduleFileExtensions": [
Expand Down
26 changes: 26 additions & 0 deletions run_e2e_setup.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,26 @@
#!/bin/bash

docker compose -f docker-compose.e2e-v3.yml up -d hardhat_node e2e_pgdb

echo "Running cutKeys script via ts-node..."
npx ts-node test/helpers/wait-node-cut-keys.ts &> keycutting.log &

echo "Waiting for Key cutting to complete..."
tail -f keycutting.log | while read LOG_LINE
do
if [[ "${LOG_LINE}" == *"Key cutting completed."* ]]; then
echo "Key cutting process completed!"
pkill -P $$ tail
fi
done

echo "Key cutting completed. Starting e2e_keys_api..."
docker compose -f docker-compose.e2e-v3.yml up -d e2e_keys_api

echo "Waiting for e2e_keys_api to be ready..."
until [ "$(curl -s -o /dev/null -w '%{http_code}' http://127.0.0.1:3000/v1/modules)" == "200" ]; do
echo "e2e_keys_api is not ready yet. Retrying..."
sleep 5
done

echo "e2e_keys_api is ready."
4 changes: 4 additions & 0 deletions src/guardian/guardian-message/guardian-message.service.ts
Original file line number Diff line number Diff line change
Expand Up @@ -74,6 +74,10 @@ export class GuardianMessageService {
});
}

/**
* Sends an unvetting message to the message broker
* @param message - MessageUnvet object
*/
public sendUnvetMessage(message: Omit<MessageUnvet, 'type'>) {
return this.sendMessageFromGuardian({
...message,
Expand Down
13 changes: 13 additions & 0 deletions src/keys-api/interfaces/SRModuleKeyListResponse.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
import { SRModule } from '.';
import { ELBlockSnapshot } from './ELBlockSnapshot';
import { RegistryKey } from './RegistryKey';

export type SRModuleKeyListResponse = {
data: {
keys: Array<RegistryKey>;
module: SRModule;
};
meta: {
elBlockSnapshot: ELBlockSnapshot;
};
};
11 changes: 11 additions & 0 deletions src/keys-api/keys-api.service.ts
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@ import { Configuration } from 'common/config';
import { GroupedByModuleOperatorListResponse } from './interfaces/GroupedByModuleOperatorListResponse';
import { InconsistentLastChangedBlockHash } from 'common/custom-errors';
import { SRModuleListResponse } from './interfaces/SRModuleListResponse';
import { SRModuleKeyListResponse } from './interfaces/SRModuleKeyListResponse';

@Injectable()
export class KeysApiService {
Expand Down Expand Up @@ -93,6 +94,16 @@ export class KeysApiService {
return result;
}

/**
* The /v1/modules/{module_id}/keys endpoint returns full list of keys
*/
public async getModuleKeys(moduleId: number, opId: number) {
const result = await this.fetch<SRModuleKeyListResponse>(
`/v1/modules/${moduleId}/keys?operatorIndex=${opId}`,
);
return result;
}

/**
* Verifies the consistency of metadata by comparing hashes.
* @param firstRequestHash - Hash of the first request
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -75,6 +75,8 @@ export class StakingModuleDataCollectorService {
blockData,
);

console.log('duplicates=', duplicates);

await Promise.all(
stakingModulesData.map(async (stakingModuleData) => {
// identify keys that were front-run withing vetted unused keys
Expand Down Expand Up @@ -189,6 +191,8 @@ export class StakingModuleDataCollectorService {
(key) =>
!key.used && key.vetted && key.moduleAddress === stakingModuleAddress,
);

console.log({ vettedUnusedKeys, stakingModuleAddress });
return vettedUnusedKeys;
}
}
28 changes: 0 additions & 28 deletions test/constants.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,3 @@
import { CHAINS } from '@lido-sdk/constants';
import { SecretKey } from '@chainsafe/blst';

import { fromHexString } from '@chainsafe/ssz';
Expand All @@ -9,37 +8,10 @@ export const TESTS_TIMEOUT = 30_000;
// Needs to be higher on gh actions for reliable runs
export const SLEEP_FOR_RESULT = 3_000;

// Addresses
export const SECURITY_MODULE = '0x808DE3b26Be9438F12E9B45528955EA94C17f217';
// https://holesky.etherscan.io/address/0x808DE3b26Be9438F12E9B45528955EA94C17f217#readContract
// getOwner
export const SECURITY_MODULE_OWNER =
'0xE92329EC7ddB11D25e25b3c21eeBf11f15eB325d';

export const SECURITY_MODULE_V2 = '0x045dd46212a178428c088573a7d102b9d89a022a';
// https://holesky.etherscan.io/address/0x045dd46212a178428c088573a7d102b9d89a022a#readContract
// getOwner
export const SECURITY_MODULE_OWNER_V2 =
'0xDA6bEE5441f2e6b364F3b25E85d5f3C29Bfb669E';
export const STAKING_ROUTER = '0xd6EbF043D30A7fe46D1Db32BA90a0A51207FE229';
export const NOP_REGISTRY = '0x595F64Ddc3856a3b5Ff4f4CC1d1fb4B46cFd2bAC';
export const DEPOSIT_CONTRACT = '0x4242424242424242424242424242424242424242';
export const SIMPLE_DVT = '0x11a93807078f8BB880c1BD0ee4C387537de4b4b6';
export const CSM = '0x4562c3e63c2e586cD1651B958C22F88135aCAd4f';
export const SANDBOX = '0xD6C2ce3BB8bea2832496Ac8b5144819719f343AC';
// Withdrawal credentials
export const LIDO_WC =
'0x010000000000000000000000f0179dec45a37423ead4fad5fcb136197872ead9';
export const BAD_WC =
'0x010000000000000000000000b9d7934878b5fb9610b3fe8a5e441e8fad7e291f';

// Fork node config
export const CHAIN_ID = CHAINS.Holesky;

export const FORK_BLOCK = 1894357;
export const FORK_BLOCK_V2 = 1817726;
export const UNLOCKED_ACCOUNTS = [SECURITY_MODULE_OWNER];
export const UNLOCKED_ACCOUNTS_V2 = [SECURITY_MODULE_OWNER_V2];
export const GANACHE_PORT = 8545;

// BLS key for the validator
Expand Down
Loading
Loading