Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Solved: AssertionError: Expected transaction to be reverted with reason 'You need to spend more ETH!', but it reverted with reason 'Did not send enough!' #6606

Open
BilgeKaanGencdogan opened this issue May 7, 2024 · 1 comment

Comments

@BilgeKaanGencdogan
Copy link

BilgeKaanGencdogan commented May 7, 2024

Hello,
I've just opened this issue for those who have the same error as I have.
When I write the test for

function fund() public payable {
        require(
            msg.value.getConversionRate(priceFeed) >= MINIMUM_USD,
            "Did not send enough!"
        );

        funders.push(msg.sender);
        addressToAmountFunded[msg.sender] += msg.value;
    }

in the FundMe.test.js, I got this error.
Error content is this:

yarn run v1.22.22
warning package.json: No license field
$ /home/bilgekaangencdogan/Desktop/FreeCodeCampBlockchain/hardhat-fund-me-fcc/node_modules/.bin/hardhat test
WARNING: You are currently using Node.js v21.7.3, which is not supported by Hardhat. This can lead to unexpected behavior. See https://hardhat.org/nodejs-versions




  FundMe
    constructor
      ✔ Sets the aggregator addresses correctly
    fund
      1) Fails if you do not send enough ETH!!


  1 passing (11s)
  1 failing

  1) FundMe
       fund
         Fails if you do not send enough ETH!!:
     AssertionError: Expected transaction to be reverted with reason 'You need to spend more ETH!', but it reverted with reason 'Did not send enough!'
      at Context.<anonymous> (test/unit/FundMe.test.js:30:13)



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

To resolve this issue, your message in
```javascript
require(
            msg.value.getConversionRate(priceFeed) >= MINIMUM_USD,
            "Did not send enough!"
        );

To resolve this issue, your message in

require(
            msg.value.getConversionRate(priceFeed) >= MINIMUM_USD,
            "Did not send enough!"
        );

should match with message which is in

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

I hope it is helpful for those who tore their hair just because of this problem.

Thanks.

@Levin932
Copy link

Levin932 commented Jul 5, 2024

yes , fund fund function in contract code , the require message need same to revertedWith massage

function fund() public payable {
        require(msg.value.getConversionRate(priceFeed) >= MINIMUM_USD, "You need to spend more ETH!");
        // require(PriceConverter.getConversionRate(msg.value) >= MINIMUM_USD, "You need to spend more ETH!");
        addressToAmountFunded[msg.sender] += msg.value;
        funders.push(msg.sender);
    }
    
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!"
            )
        })
    })


Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants