【发布时间】:2022-08-19 03:15:18
【问题描述】:
我想测试我的合同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
FundMe.test.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!\")
})
})
})
我究竟做错了什么?
标签: javascript node.js blockchain hardhat