Created
May 5, 2022 08:00
-
-
Save 0xhmn/67646e850ece172456af0543c51ed97a to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import hre, { ethers } from "hardhat"; | |
import { Contract } from "ethers"; | |
describe("Forking", function () { | |
it("Should fork mainnet4", async function () { | |
const mainnetTestAccountAddress = "0x618d17fa59c67aEA20A88dc75d4E28E728a6fF28"; | |
const usdcAbi = require("@openzeppelin/contracts/build/contracts/IERC20.json").abi; | |
const usdcAddress = "0xA0b86991c6218b36c1d19D4a2e9Eb0cE3606eB48"; | |
// check the block number | |
const blockNumber = await ethers.provider.getBlockNumber(); | |
console.log("blocknumber", blockNumber); // blocknumber 14715419 | |
// impersonate test account | |
await hre.network.provider.request({ | |
method: "hardhat_impersonateAccount", | |
params: [mainnetTestAccountAddress], | |
}); | |
// check eth balance | |
const ethBalance = await ethers.provider.getBalance(mainnetTestAccountAddress); | |
console.log("eth balance:", ethers.utils.formatEther(ethBalance)); // eth balance: 15.315010386254091492 | |
// check usdc balance | |
const testAccount = await ethers.getSigner(mainnetTestAccountAddress); | |
const USDCContract: Contract = new ethers.Contract(usdcAddress, usdcAbi, testAccount); | |
// ERROR | |
await USDCContract.connect(testAccount).balanceOf(mainnetTestAccountAddress); | |
}); | |
}); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment