如何测试需要用硬汉进行陈述?
我正在测试一项智能合约,该合约在其中一个功能中具有要求。
过去,我会写。
await expect(token.transfer(user.address, ethers.utils.parseEther("10")).to.be.reverted;
但是最近它停止了工作,它给了我这个错误:
Property 'reverted' does not exist on type 'Assertion'.ts(2339)
有什么想法为什么它无法正常工作,还是我做错了什么?
多谢。
I'm testing a smart contract that has a require statement in one of the functions.
In the past, I would just write.
await expect(token.transfer(user.address, ethers.utils.parseEther("10")).to.be.reverted;
But recently it stopped working, and it gives me this error:
Property 'reverted' does not exist on type 'Assertion'.ts(2339)
Any ideas why it's not working properly, or am I doing something wrong?
Thanks a lot.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
事实证明,我没有正确导入柴。
因此,为了解决这个问题,我创建了另一个名为
chai-setup.ts
的文件,然后在内部添加了此代码:然后在我的主测试文件中,我添加了此导入语句:
这解决了我的问题。
It turns out I didn't import chai correctly.
So to solve this I created another file called
chai-setup.ts
and added this code inside:Then in my main test file, I added this import statement:
And that solved my problem.
回答稍晚,但是您可以使用 hardhat chai matchers 问题。
安装hardhat chai Matchers
通过
YARN ADD-DEV @nomicFoundation/hardhat-chai-matchers
现在您需要的只是在您的hardhat配置中导入它:
import @insionfoundation/ @noricfoundation/hardhat-chai -Matchers“;
或
require(“@nomicfoundation/hardhat-chai击败者”)
现在您将可以使用
rection> drectered
和其他东西。A little late to answer, but you can use hardhat chai matchers to solve this issue.
Install hardhat chai matchers by
yarn add --dev @nomicfoundation/hardhat-chai-matchers
Now all you need to is import it in your hardhat config by:
import "@nomicfoundation/hardhat-chai-matchers";
or
require("@nomicfoundation/hardhat-chai-matchers")
Now you will be able to use
reverted
and other stuff.