0

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

2 Answers 2

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.

1
  • 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 at 21:33
0

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

Ran this again and fixed the issue.

Now test 1 passes but test returns the following error when it gets to

await expect(fundMe.fund()).to.be.revertedWith("You need to spend more ETH!");

ERROR:

  1) FundMe
       fund
         Fails if you don't send enough ETH:
     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
1
  • Create a new question, if you add a follow up question as answer it won't be noticed.
    – Ismael
    Jun 14 at 13:49

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

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