'"owner" account start with a non-zero DAI balance in Hardhat test suite
I'm writing unit tests using Hardhat's mainnet fork, and for a test I want to assert that the initial DAI balance for the owner account is 0. However when the code reaches the assertion assert(ownerDai.isZero());, the assertion fails. Here's the test:
const { assert } = require("chai");
const { ethers } = require("hardhat");
const ERC20ABI = require('../external_ABI/ERC20.json'); // ERC20 abi for interacting with DAI
const DAI_ADDRESS = "0x6b175474e89094c44da98b954eedeac495271d0f";
describe("SimpleTest", function () {
it("Test that owner DAI balance is 0", async function () {
const provider = ethers.provider;
const [owner] = await ethers.getSigners();
const DAI = new ethers.Contract(DAI_ADDRESS, ERC20ABI, provider);
ownerDaiBalance = await DAI.balanceOf(owner.address);
assert(ownerDaiBalance.isZero()); // Assertion fails here
});
});
If I print ownerDaiBalance to console it shows that the balance is actually equal to 10008133730236507217. Why is ownerDaiBalance non-zero to start?
Sources
This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.
Source: Stack Overflow
| Solution | Source |
|---|
