i'm testing my contracts on hardhat network with fork of BSC.
i'm deploying my token contract that have mint function:
// @dev Creates `_amount` token to `_to`. Must only be called by the owner (MasterChef).
function mint(address _to, uint256 _amount) public onlyOwner {
_mint(_to, _amount);
_moveDelegates(address(0), _delegates[_to], _amount);
}
then i'm deploying it on test using > npx hardhat test
, it will run tests of this code:
...
it("Should deploy", async () => {
token = await Token.deploy();
await token.deployed();
console.debug(`\t\t\tToken Contract Address: ${cyan}`, token.address);
const supply = await token.totalSupply()
console.debug(`\t\t\tToken totalSupply: ${yellow}`, supply);
await token.mint(owner.address, web3.utils.toWei("1000", 'ether'))
console.debug(`\t\t\tToken owner balance: ${cyan}`, token.balanceOf(owner.address));
});
...
test print the first 2 console debug correctly:
Token Contract Address: 0x5FbDB2315678afecb367f032d93F642f64180aa3
Token totalSupply: 0
also token.totalSupply()
works, so the token is deployed correctly, but when it have to call token.mint()
it give this error:
TypeError: token.mint is not a function
at Context.<anonymous> (test/general.js:102:21)
at runMicrotasks (<anonymous>)
at processTicksAndRejections (internal/process/task_queues.js:95:5)
i tried to clean all the artifacts running > npx hardhat clean
and delated all the cache, but i still have the error
if you declared two mint functions then you have to explicitly use the fully qualified signature. Example:
token["mint(address,uint256)"](owner.address, web3.utils.toWei("1000", 'ether'))
I found the solution here https://github.com/ethers-io/ethers.js/issues/407