Skip to content

Commit

Permalink
chore: add forking option
Browse files Browse the repository at this point in the history
  • Loading branch information
kittybest committed Mar 4, 2024
1 parent e94530f commit 56f81af
Show file tree
Hide file tree
Showing 5 changed files with 43 additions and 24 deletions.
2 changes: 1 addition & 1 deletion cli/hardhat.config.ts
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@ const config: HardhatUserConfig = {
localhost: {
url: process.env.ETH_PROVIDER || DEFAULT_ETH_PROVIDER,
accounts: [process.env.ETH_SK || DEFAULT_ETH_SK],
loggingEnabled: false,
loggingEnabled: true,
},
},
paths: {
Expand Down
2 changes: 1 addition & 1 deletion cli/ts/utils/defaults.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
// the default URL of the EVM provider
export const DEFAULT_ETH_PROVIDER = "http://localhost:8545";
export const DEFAULT_ETH_PROVIDER = "http://127.0.0.1:8545";
// the default EVM private key
export const DEFAULT_ETH_SK = "0xc87509a1c067bbde78beb793e6fa76530b6382a4c0241e5e4a9ec0a0f44dc0d3";
// the default initial voice credits assigned to users
Expand Down
3 changes: 3 additions & 0 deletions contracts/.env.example
Original file line number Diff line number Diff line change
Expand Up @@ -3,3 +3,6 @@ ETHERSCAN_API_KEY=
INFURA_KEY=
OP_RPC_URL=
GAS_PRICE=
FORKING_URL=
FORKING_BLOCK_NUM=
HARDHAT_LOGGING=
58 changes: 37 additions & 21 deletions contracts/hardhat.config.ts
Original file line number Diff line number Diff line change
Expand Up @@ -38,6 +38,42 @@ const getCommonNetworkConfig = (networkName: ESupportedChains, chainId: number,
},
});

const getHardhatConfig = () => {
const defaultConfig = {
blockGasLimit: DEFAULT_BLOCK_GAS_LIMIT,
gasMultiplier: DEFAULT_GAS_MUL,
gasPrice: NETWORKS_DEFAULT_GAS[ESupportedChains.Hardhat],
chainId: EChainId.Hardhat,
accounts: {
mnemonic: TEST_MNEMONIC,
path: "m/44'/60'/0'/0",
initialIndex: 0,
count: 20,
},
gas: DEFAULT_BLOCK_GAS_LIMIT,
loggingEnabled: !!(process.env.HARDHAT_LOGGING && process.env.HARDHAT_LOGGING === "true"),
allowUnlimitedContractSize: true,
throwOnTransactionFailures: true,
throwOnCallFailures: true,
mining: {
auto: true,
interval: 100,
},
};

if (process.env.FORKING_URL) {
return {
...defaultConfig,
forking: {
url: process.env.FORKING_URL,
blockNumber: process.env.FORKING_BLOCK_NUM ? parseInt(process.env.FORKING_BLOCK_NUM, 10) : 0,
},
};
}

return defaultConfig;
};

const config: HardhatUserConfig = {
solidity: {
version: "0.8.10",
Expand All @@ -56,27 +92,7 @@ const config: HardhatUserConfig = {
url: "http://localhost:8545",
loggingEnabled: false,
},
hardhat: {
blockGasLimit: DEFAULT_BLOCK_GAS_LIMIT,
gasMultiplier: DEFAULT_GAS_MUL,
gasPrice: NETWORKS_DEFAULT_GAS[ESupportedChains.Hardhat],
chainId: EChainId.Hardhat,
accounts: {
mnemonic: TEST_MNEMONIC,
path: "m/44'/60'/0'/0",
initialIndex: 0,
count: 20,
},
gas: DEFAULT_BLOCK_GAS_LIMIT,
loggingEnabled: false,
allowUnlimitedContractSize: true,
throwOnTransactionFailures: true,
throwOnCallFailures: true,
mining: {
auto: true,
interval: 100,
},
},
hardhat: getHardhatConfig(),
},
contractSizer: {
alphaSort: true,
Expand Down
2 changes: 1 addition & 1 deletion contracts/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@
],
"scripts": {
"watch": "tsc --watch",
"hardhat": "hardhat node --hostname 0.0.0.0 --port 8545",
"hardhat": "hardhat node",
"compileSol": "./scripts/compileSol.sh $1",
"moveIntegrationArtifacts": "cp -r artifacts/ ../integrationTests/artifacts",
"prebuild": "pnpm run compileSol",
Expand Down

0 comments on commit 56f81af

Please sign in to comment.