我想测试我的契约FundMe.sol但它如何启动FundMe.test.js弹出以下错误
我的主机
FundMe
constructor
Development network detected! Deploying mocks...
✓ Should set the aggregator addresses correctly
fund
1) Should fail if you don't send enough ETH
1 passing (977ms)
1 failing
1) FundMe
fund
Should fail if you don't send enough ETH:
Error: Invalid Chai property: revertedWith
at Object.proxyGetter [as get] (node_modules/chai/lib/chai/utils/proxify.js:78:17)
at Context.<anonymous> (test/unit/FundMe.test.js:29:46)
将测试写入文件FundMe.sol的文件
资金管理测试js
const { deployments, ethers, getNamedAccounts } = require("hardhat")
const { assert, expect, revertedWith } = require("chai")
describe("FundMe", async function() {
let fundMe
let deployer
let mockV3Aggregator
beforeEach(async function() {
deployer = (await getNamedAccounts()).deployer
await deployments.fixture(["all"]) // deploy all contracts using deployment.fixture()
fundMe = await ethers.getContract("FundMe", deployer)
mockV3Aggregator = await ethers.getContract(
"MockV3Aggregator",
deployer
)
})
describe("constructor", async function() {
it("Should set the aggregator addresses correctly", async function() {
const response = await fundMe.priceFeed()
assert.equal(response, mockV3Aggregator.address)
})
})
describe("fund", async function() {
it("Should fail if you don't send enough ETH", async function() {
await expect(fundMe.fund()).to.be.revertedWith("You need to spend more ETH!")
})
})
})
我做错了什么?
4条答案
按热度按时间0ejtzxu11#
revertedWith()实际上并不是Chai的一部分,它来自hardhat,请确保在脚本的顶部设置const {ethers} = require(“hardhat”)
例如:
wwwo4jvm2#
您只需要安装hardhat-chai-matchers如下:
然后将下面这一行添加到hardhat.config.js中:
0aydgbwb3#
您需要将
ethereum-waffle
添加到您的软件包中。安装了@nomiclabs/hardhat-waffle
后,它无法正常工作!完成后,您将能够使用
revertedWith
。最近安全帽的新包安全帽工具箱已经取代了一些基本包here
0pizxfdo4#
您不必导入
revertedWith
,这是导致Error: Invalid Chai property: revertedWith
错误的原因。尝试将chai导入行更改为: