From 60d6e23c375edf9bf63b6c4cef41e27f313aab0f Mon Sep 17 00:00:00 2001 From: Yuri Tkachenko Date: Fri, 4 Oct 2024 17:24:20 +0100 Subject: [PATCH] chore: updates non related to sdvt --- .env.example | 6 +++++- CONTRIBUTING.md | 8 +++++--- globals.d.ts | 18 ++++++++++++------ hardhat.config.ts | 20 +++++++++++++------- lib/protocol/context.ts | 4 ++-- lib/state-file.ts | 20 +++++++++++++++++--- package.json | 8 ++++---- 7 files changed, 58 insertions(+), 26 deletions(-) diff --git a/.env.example b/.env.example index 916e48b31..d616d3508 100644 --- a/.env.example +++ b/.env.example @@ -25,9 +25,13 @@ LOCAL_WITHDRAWAL_VAULT_ADDRESS= # RPC URL for a separate, non Hardhat Network node (Anvil, Infura, Alchemy, etc.) MAINNET_RPC_URL=http://localhost:8545 + # RPC URL for Hardhat Network forking, required for running tests on mainnet fork with tracing (Infura, Alchemy, etc.) # https://hardhat.org/hardhat-network/docs/guides/forking-other-networks#forking-other-networks -MAINNET_FORKING_URL= +HARDHAT_FORKING_URL= + +# Chain ID for the network on Hardhat Network +HARDHAT_CHAIN_ID= # https://docs.lido.fi/deployed-contracts MAINNET_LOCATOR_ADDRESS=0xC1d0b3DE6792Bf6b4b37EccdcC24e45978Cfd2Eb diff --git a/CONTRIBUTING.md b/CONTRIBUTING.md index fcd9c9941..b95f36970 100644 --- a/CONTRIBUTING.md +++ b/CONTRIBUTING.md @@ -50,7 +50,9 @@ the [Lido Research Forum](https://research.lido.fi/). - [Foundry](https://book.getfoundry.sh/) latest available version > [!TIP] -> On macOS with Homebrew, it is recommended to install Node.js using [`n`](https://github.com/tj/n) or [ > `nvm`](https://github.com/nvm-sh/nvm) version managers. +> On macOS with Homebrew, it is recommended to install Node.js using [`n`](https://github.com/tj/n) or +> [ >`nvm`](https://github.com/nvm-sh/nvm) version managers. +> > Example setup process using `n` package manager for zsh users: > > ```bash @@ -325,8 +327,8 @@ This is the most common method for running integration tests. It uses an instanc mainnet environment, allowing you to run integration tests with trace logging. > [!NOTE] -> Ensure that `MAINNET_FORKING_URL` and other `MAINNET_*` environment variables are set in the `.env` file (refer to -> `.env.example` for guidance). +> Ensure that `HARDHAT_FORKING_URL` is set to Ethereum Mainnet RPC and `MAINNET_*` environment variables are set in the +> `.env` file (refer to `.env.example` for guidance). ```bash # Run all integration tests diff --git a/globals.d.ts b/globals.d.ts index 7637be82d..2ffc3f6c8 100644 --- a/globals.d.ts +++ b/globals.d.ts @@ -1,19 +1,25 @@ declare namespace NodeJS { export interface ProcessEnv { - /* RPC URL for Hardhat Network forking, required for running tests on mainnet fork with tracing */ - MAINNET_FORKING_URL?: string; + /* iternal logging verbosity (used in scratch deploy / integration tests) */ + LOG_LEVEL?: "all" | "debug" | "info" | "warn" | "error" | "none"; // default: "info" - /* logging verbosity */ - LOG_LEVEL?: "all" | "debug" | "info" | "warn" | "error" | "none"; + /** + * Flags for changing the behavior of the Hardhat Network + */ + + /* RPC URL for Hardhat Network forking, required for running tests on mainnet fork with tracing */ + HARDHAT_FORKING_URL?: string; + /* Chain ID for Hardhat Network forking, required for running tests on different networks */ + HARDHAT_CHAIN_ID?: string; /** * Flags for changing the behavior of the integration tests */ /* if "on" the integration tests will deploy the contracts to the empty Hardhat Network node using scratch deploy */ - INTEGRATION_SCRATCH_DEPLOY?: "on" | "off"; + INTEGRATION_WITH_SCRATCH_DEPLOY?: "on" | "off"; // default: "off" /* if "on" the integration tests will enable assertions and checks for the simple DVT module */ - INTEGRATION_SIMPLE_DVT_MODULE?: "on" | "off"; + INTEGRATION_WITH_SIMPLE_DVT_MODULE?: "on" | "off"; // default: "on" /** * Network configuration for the protocol discovery. diff --git a/hardhat.config.ts b/hardhat.config.ts index c4b0c2ef0..98b61e11a 100644 --- a/hardhat.config.ts +++ b/hardhat.config.ts @@ -21,16 +21,20 @@ import { mochaRootHooks } from "test/hooks"; import "./tasks"; const RPC_URL: string = process.env.RPC_URL || ""; -const MAINNET_FORKING_URL = process.env.MAINNET_FORKING_URL || ""; -const INTEGRATION_SCRATCH_DEPLOY = process.env.INTEGRATION_SCRATCH_DEPLOY || "off"; const ACCOUNTS_PATH = "./accounts.json"; -/** - * Determines the forking configuration for Hardhat. - * @returns The forking configuration object or undefined. - */ +const HARDHAT_CHAIN_ID_DEFAULT = 31337; +const HARDHAT_FORKING_URL = process.env.HARDHAT_FORKING_URL || ""; +const HARDHAT_CHAIN_ID = process.env.HARDHAT_CHAIN_ID || HARDHAT_CHAIN_ID_DEFAULT; + +const INTEGRATION_WITH_SCRATCH_DEPLOY = process.env.INTEGRATION_WITH_SCRATCH_DEPLOY || "off"; + +/* Determines the forking configuration for Hardhat */ function getHardhatForkingConfig() { - return INTEGRATION_SCRATCH_DEPLOY === "on" || !MAINNET_FORKING_URL ? undefined : { url: MAINNET_FORKING_URL }; + if (INTEGRATION_WITH_SCRATCH_DEPLOY === "on" || !HARDHAT_FORKING_URL) { + return undefined; + } + return { url: HARDHAT_FORKING_URL }; } function loadAccounts(networkName: string) { @@ -51,6 +55,7 @@ const config: HardhatUserConfig = { networks: { "local": { url: process.env.LOCAL_RPC_URL || RPC_URL, + chainId: HARDHAT_CHAIN_ID_DEFAULT, }, "mainnet-fork": { url: process.env.MAINNET_RPC_URL || RPC_URL, @@ -69,6 +74,7 @@ const config: HardhatUserConfig = { count: 30, accountsBalance: "100000000000000000000000", }, + chainId: parseInt(HARDHAT_CHAIN_ID.toString()), forking: getHardhatForkingConfig(), }, "sepolia": { diff --git a/lib/protocol/context.ts b/lib/protocol/context.ts index ed05cc8c4..d4c04232e 100644 --- a/lib/protocol/context.ts +++ b/lib/protocol/context.ts @@ -23,8 +23,8 @@ export const getProtocolContext = async (): Promise => { // By default, all flags are "on" const flags = { - isScratchDeploy: process.env.INTEGRATION_SCRATCH_DEPLOY === "on", - withSimpleDvtModule: process.env.INTEGRATION_SIMPLE_DVT_MODULE !== "off", + isScratchDeploy: process.env.INTEGRATION_WITH_SCRATCH_DEPLOY === "on", + withSimpleDvtModule: process.env.INTEGRATION_WITH_SIMPLE_DVT_MODULE !== "off", } as ProtocolContextFlags; log.debug("Protocol context flags", { diff --git a/lib/state-file.ts b/lib/state-file.ts index ba7d271cf..7ff742643 100644 --- a/lib/state-file.ts +++ b/lib/state-file.ts @@ -12,7 +12,7 @@ export type DeploymentState = { [key: string]: any; }; -export const AppNames = { +export const TemplateAppNames = { // Lido apps LIDO: "lido", ORACLE: "oracle", @@ -32,6 +32,7 @@ export enum Sk { appLido = "app:lido", appOracle = `app:oracle`, appNodeOperatorsRegistry = "app:node-operators-registry", + appSimpleDvt = "app:simple-dvt", aragonAcl = "aragon-acl", aragonEvmScriptRegistry = "aragon-evm-script-registry", aragonApmRegistry = "aragon-apm-registry", @@ -57,6 +58,7 @@ export enum Sk { lidoTemplate = "lidoTemplate", miniMeTokenFactory = "miniMeTokenFactory", lidoTemplateCreateStdAppReposTx = "lidoTemplateCreateStdAppReposTx", + nodeOperatorsRegistry = "nodeOperatorsRegistry", createAppReposTx = "createAppReposTx", lidoTemplateNewDaoTx = "lidoTemplateNewDaoTx", callsScript = "callsScript", @@ -138,13 +140,25 @@ export function readNetworkState({ deployer?: string; networkStateFile?: string; } = {}) { + const networkName = hardhatNetwork.name; + const networkChainId = hardhatNetwork.config.chainId; + const fileName = networkStateFile ? resolve(NETWORK_STATE_FILE_DIR, networkStateFile) - : _getFileName(hardhatNetwork.name, NETWORK_STATE_FILE_BASENAME, NETWORK_STATE_FILE_DIR); + : _getFileName(networkName, NETWORK_STATE_FILE_BASENAME, NETWORK_STATE_FILE_DIR); + const state = _readStateFile(fileName); + // Validate the deployer if (deployer !== undefined && deployer != state.deployer) { - throw new Error(`The specified deployer ${deployer} does not match the one ${state.deployer} in the state file`); + throw new Error(`The specified deployer ${deployer} does not match the one ${state.deployer} in the state file!`); + } + + // Validate the chainId + if (state[Sk.chainSpec].chainId && networkChainId !== parseInt(state[Sk.chainSpec].chainId)) { + throw new Error( + `The chainId: ${networkChainId} does not match the one (${state[Sk.chainSpec].chainId}) in the state file!`, + ); } return state; diff --git a/package.json b/package.json index 5ba138163..93950733f 100644 --- a/package.json +++ b/package.json @@ -25,10 +25,10 @@ "test:integration": "hardhat test test/integration/**/*.ts --bail", "test:integration:trace": "hardhat test test/integration/**/*.ts --trace --disabletracer --bail", "test:integration:fulltrace": "hardhat test test/integration/**/*.ts --fulltrace --disabletracer --bail", - "test:integration:scratch": "INTEGRATION_SCRATCH_DEPLOY=on INTEGRATION_SIMPLE_DVT_MODULE=off hardhat test test/integration/**/*.ts --bail", - "test:integration:scratch:trace": "INTEGRATION_SCRATCH_DEPLOY=on INTEGRATION_SIMPLE_DVT_MODULE=off hardhat test test/integration/**/*.ts --trace --disabletracer --bail", - "test:integration:scratch:fulltrace": "INTEGRATION_SCRATCH_DEPLOY=on INTEGRATION_SIMPLE_DVT_MODULE=off hardhat test test/integration/**/*.ts --fulltrace --disabletracer --bail", - "test:integration:fork:local": "INTEGRATION_SIMPLE_DVT_MODULE=off hardhat test test/integration/**/*.ts --network local --bail", + "test:integration:scratch": "INTEGRATION_WITH_SCRATCH_DEPLOY=on INTEGRATION_WITH_SIMPLE_DVT_MODULE=off hardhat test test/integration/**/*.ts --bail", + "test:integration:scratch:trace": "INTEGRATION_WITH_SCRATCH_DEPLOY=on INTEGRATION_WITH_SIMPLE_DVT_MODULE=off hardhat test test/integration/**/*.ts --trace --disabletracer --bail", + "test:integration:scratch:fulltrace": "INTEGRATION_WITH_SCRATCH_DEPLOY=on INTEGRATION_WITH_SIMPLE_DVT_MODULE=off hardhat test test/integration/**/*.ts --fulltrace --disabletracer --bail", + "test:integration:fork:local": "INTEGRATION_WITH_SIMPLE_DVT_MODULE=off hardhat test test/integration/**/*.ts --network local --bail", "test:integration:fork:mainnet": "hardhat test test/integration/**/*.ts --network mainnet-fork --bail", "typecheck": "tsc --noEmit", "prepare": "husky",