0

Why it doesn't work when I use...

$ yarn hardhat --verison 2.10.2
await expect(fundMeConnectedContract.withdraw()
            ).to.be.revertedWith(
                "FundMe__NotOwner"
            )

but this worked

await expect(fundMeConnectedContract.withdraw()
            ).to.be.revertedWithCustomError(
                fundMeConnectedContract,
                "FundMe__NotOwner"
            )

Has the hardhat custom error handling changed since May this year..??

1

3 Answers 3

0

the former is matching against the revert message.

e.g.

.to.be.revertedWith("go away")

would work with this code

require(msg.sender == owner,"go away");

the latter is just matching against the custom error

0
    await expect(fundMeConnectedContract.withdraw()).to.be.revertedWithCustomError(fundMe, "FundMe__NotOwner")

Hey , buddy if you follow exactly the tutorial. try revertedWithCustomError and add fundMe, "FundMe__NotOwner".

Line explanation :

  • fundMe will be your deployed contract
  • FundMe__NotOwner the custom error from fundMe.sol

Do also check if you using single or double underscore for FundMe__NotOwner in fundMe.sol

I hope this would help if you still not found out the solution

0

I hope you got an Answer already, if not just try to delete the custom error passed to revertedWithCustomError and write it down yourself. I copie-pasted it and it could not recognise as defined custom-Error in the contract.

Your Answer

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

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