diff --git a/hardhat.config.ts b/hardhat.config.ts index 94e646a9..10b4402b 100644 --- a/hardhat.config.ts +++ b/hardhat.config.ts @@ -5,7 +5,12 @@ import { HardhatUserConfig } from 'hardhat/types'; import { accounts } from './test-wallets.js'; import { eEthereumNetwork, eNetwork, ePolygonNetwork, eXDaiNetwork } from './helpers/types'; import { BUIDLEREVM_CHAINID, COVERAGE_CHAINID } from './helpers/buidler-constants'; -import { NETWORKS_RPC_URL, NETWORKS_DEFAULT_GAS, BLOCK_TO_FORK } from './helper-hardhat-config'; +import { + NETWORKS_RPC_URL, + NETWORKS_DEFAULT_GAS, + BLOCK_TO_FORK, + buildForkConfig, +} from './helper-hardhat-config'; require('dotenv').config(); @@ -16,6 +21,7 @@ import 'hardhat-gas-reporter'; import 'hardhat-typechain'; import '@tenderly/hardhat-tenderly'; import 'solidity-coverage'; +import { fork } from 'child_process'; const SKIP_LOAD = process.env.SKIP_LOAD === 'true'; const DEFAULT_BLOCK_GAS_LIMIT = 12450000; @@ -24,7 +30,6 @@ const HARDFORK = 'istanbul'; const ETHERSCAN_KEY = process.env.ETHERSCAN_KEY || ''; const MNEMONIC_PATH = "m/44'/60'/0'/0"; const MNEMONIC = process.env.MNEMONIC || ''; -const FORK = process.env.FORK || ''; // Prevent to load scripts before compilation and typechain if (!SKIP_LOAD) { @@ -57,15 +62,7 @@ const getCommonNetworkConfig = (networkName: eNetwork, networkId: number) => ({ }, }); -const forkMode = FORK - ? { - url: NETWORKS_RPC_URL[FORK], - ...(FORK && - BLOCK_TO_FORK[FORK] && { - blockNumber: BLOCK_TO_FORK[FORK], - }), - } - : undefined; +let forkMode; const buidlerConfig: HardhatUserConfig = { solidity: { @@ -114,7 +111,7 @@ const buidlerConfig: HardhatUserConfig = { privateKey: secretKey, balance, })), - forking: forkMode, + forking: buildForkConfig(), }, buidlerevm_docker: { hardfork: 'berlin', diff --git a/helper-hardhat-config.ts b/helper-hardhat-config.ts index 5b903000..3df38000 100644 --- a/helper-hardhat-config.ts +++ b/helper-hardhat-config.ts @@ -1,4 +1,5 @@ // @ts-ignore +import { HardhatNetworkForkingUserConfig, HardhatUserConfig } from 'hardhat/types'; import { eEthereumNetwork, ePolygonNetwork, @@ -11,9 +12,26 @@ require('dotenv').config(); const INFURA_KEY = process.env.INFURA_KEY || ''; const ALCHEMY_KEY = process.env.ALCHEMY_KEY || ''; const TENDERLY_FORK_ID = process.env.TENDERLY_FORK_ID || ''; +const FORK = process.env.FORK || ''; +const FORK_BLOCK_NUMBER = process.env.FORK_BLOCK_NUMBER + ? parseInt(process.env.FORK_BLOCK_NUMBER) + : 0; const GWEI = 1000 * 1000 * 1000; +export const buildForkConfig = (): HardhatNetworkForkingUserConfig | undefined => { + let forkMode; + if (FORK) { + forkMode = { + url: NETWORKS_RPC_URL[FORK], + }; + if (FORK_BLOCK_NUMBER || BLOCK_TO_FORK[FORK]) { + forkMode.blockNumber = FORK_BLOCK_NUMBER || BLOCK_TO_FORK[FORK]; + } + } + return forkMode; +}; + export const NETWORKS_RPC_URL: iParamsPerNetwork = { [eEthereumNetwork.kovan]: ALCHEMY_KEY ? `https://eth-kovan.alchemyapi.io/v2/${ALCHEMY_KEY}` diff --git a/package.json b/package.json index 79b60118..1caff7c1 100644 --- a/package.json +++ b/package.json @@ -23,7 +23,7 @@ "test-amm-scenarios": "npm run compile && TS_NODE_TRANSPILE_ONLY=1 hardhat test ./test-suites/test-amm/__setup.spec.ts test-suites/test-amm/scenario.spec.ts", "test-scenarios": "npm run compile && npx hardhat test test-suites/test-aave/__setup.spec.ts test-suites/test-aave/scenario.spec.ts", "test-subgraph:scenarios": "npm run compile && hardhat --network hardhatevm_docker test test-suites/test-aave/__setup.spec.ts test-suites/test-aave/subgraph-scenarios.spec.ts", - "test:main:check-list": "npm run compile && FORK=true TS_NODE_TRANSPILE_ONLY=1 hardhat test test-suites/test-aave/__setup.spec.ts test-suites/test-aave/mainnet/check-list.spec.ts", + "test:main:check-list": "npm run compile && FORK=main TS_NODE_TRANSPILE_ONLY=1 hardhat test test-suites/test-aave/__setup.spec.ts test-suites/test-aave/mainnet/check-list.spec.ts", "dev:coverage": "buidler compile --force && buidler coverage --network coverage", "aave:evm:dev:migration": "npm run compile && hardhat aave:dev", "aave:docker:full:migration": "npm run compile && npm run hardhat:docker -- aave:mainnet --skip-registry",