1

AssertionError: Expected transaction to be reverted with You need to spend more ETH!, but other exception was thrown: Error: Transaction reverted: function returned an unexpected amount of data

I was getting this error when running test for fundMe() around 11:20:38 of the video

describe("FundMe", async function () {
  let fundMe;
  let deployer;
  let MockV3Aggregator;
  beforeEach(async function () {
    deployer = (await getNamedAccounts()).deployer;
    await deployments.fixture(["all"]);
    fundMe = await ethers.getContract("FundMe", deployer);
    MockV3Aggregator = await ethers.getContract("MockV3Aggregator", deployer);
  });

  describe("constructor", async function () {
    it("sets the aggregator addresses correctly", async function () {
      const response = await fundMe.priceFeed();
      assert.equal(response, MockV3Aggregator.address);
    });
  });
  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!"
      );
    });
  });
});

After some research it seemed that the issue could ber esolved by downloading @nomicslabs/hardhat-waffle from hardhat docs [https://hardhat.org/plugins/nomiclabs-hardhat-waffle]

But after running the install I now get the following error running the above test

  1) FundMe
       "before each" hook for "sets the aggregator addresses correctly":
     TypeError: ethers.getContract is not a function

Any ideas of what could be the issue here? thank you!

0

4 Answers 4

5

yarn add --dev hardhat @nomiclabs/hardhat-ethers@npm:hardhat-deploy-ethers ethers

Ran this again and fixed the issue.

1
  • This was a solution for me also, forgot to run ethers deploy override of ethers so it didnt work and had same error.
    – Blissful
    Jul 25, 2022 at 14:39
0

[SOLVED]

I tried to modify the line so it reads: await expect(fundMe.fund()).to.be.reverted

Both tests seem to pass that way as you can see below image

So it is definitely the line but I still don't understand why adding the string causes the error, maybe I am missing a parameter or an import.

2
  • It's great to see that you were able to solve the issue by yourself, thanks for putting the answer here. Can you please next time open an issue at the actual repo instead of posting it here, because it's hard for the general audience to follow specific course' timestamps? Thanks :)
    – Andrej
    Jun 15, 2022 at 21:33
  • I did open a discussion but no one seemed to have a solution. Shared the solution there as well :) Jul 26, 2022 at 15:09
0

Two Solutions:

  1. If you use getContract, then use require("@nomiclabs/hardhat-ethers") in your hardhat.config.js file.
  2. If above does not work, then you might be using a newer version of hardhat, try getContractAt method instead.
0

For the future readers. In the newer hardhat versions, instead of address you should use target. For instance you should change mockV3Aggregator.address to mockV3Aggregator.target

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.