Hardhat-Ethers forking test

Viewed 15

I want to write a test that simultaniously works with already deployed contracts from the mainnet, change it state in fork and can deploy its own contracts in the same fork. This is my test:

it("Deploy check", async function () {
    const provider = new ethers.providers.AlchemyProvider("homestead", process.env.ALCHEMY_API_KEY)

    const [Alice] = await ethers.getSigners()
    const WETH9 = await new ethers.Contract(ETHEREUM.WETH9.address, WETH9ABI, provider)
    const txGetWETH = await WETH9.connect(Alice).deposit({value: getBigNumber(1e18)})
    const balance = await WETH9.connect(provider).balanceOf(Alice.address)).toString();
    expect(balance).equals(1e18)
})

But the result balance is 0 ( My default hardhat network configuration:

hardhat: {
  forking: {
    enabled: process.env.FORKING === "true",
    url: `https://eth-mainnet.alchemyapi.io/v2/${process.env.ALCHEMY_API_KEY}`,
  },
  live: false,
  saveDeployments: true,
  tags: ["test", "local"],
},

Could please anybody explain - what I do wrong? I want balance to be changed in my fork

Thank you!

1 Answers

OK, I've changed 'enabled: process.env.FORKING === "true"' to 'enabled: true' and WETH9 provider from provider to Alice.

And it works now !

Closed )

Related