小编Dzu*_*ray的帖子

使用 Waffle 模拟合约作为单元测试中方法的被调用者

问题:我想测试一个方法只能由另一个合约调用。

例子:

// B.sol
contract B {
  A _a;
  uint256 i;

  constructor(A a) {
    _a = a;
    i = 0;
  }
  function doSomething() external {
    require(address(_a) == msg.sender);
    i += 1;
  }
}

// A.sol
contract A {
  B _b;
  constructor(B b) {
    _b = b;
  }
  function callB() external {
    _b.doSomething();
  }
}
Run Code Online (Sandbox Code Playgroud)
// B.sol
contract B {
  A _a;
  uint256 i;

  constructor(A a) {
    _a = a;
    i = 0;
  }
  function doSomething() external {
    require(address(_a) == msg.sender); …
Run Code Online (Sandbox Code Playgroud)

testing ethers.js hardhat

4
推荐指数
1
解决办法
286
查看次数

标签 统计

ethers.js ×1

hardhat ×1

testing ×1