如何用 hardhat 去测试fallback函数?

合约代码:

//SPDX-License-Identifier: Unlicense
pragma solidity ^0.8.0;

import "hardhat/console.sol";

contract Greeter {

    string private greeting;

    event Log(uint gas);

    constructor() {

    }

    fallback() external payable {
        console.log("hello", "");
        emit Log(gasleft());
    }

    receive() external payable {
    }

}

js调用的代码:

const Greeter = await ethers.getContractFactory("Greeter");
    const greeter = await Greeter.deploy();
    await greeter.deployed();

    const tx = await greeter.abc();

错误提示:greeter.abc is not a function

反正就是我调用了智能合约里面没有的函数,就会报错的。

请先 登录 后评论

最佳答案 2022-07-19 11:54

提示 abc 不是一个函数是因为 abi 里不包含abc 函数。

你可以在 abi 里添加 abc 函数,然后用 abi 去构造合约对象,再调用。

请先 登录 后评论

其它 2 个回答

663 - 合约
请先 登录 后评论
xiang
请先 登录 后评论
  • 4 关注
  • 0 收藏,1437 浏览
  • salic 提出于 2022-07-19 05:05

相似问题