I am getting an error using a hardhat fork for testing. I run the forked node with
"npx hardhat node --fork https://eth-mainnet.alchemyapi.io/v2/key --fork-block-number 13997235"
I am able to successfully query the node from a web3 application. When I try to run tests with "npx hardhat test" it fails.
The test code is:
const { expect } = require("chai");
const { ethers, waffle } = require("hardhat");
const provider = waffle.provider;
it("test getting contract data from fork", async function () {
WETH9 = await ethers.getContractFactory('WETH9')
const WETH_address = "0xC02aaA39b223FE8D0A0e5C4F27eAD9083C756Cc2"
weth = await WETH9.attach(WETH_address)
console.log("rweth: " + await weth.decimals());
return true;
})
The error is,
"Error: call revert exception (method="decimals()", errorArgs=null, errorName=null, errorSignature=null, reason=null, code=CALL_EXCEPTION, version=abi/5.5.0)"