如何测试需要用硬汉进行陈述?

发布于 2025-02-03 06:51:46 字数 325 浏览 1 评论 0原文

我正在测试一项智能合约,该合约在其中一个功能中具有要求。

过去,我会写。

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 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(2

怪我入戏太深 2025-02-10 06:51:46

事实证明,我没有正确导入柴。

因此,为了解决这个问题,我创建了另一个名为chai-setup.ts的文件,然后在内部添加了此代码:

import chaiModule from "chai";
import { chaiEthers } from "chai-ethers";
chaiModule.use(chaiEthers);
export = chaiModule;

然后在我的主测试文件中,我添加了此导入语句:

import { expect } from "./chai-setup"

这解决了我的问题。

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:

import chaiModule from "chai";
import { chaiEthers } from "chai-ethers";
chaiModule.use(chaiEthers);
export = chaiModule;

Then in my main test file, I added this import statement:

import { expect } from "./chai-setup"

And that solved my problem.

勿忘初心 2025-02-10 06:51:46

回答稍晚,但是您可以使用 hardhat chai matchers 问题。

安装hardhat chai Matchers

通过YARN ADD-DEV @nomicFoundation/hardhat-c​​hai-matchers

现在您需要的只是在您的hardhat配置中导入它:

import @insionfoundation/ @noricfoundation/hardhat-c​​hai -Matchers“;

require(“@nomicfoundation/hardhat-c​​hai击败者”)

现在您将可以使用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.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文