【问题标题】:Error: Invalid Chai property: revertedWith错误:无效的 Chai 属性:revertedWith
【发布时间】: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


    【解决方案1】:
    猜你喜欢
    • 2019-01-30
    • 1970-01-01
    • 2019-07-01
    • 2019-08-28
    • 2018-01-01
    • 2018-05-30
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多