在硬帽项目中,我使用工作服模拟ERC20合同,使用柴氏曾被称为断言:
const {expect} = require("chai")
const {artifacts, ethers} = require("hardhat")
const {smock} = require("@defi-wonderland/smock")
it("Should successfuly invoke transfer of given ERC20", async () => {
//ARRANGE
const MyContractFactory = await ethers.getContractFactory("MyContract")
const myContract = await MyContractFactory.deploy()
await myContract.deployed()
const fakeERC20 = await smock.fake('IERC20');
fakeERC20.transfer.returns(true)
const erc20Contract = fakeERC20.address
const amount = 5
const to = '0xEA674fdDe714fd979de3EdF0F56AA9716B898ec8'
//ACT
const txReceipt = await myContract.myTransfer(erc20Contract, to, amount)
//ASSERT
expect(fakeERC20.transfer).to.have.been.calledOnce
expect(fakeERC20.transfer).to.have.been.calledWith(to, amount);
})我收到一个错误:
Error: Invalid Chai property: calledOnceTypeError: { [Function]
_watchable:
{ callHistory: [ [Object] ],
name: 'transfer',
answerByIndex: {},
answerByArgs: [],
encoder: [Function],
defaultAnswer: { value: true, shouldRevert: false } },
atCall: [Function: bound atCall],
getCall: [Function: bound getCall],
returns: [Function: bound returns],
returnsAtCall: [Function: bound returnsAtCall],
reverts: [Function: bound reverts],
revertsAtCall: [Function: bound revertsAtCall],
whenCalledWith: [Function: bound whenCalledWith],
reset: [Function: bound reset] } is not a spy or a call to a spy!有什么想法吗?
发布于 2021-12-12 21:34:58
通过增加
chai.use(smock.matchers)所以基本上你应该:
Invalid Chai property when calling calledOnce中失败,您应该安装sinon和sinon-chai。const chai = require('chai') const sinon = require('sinon') const sinonChai = require('sinon-chai') const {ethers} = require('hardhat') const {smock} = require('@defi-wonderland/smock') const expect = chai.expect chai.use(smock.matchers)发布于 2022-05-25 14:21:55
从这里开始这里。
您可以通过在测试开始时添加以下内容来解决此问题。chai.config.proxyExcludedKeys.push('calledOnce');
https://ethereum.stackexchange.com/questions/115429
复制相似问题