错误:处理交易时 VM 异常:已恢复,原因字符串“您需要花费更多 ETH!”

问题描述 投票:0回答:2

11:23 左右在 Solidity 课程第 7 课的单元测试部分

https://youtu.be/gyMwXuJrbJQ?t=41004。 未通过“更新资助金额数据结构”测试。 好像 sendValue 失败 但我声明了 1 以太的 sendValue 并传递了 sendvalue 的参数。

错误信息

FundMe
fund
updated the amount funded data structure:
Error: VM Exception while processing transaction: reverted with reason string 'You need to spend more ETH!'
at FundMe.fund (contracts/FundMe.sol:40)
at processTicksAndRejections (node:internal/process/task_queues:96:5)
at runNextTicks (node:internal/process/task_queues:65:3)

测试脚本-fundme.test.js

const sendValue = ethers.utils.parseEther("1")

describe("fund", async function () {
    it("Fails if you don't send enough ETH", async function () {
        await expect(fundMe.fund()).to.be.revertedWith(
            "You need to spend more ETH!"
        )
    })

    it("updated the amount funded data structure", async function () {
        // 执行fund,获取funder的地址=>金额映射,和fund的金额做对比
        await fundMe.fund({ value: sendValue })
        const response = await fundMe.addressToAmountFunded(deployer)
        assert.equal(response.toString(), sendValue.toString())
    })
javascript deployment ethereum solidity hardhat
2个回答
0
投票

尝试从以下位置删除“异步”一词:

describe("fund", async function () {

0
投票

你可以尝试替换

const sendValue = ethers.parseEther("1"); instead to 
const sendValue = ethers.parseEther("10");对我有用 `

© www.soinside.com 2019 - 2024. All rights reserved.