PatrickAlphaC / hardhat-fund-me-fcc

82 stars 183 forks source link

I meet an error in FundMe.test.js, when I want to "Updates the amount funded data structure" #131

Open alexchenyu opened 1 year ago

alexchenyu commented 1 year ago

I meet an error in FundMe.test.js, when I want to "Updates the amount funded data structure" Can you help? Here is the error message:

alex@us-cu0174-nb:~/learn-web3/hh-fcc/hardhat-fund-me-fcc$ yarn hardhat test
yarn run v1.22.19
$ /home/alex/learn-web3/hh-fcc/hardhat-fund-me-fcc/node_modules/.bin/hardhat test

  FundMe
    constructor
      ✔ sets the aggregator addresses correctly
    fund
      ✔ Fails if you don't send enough ETH (75ms)
      1) Updates the amount funded data structure

  2 passing (544ms)
  1 failing

  1) FundMe
       fund
         Updates 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:53)
    at processTicksAndRejections (node:internal/process/task_queues:95:5)
    at runNextTicks (node:internal/process/task_queues:64:3)
    at listOnTimeout (node:internal/timers:533:9)
    at processTimers (node:internal/timers:507:7)
    at HardhatNode._mineBlockWithPendingTxs (node_modules/hardhat/src/internal/hardhat-network/provider/node.ts:1815:23)
    at HardhatNode.mineBlock (node_modules/hardhat/src/internal/hardhat-network/provider/node.ts:504:16)
    at EthModule._sendTransactionAndReturnHash (node_modules/hardhat/src/internal/hardhat-network/provider/modules/eth.ts:1522:18)

error Command failed with exit code 1.
info Visit https://yarnpkg.com/en/docs/cli/run for documentation about this command.

and here is my codes:

const { assert, expect } = require("chai")
const { network, deployments, ethers } = require("hardhat")
const { developmentChains } = require("../../helper-hardhat-config")

describe("FundMe", async function() {
    let fundMe
    let mockV3Aggregator
    let deployer
    const sendValue = ethers.utils.parseEther("1") // ETH
    beforeEach(async function() {
        // deploy our fundme contract
        // using hardhat-deploy
        // const accounts = await ethers.getSigners()
        // const accountZero = accounts[0]
        // const { deployer } = await getNamedAccounts() // same with next line
        deployer = (await getNamedAccounts()).deployer
        await deployments.fixture(["all"]) // deploy everything in deploy folder?
        fundMe = await ethers.getContract("FundMe", deployer) // most recent deployed contarct
        mockV3Aggregator = await ethers.getContract(
            "MockV3Aggregator",
            deployer
        )
    })

    describe("constructor", async function() {
        it("sets the aggregator addresses correctly", async () => {
            const response = await fundMe.getPriceFeed()
            assert.equal(response, mockV3Aggregator.address)
        })
    })

    describe("fund", function() {
        it("Fails if you don't send enough ETH", async () => {
            await expect(fundMe.fund()).to.be.revertedWith(
                "You need to spend more ETH!"
            )
        })
        it("Updates the amount funded data structure", async () => {
            await fundMe.fund({ value: sendValue })
            const response = await fundMe.getAddressToAmountFunded(deployer)
            assert.equal(response.toString(), sendValue.toString())
        })
    })
})
alexchenyu commented 1 year ago

I solved this issue just by add more send value:


const sendValue = ethers.utils.parseEther("5") // ETH
SNEHAASHISH commented 1 year ago

I solved this issue just by add more send value:

const sendValue = ethers.utils.parseEther("5") // ETH

For me that's not working