diff --git a/.env.example b/.env.example index f21c1c63a..f61f0a1ae 100644 --- a/.env.example +++ b/.env.example @@ -28,7 +28,7 @@ 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 -HARDHAT_FORKING_URL=https://eth.drpc.org +FORK_RPC_URL=https://eth.drpc.org # https://docs.lido.fi/deployed-contracts MAINNET_LOCATOR_ADDRESS=0xC1d0b3DE6792Bf6b4b37EccdcC24e45978Cfd2Eb diff --git a/CONTRIBUTING.md b/CONTRIBUTING.md index cf71b365f..007f7accb 100644 --- a/CONTRIBUTING.md +++ b/CONTRIBUTING.md @@ -327,7 +327,7 @@ 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 `HARDHAT_FORKING_URL` is set to Ethereum Mainnet RPC and `MAINNET_*` environment variables are set in the +> Ensure that `FORK_RPC_URL` is set to Ethereum Mainnet RPC and `MAINNET_*` environment variables are set in the > `.env` file (refer to `.env.example` for guidance). Otherwise, the tests will run against the Scratch deployment. ```bash diff --git a/globals.d.ts b/globals.d.ts index f58fe5b10..7f4233969 100644 --- a/globals.d.ts +++ b/globals.d.ts @@ -1,22 +1,22 @@ declare namespace NodeJS { export interface ProcessEnv { - /* iternal logging verbosity (used in scratch deploy / integration tests) */ + /* internal logging verbosity (used in scratch deploy / integration tests) */ LOG_LEVEL?: "all" | "debug" | "info" | "warn" | "error" | "none"; // default: "info" /** * 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; + /* Test execution mode: 'scratch' for fresh network, 'fork' for forked network */ + MODE?: "scratch" | "forking"; // default: "scratch" + + /* URL of the network to fork from */ + FORK_RPC_URL?: string; // default: "https://eth.drpc.org" /** * 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_ON_SCRATCH?: "on" | "off"; // default: "off" - /* if "on" the integration tests will assume CSM module is present in the StakingRouter, and adjust accordingly */ INTEGRATION_WITH_CSM?: "on" | "off"; // default: "off" diff --git a/hardhat.helpers.ts b/hardhat.helpers.ts index 47f6533b8..518ce7a36 100644 --- a/hardhat.helpers.ts +++ b/hardhat.helpers.ts @@ -2,16 +2,22 @@ import { existsSync, readFileSync } from "node:fs"; /* Determines the forking configuration for Hardhat */ export function getHardhatForkingConfig() { - const forkingUrl = process.env.HARDHAT_FORKING_URL || ""; + const mode = process.env.MODE || "scratch"; - if (!forkingUrl) { - // Scratch deploy, need to disable CSM - process.env.INTEGRATION_ON_SCRATCH = "on"; - process.env.INTEGRATION_WITH_CSM = "off"; - return undefined; - } + switch (mode) { + case "scratch": + process.env.INTEGRATION_WITH_CSM = "off"; + return undefined; + + case "forking": + if (!process.env.FORK_RPC_URL) { + throw new Error("FORK_RPC_URL must be set when MODE=forking"); + } + return { url: process.env.FORK_RPC_URL }; - return { url: forkingUrl }; + default: + throw new Error("MODE must be either 'scratch' or 'forking'"); + } } // TODO: this plaintext accounts.json private keys management is a subject diff --git a/lib/protocol/context.ts b/lib/protocol/context.ts index f6151f803..831c366f2 100644 --- a/lib/protocol/context.ts +++ b/lib/protocol/context.ts @@ -4,7 +4,6 @@ import hre from "hardhat"; import { deployScratchProtocol, deployUpgrade, ether, findEventsWithInterfaces, impersonate, log } from "lib"; import { discover } from "./discover"; -import { isNonForkingHardhatNetwork } from "./networks"; import { provision } from "./provision"; import { ProtocolContext, ProtocolContextFlags, ProtocolSigners, Signer } from "./types"; @@ -14,8 +13,11 @@ const getSigner = async (signer: Signer, balance = ether("100"), signers: Protoc }; export const getProtocolContext = async (): Promise => { - if (isNonForkingHardhatNetwork()) { - await deployScratchProtocol(hre.network.name); + if (hre.network.name === "hardhat") { + const networkConfig = hre.config.networks[hre.network.name]; + if (!networkConfig.forking?.enabled) { + await deployScratchProtocol(hre.network.name); + } } else { await deployUpgrade(hre.network.name); } @@ -25,12 +27,11 @@ export const getProtocolContext = async (): Promise => { // By default, all flags are "on" const flags = { - onScratch: process.env.INTEGRATION_ON_SCRATCH === "on", withCSM: process.env.INTEGRATION_WITH_CSM !== "off", } as ProtocolContextFlags; log.debug("Protocol context flags", { - "On scratch": flags.onScratch, + "With CSM": flags.withCSM, }); const context = { diff --git a/lib/protocol/types.ts b/lib/protocol/types.ts index f528b7124..ce2223804 100644 --- a/lib/protocol/types.ts +++ b/lib/protocol/types.ts @@ -134,7 +134,6 @@ export type ProtocolSigners = { export type Signer = keyof ProtocolSigners; export type ProtocolContextFlags = { - onScratch: boolean; withCSM: boolean; }; diff --git a/package.json b/package.json index 23057b7c8..31f451b50 100644 --- a/package.json +++ b/package.json @@ -22,15 +22,15 @@ "test:trace": "hardhat test test/**/*.test.ts --trace --disabletracer", "test:fulltrace": "hardhat test test/**/*.test.ts --fulltrace --disabletracer", "test:watch": "hardhat watch", - "test:integration": "hardhat test test/integration/**/*.ts", - "test:integration:trace": "hardhat test test/integration/**/*.ts --trace --disabletracer", - "test:integration:fulltrace": "hardhat test test/integration/**/*.ts --fulltrace --disabletracer", - "test:integration:scratch": "HARDHAT_FORKING_URL= INTEGRATION_WITH_CSM=off INTEGRATION_WITH_SCRATCH_DEPLOY=on hardhat test test/integration/**/*.ts", - "test:integration:scratch:trace": "HARDHAT_FORKING_URL= INTEGRATION_WITH_CSM=off INTEGRATION_WITH_SCRATCH_DEPLOY=on hardhat test test/integration/**/*.ts --trace --disabletracer", - "test:integration:scratch:fulltrace": "HARDHAT_FORKING_URL= INTEGRATION_WITH_CSM=off INTEGRATION_WITH_SCRATCH_DEPLOY=on hardhat test test/integration/**/*.ts --fulltrace --disabletracer", - "test:integration:fork:local": "hardhat test test/integration/**/*.ts --network local", - "test:integration:fork:mainnet": "hardhat test test/integration/**/*.ts --network mainnet-fork", - "test:integration:fork:mainnet:custom": "hardhat test --network mainnet-fork", + "test:integration": "MODE=forking hardhat test test/integration/**/*.ts", + "test:integration:trace": "MODE=forking hardhat test test/integration/**/*.ts --trace --disabletracer", + "test:integration:fulltrace": "MODE=forking hardhat test test/integration/**/*.ts --fulltrace --disabletracer", + "test:integration:scratch": "MODE=scratch hardhat test test/integration/**/*.ts", + "test:integration:scratch:trace": "MODE=scratch hardhat test test/integration/**/*.ts --trace --disabletracer", + "test:integration:scratch:fulltrace": "MODE=scratch hardhat test test/integration/**/*.ts --fulltrace --disabletracer", + "test:integration:fork:local": "MODE=scratch hardhat test test/integration/**/*.ts --network local", + "test:integration:fork:mainnet": "MODE=forking hardhat test test/integration/**/*.ts --network mainnet-fork", + "test:integration:fork:mainnet:custom": "MODE=forking hardhat test --network mainnet-fork", "typecheck": "tsc --noEmit", "prepare": "husky", "abis:extract": "hardhat abis:extract", diff --git a/tasks/verify-contracts.ts b/tasks/verify-contracts.ts index 0a546c15d..c03940665 100644 --- a/tasks/verify-contracts.ts +++ b/tasks/verify-contracts.ts @@ -60,7 +60,7 @@ task("verify:deployed", "Verifies deployed contracts based on state file").setAc async function verifyContract(contract: DeployedContract, hre: HardhatRuntimeEnvironment) { if (!contract.contract) { // TODO: In the case of state processing on the local devnet there are skips, we need to find the cause - return + return; } const contractName = contract.contract.split("/").pop()?.split(".")[0]; const verificationParams = { diff --git a/test/0.8.9/oracle/validator-exit-bus-oracle.submitReportData.test.ts b/test/0.8.9/oracle/validator-exit-bus-oracle.submitReportData.test.ts index 5a79f8ab1..a5f7fd628 100644 --- a/test/0.8.9/oracle/validator-exit-bus-oracle.submitReportData.test.ts +++ b/test/0.8.9/oracle/validator-exit-bus-oracle.submitReportData.test.ts @@ -501,7 +501,7 @@ describe("ValidatorsExitBusOracle.sol:submitReportData", () => { }); it("SUBMIT_DATA_ROLE is allowed", async () => { - oracle.grantRole(await oracle.SUBMIT_DATA_ROLE(), stranger, { from: admin }); + await oracle.grantRole(await oracle.SUBMIT_DATA_ROLE(), stranger, { from: admin }); await consensus.advanceTimeToNextFrameStart(); const { reportData } = await prepareReportAndSubmitHash(); await oracle.connect(stranger).submitReportData(reportData, oracleVersion);