mirror of
https://github.com/Instadapp/aave-protocol-v2.git
synced 2024-07-29 21:47:30 +00:00
feat: Improve readability of fork configuration. Support FORK_BLOCK_NUMBER enviroment variable.
This commit is contained in:
parent
e15bdec898
commit
9b06eb1477
|
@ -5,7 +5,12 @@ import { HardhatUserConfig } from 'hardhat/types';
|
||||||
import { accounts } from './test-wallets.js';
|
import { accounts } from './test-wallets.js';
|
||||||
import { eEthereumNetwork, eNetwork, ePolygonNetwork, eXDaiNetwork } from './helpers/types';
|
import { eEthereumNetwork, eNetwork, ePolygonNetwork, eXDaiNetwork } from './helpers/types';
|
||||||
import { BUIDLEREVM_CHAINID, COVERAGE_CHAINID } from './helpers/buidler-constants';
|
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();
|
require('dotenv').config();
|
||||||
|
|
||||||
|
@ -16,6 +21,7 @@ import 'hardhat-gas-reporter';
|
||||||
import 'hardhat-typechain';
|
import 'hardhat-typechain';
|
||||||
import '@tenderly/hardhat-tenderly';
|
import '@tenderly/hardhat-tenderly';
|
||||||
import 'solidity-coverage';
|
import 'solidity-coverage';
|
||||||
|
import { fork } from 'child_process';
|
||||||
|
|
||||||
const SKIP_LOAD = process.env.SKIP_LOAD === 'true';
|
const SKIP_LOAD = process.env.SKIP_LOAD === 'true';
|
||||||
const DEFAULT_BLOCK_GAS_LIMIT = 12450000;
|
const DEFAULT_BLOCK_GAS_LIMIT = 12450000;
|
||||||
|
@ -24,7 +30,6 @@ const HARDFORK = 'istanbul';
|
||||||
const ETHERSCAN_KEY = process.env.ETHERSCAN_KEY || '';
|
const ETHERSCAN_KEY = process.env.ETHERSCAN_KEY || '';
|
||||||
const MNEMONIC_PATH = "m/44'/60'/0'/0";
|
const MNEMONIC_PATH = "m/44'/60'/0'/0";
|
||||||
const MNEMONIC = process.env.MNEMONIC || '';
|
const MNEMONIC = process.env.MNEMONIC || '';
|
||||||
const FORK = process.env.FORK || '';
|
|
||||||
|
|
||||||
// Prevent to load scripts before compilation and typechain
|
// Prevent to load scripts before compilation and typechain
|
||||||
if (!SKIP_LOAD) {
|
if (!SKIP_LOAD) {
|
||||||
|
@ -57,15 +62,7 @@ const getCommonNetworkConfig = (networkName: eNetwork, networkId: number) => ({
|
||||||
},
|
},
|
||||||
});
|
});
|
||||||
|
|
||||||
const forkMode = FORK
|
let forkMode;
|
||||||
? {
|
|
||||||
url: NETWORKS_RPC_URL[FORK],
|
|
||||||
...(FORK &&
|
|
||||||
BLOCK_TO_FORK[FORK] && {
|
|
||||||
blockNumber: BLOCK_TO_FORK[FORK],
|
|
||||||
}),
|
|
||||||
}
|
|
||||||
: undefined;
|
|
||||||
|
|
||||||
const buidlerConfig: HardhatUserConfig = {
|
const buidlerConfig: HardhatUserConfig = {
|
||||||
solidity: {
|
solidity: {
|
||||||
|
@ -114,7 +111,7 @@ const buidlerConfig: HardhatUserConfig = {
|
||||||
privateKey: secretKey,
|
privateKey: secretKey,
|
||||||
balance,
|
balance,
|
||||||
})),
|
})),
|
||||||
forking: forkMode,
|
forking: buildForkConfig(),
|
||||||
},
|
},
|
||||||
buidlerevm_docker: {
|
buidlerevm_docker: {
|
||||||
hardfork: 'berlin',
|
hardfork: 'berlin',
|
||||||
|
|
|
@ -1,4 +1,5 @@
|
||||||
// @ts-ignore
|
// @ts-ignore
|
||||||
|
import { HardhatNetworkForkingUserConfig, HardhatUserConfig } from 'hardhat/types';
|
||||||
import {
|
import {
|
||||||
eEthereumNetwork,
|
eEthereumNetwork,
|
||||||
ePolygonNetwork,
|
ePolygonNetwork,
|
||||||
|
@ -11,9 +12,26 @@ require('dotenv').config();
|
||||||
const INFURA_KEY = process.env.INFURA_KEY || '';
|
const INFURA_KEY = process.env.INFURA_KEY || '';
|
||||||
const ALCHEMY_KEY = process.env.ALCHEMY_KEY || '';
|
const ALCHEMY_KEY = process.env.ALCHEMY_KEY || '';
|
||||||
const TENDERLY_FORK_ID = process.env.TENDERLY_FORK_ID || '';
|
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;
|
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<string> = {
|
export const NETWORKS_RPC_URL: iParamsPerNetwork<string> = {
|
||||||
[eEthereumNetwork.kovan]: ALCHEMY_KEY
|
[eEthereumNetwork.kovan]: ALCHEMY_KEY
|
||||||
? `https://eth-kovan.alchemyapi.io/v2/${ALCHEMY_KEY}`
|
? `https://eth-kovan.alchemyapi.io/v2/${ALCHEMY_KEY}`
|
||||||
|
|
|
@ -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-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-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-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",
|
"dev:coverage": "buidler compile --force && buidler coverage --network coverage",
|
||||||
"aave:evm:dev:migration": "npm run compile && hardhat aave:dev",
|
"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",
|
"aave:docker:full:migration": "npm run compile && npm run hardhat:docker -- aave:mainnet --skip-registry",
|
||||||
|
|
Loading…
Reference in New Issue
Block a user