我正在测试一个智能合同,在其中一个函数中有一个require语句。
在过去,我只会写。
await expect(token.transfer(user.address, ethers.utils.parseEther("10")).to.be.reverted;但是最近它停止工作了,它给了我一个错误:
Property 'reverted' does not exist on type 'Assertion'.ts(2339)你知道它为什么不能正常工作吗,还是我做错了什么?
非常感谢。
发布于 2022-06-08 19:50:59
原来我没有正确地导入柴果。
因此,为了解决这个问题,我创建了另一个名为chai-setup.ts的文件,并在其中添加了以下代码:
import chaiModule from "chai";
import { chaiEthers } from "chai-ethers";
chaiModule.use(chaiEthers);
export = chaiModule;然后,在我的主测试文件中,添加了以下导入语句:
import { expect } from "./chai-setup"这解决了我的问题。
发布于 2022-08-01 19:10:11
回答有点晚,但是您可以使用草帽柴胡来解决这个问题。
安装草帽柴布
yarn add --dev @nomicfoundation/hardhat-chai-matchers
现在,您只需要通过以下方法将其导入到您的硬帽子配置中:
import "@nomicfoundation/hardhat-chai-matchers";
或
require("@nomicfoundation/hardhat-chai-matchers")
现在,您将能够使用reverted和其他东西。
https://stackoverflow.com/questions/72452057
复制相似问题