我用“安全帽”作为框架来开发我的智能合同。到目前为止,这是很好的,但我不知道为什么我不能调用薄荷函数从我的测试。以下是错误消息:
Token.connect(...).mint is not a function下面是我的TESTing代码的简化版本:
describe("Token contract", function () {
let TokenContract;
let Token;
beforeEach(async () => {
TokenContract = await ethers.getContractFactory("Token");
[owner, alice, bob, carol, fakeRouter] = await ethers.getSigners();
Token = await Contract.deploy(); //sender is by default owner/first address
});
it('onlyOwner modifier', async () => {
await expect(Token.connect(alice).mint(bob.address,
10)).to.be.revertedWith('operator: caller is not the operator')
});下面是驻留在我的智能契约代码中的mint函数:
/// @notice 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);
}有人知道这是怎么回事吗?
发布于 2021-05-31 11:45:42
这件事已经在“白帽”的不和谐中得到了回答,但万一有人来了.
问题是mint函数重载了。也就是说,契约有两个不同签名的函数实现:
contract Foo {
function mint(uint amount) public { ... }
function mint(uint amount, address to) public { ... }
}当发生这种情况时,您需要使用ethers.js合同中的完全签名作为函数的名称:
await foo['mint(uint)'](123)
// or
await foo['mint(uint,address)'](123, "0x123...")https://ethereum.stackexchange.com/questions/99904
复制相似问题