Reputation: 1
My smart contract has to check balance of OpenSea OpenStore contract, so I need to be able to fork polygon mainnet. I want each test to start fresh with the same fork, so I'm invoking hardhat_reset
in beforeEach
. But I'm getting this incomprehensible error:
"before each" hook for "<very first 'it' under first 'describe'>":
InvalidArgumentsError: Errors encountered in param 0: Invalid value undefined supplied to : HardhatNetworkConfig | undefined/forking: RpcForkConfig | undefined | undefined/jsonRpcUrl: string
My code looks like this (it's abridged, with ellipses filling in for standard boilerplate)
import ....
import * as helpers from "@nomicfoundation/hardhat-network-helpers"
....
async function deployContract(addr=myAddr) {
await ethers.provider.send("hardhat_impersonateAccount", [addr])
helpers.setBalance(addr, "0x100000000000000000000")
const signer = await ethers.getSigner(addr)
const cf = await ethers.getContractFactory("MyContractName", signer)
contract = await cf.deploy()
}
beforeEach(async () => {
await network.provider.request({
method: "hardhat_reset",
params: [{
forking: {
url: "https://polygon-mainnet.g.alchemy.com/v2/" + apiKey,
blockNumber: 31911877
}
}]
})
const wallets = waffle.provider.getWallets()
wallet = wallets[0]
await deployContract()
})
Note that I don't get this issue if I move the forking
param data to my hardhat.config.ts
- in that case, the test executes fine except that because nothing is reset between tests, the actions done in the first test mess up the ones in later tests.
Thanks!
Upvotes: 0
Views: 1180
Reputation: 1
Under the forking
params, replace url
with jsonRpcUrl
I realized this after seeing https://stackoverflow.com/a/71811223/19350337
Upvotes: 0