我正在使用 BSC 的分支在 hardhat 网络上测试我的合约。
我正在部署我的具有铸币功能的代币合约:
// @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);
}
然后我使用 > npx hardhat test
在测试中部署它,它将运行这段代码的测试:
...
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));
});
...
测试打印前 2 个控制台调试正确:
Token Contract Address: 0x5FbDB2315678afecb367f032d93F642f64180aa3
Token totalSupply: 0
token.totalSupply()
也可以正常工作,因此 token 已正确部署,但是当它必须调用 token.mint()
时会出现此错误:
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)
我尝试清理所有运行 > npx hardhat clean
的工件并删除所有缓存,但我仍然有错误
最佳答案
如果您声明了两个 mint 函数,那么您必须明确使用完全限定的签名。 示例:
token["mint(address,uint256)"](owner.address, web3.utils.toWei("1000", 'ether'))
我在这里找到了解决方案 https://github.com/ethers-io/ethers.js/issues/407
关于blockchain - 安全帽测试 : <functionName> is not a function,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/70364713/
相关文章:
typescript - zod:将字符串转换为数字后设置最小最大值
python - 如何在句子中交替替换单词中的大小写字母? Python
c# - 循环中 Enumerable Count 方法的性能
kotlin - 是否可以使用私有(private)辅助构造函数在 Kotlin 中分配一个 val
c - 为什么这个计算字符串长度的 C 程序会给出错误的输出?
c++ - 是否有标准的 Untokenize 模板化类型?
python - 如何乘以一个数字直到它达到 Python 中的特定数字?
gradle - 如何在 GitHub 工作流程中重用 gradle 缓存