diff --git a/.env.example b/.env.example index 28369e584..5dcda8f6b 100644 --- a/.env.example +++ b/.env.example @@ -52,7 +52,7 @@ SEPOLIA_RPC_URL= # 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= +HARDHAT_FORKING_URL=https://eth.drpc.org # Scratch deployment via hardhat variables DEPLOYER=0xf39Fd6e51aad88F6F4ce6aB8827279cffFb92266 diff --git a/CONTRIBUTING.md b/CONTRIBUTING.md index b4babc6ce..5ca9857d1 100644 --- a/CONTRIBUTING.md +++ b/CONTRIBUTING.md @@ -328,7 +328,7 @@ 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 -> `.env` file (refer to `.env.example` for guidance). +> `.env` file (refer to `.env.example` for guidance). Otherwise, the tests will run against the Scratch deployment. ```bash # Run all integration tests diff --git a/hardhat.config.ts b/hardhat.config.ts index a8a1af019..5867f8ffe 100644 --- a/hardhat.config.ts +++ b/hardhat.config.ts @@ -1,5 +1,4 @@ -import { existsSync, readFileSync } from "node:fs"; -import path from "node:path"; +import * as process from "node:process"; import "@nomicfoundation/hardhat-chai-matchers"; import "@nomicfoundation/hardhat-toolbox"; @@ -13,41 +12,15 @@ import "hardhat-watcher"; import "hardhat-ignore-warnings"; import "hardhat-contract-sizer"; import "hardhat-gas-reporter"; -import { globSync } from "glob"; -import { TASK_COMPILE_SOLIDITY_GET_SOURCE_PATHS } from "hardhat/builtin-tasks/task-names"; -import { HardhatUserConfig, subtask } from "hardhat/config"; +import { HardhatUserConfig } from "hardhat/config"; import { mochaRootHooks } from "test/hooks"; import "./tasks"; -const RPC_URL: string = process.env.RPC_URL || ""; -const ACCOUNTS_PATH = "./accounts.json"; - -const HARDHAT_FORKING_URL = process.env.HARDHAT_FORKING_URL || ""; - -const INTEGRATION_WITH_SCRATCH_DEPLOY = process.env.INTEGRATION_WITH_SCRATCH_DEPLOY || "off"; - -/* Determines the forking configuration for Hardhat */ -function getHardhatForkingConfig() { - if (INTEGRATION_WITH_SCRATCH_DEPLOY === "on" || !HARDHAT_FORKING_URL) { - return undefined; - } - return { url: HARDHAT_FORKING_URL }; -} +import { getHardhatForkingConfig, loadAccounts } from "./hardhat.helpers"; -function loadAccounts(networkName: string) { - // TODO: this plaintext accounts.json private keys management is a subject - // of rework to a solution with the keys stored encrypted - if (!existsSync(ACCOUNTS_PATH)) { - return []; - } - const content = JSON.parse(readFileSync(ACCOUNTS_PATH, "utf-8")); - if (!content.eth) { - return []; - } - return content.eth[networkName] || []; -} +const RPC_URL: string = process.env.RPC_URL || ""; const config: HardhatUserConfig = { defaultNetwork: "hardhat", @@ -73,18 +46,6 @@ const config: HardhatUserConfig = { "local": { url: process.env.LOCAL_RPC_URL || RPC_URL, }, - "holesky-vaults-devnet-0": { - url: process.env.LOCAL_RPC_URL || RPC_URL, - timeout: 20 * 60 * 1000, // 20 minutes - }, - "mekong-vaults-devnet-1": { - url: process.env.LOCAL_RPC_URL || RPC_URL, - timeout: 20 * 60 * 1000, // 20 minutes - }, - "mainnet-fork": { - url: process.env.MAINNET_RPC_URL || RPC_URL, - timeout: 20 * 60 * 1000, // 20 minutes - }, "holesky": { url: process.env.HOLESKY_RPC_URL || RPC_URL, chainId: 17000, @@ -99,28 +60,13 @@ const config: HardhatUserConfig = { url: process.env.SEPOLIA_RPC_URL || RPC_URL, chainId: 11155111, }, - "mekong": { - url: process.env.MEKONG_RPC_URL || RPC_URL, - chainId: 7078815900, - accounts: loadAccounts("mekong"), + "mainnet-fork": { + url: process.env.MAINNET_RPC_URL || RPC_URL, + timeout: 20 * 60 * 1000, // 20 minutes }, }, etherscan: { - apiKey: { - default: process.env.ETHERSCAN_API_KEY || "", - holesky: process.env.ETHERSCAN_API_KEY || "", - mekong: process.env.BLOCKSCOUT_API_KEY || "", - }, - customChains: [ - { - network: "mekong", - chainId: 7078815900, - urls: { - apiURL: "https://explorer.mekong.ethpandaops.io/api", - browserURL: "https://explorer.mekong.ethpandaops.io", - }, - }, - ], + apiKey: process.env.ETHERSCAN_API_KEY || "", }, solidity: { compilers: [ @@ -231,16 +177,4 @@ const config: HardhatUserConfig = { }, }; -// a workaround for having an additional source directory for compilation -// see, https://github.com/NomicFoundation/hardhat/issues/776#issuecomment-1713584386 -subtask(TASK_COMPILE_SOLIDITY_GET_SOURCE_PATHS).setAction(async (_, hre, runSuper) => { - const paths = await runSuper(); - - const otherDirectoryGlob = path.join(hre.config.paths.root, "test", "**", "*.sol"); - // Don't need to compile test, helper and script files that are not part of the contracts for Hardhat. - const otherPaths = globSync(otherDirectoryGlob).filter((x) => !/\.([ths]\.sol)$/.test(x)); - - return [...paths, ...otherPaths]; -}); - export default config; diff --git a/hardhat.helpers.ts b/hardhat.helpers.ts new file mode 100644 index 000000000..47f6533b8 --- /dev/null +++ b/hardhat.helpers.ts @@ -0,0 +1,32 @@ +import { existsSync, readFileSync } from "node:fs"; + +/* Determines the forking configuration for Hardhat */ +export function getHardhatForkingConfig() { + const forkingUrl = process.env.HARDHAT_FORKING_URL || ""; + + if (!forkingUrl) { + // Scratch deploy, need to disable CSM + process.env.INTEGRATION_ON_SCRATCH = "on"; + process.env.INTEGRATION_WITH_CSM = "off"; + return undefined; + } + + return { url: forkingUrl }; +} + +// TODO: this plaintext accounts.json private keys management is a subject +// of rework to a solution with the keys stored encrypted +export function loadAccounts(networkName: string) { + const accountsPath = "./accounts.json"; + + if (!existsSync(accountsPath)) { + return []; + } + + const content = JSON.parse(readFileSync(accountsPath, "utf-8")); + if (!content.eth) { + return []; + } + + return content.eth[networkName] || []; +} diff --git a/tasks/index.ts b/tasks/index.ts index ada28baca..04b17d7c9 100644 --- a/tasks/index.ts +++ b/tasks/index.ts @@ -1,2 +1,3 @@ export * from "./verify-contracts"; export * from "./extract-abis"; +export * from "./solidity-get-source"; diff --git a/tasks/solidity-get-source.ts b/tasks/solidity-get-source.ts new file mode 100644 index 000000000..522a4af59 --- /dev/null +++ b/tasks/solidity-get-source.ts @@ -0,0 +1,18 @@ +import path from "node:path"; + +import { globSync } from "glob"; +import { TASK_COMPILE_SOLIDITY_GET_SOURCE_PATHS } from "hardhat/builtin-tasks/task-names"; +import { subtask } from "hardhat/config"; + +// a workaround for having an additional source directory for compilation +// see, https://github.com/NomicFoundation/hardhat/issues/776#issuecomment-1713584386 + +subtask(TASK_COMPILE_SOLIDITY_GET_SOURCE_PATHS).setAction(async (_, hre, runSuper) => { + const paths = await runSuper(); + + const otherDirectoryGlob = path.join(hre.config.paths.root, "test", "**", "*.sol"); + // Don't need to compile test, helper and script files that are not part of the contracts for Hardhat. + const otherPaths = globSync(otherDirectoryGlob).filter((x) => !/\.([ths]\.sol)$/.test(x)); + + return [...paths, ...otherPaths]; +});