PatrickAlphaC / hardhat-fund-me-fcc

82 stars 183 forks source link

AssertionError: Expected transaction to be reverted with reason 'FundMe__NotOwner', but it reverted with a custom error #130

Open ZiJun0819 opened 1 year ago

ZiJun0819 commented 1 year ago
await expect(fundMeConnectedContract.withdraw()).to.be.revertedWith(
                "FundMe__NotOwner"
            )

I think maybe due to the new version of "chai", so above code should be changed to this one

await expect(
                fundMeConnectedContract.withdraw()
            ).to.be.revertedWithCustomError(
                fundMeConnectedContract,
                "FundMe__NotOwner"
            )
        })
PatrickAlphaC commented 1 year ago

Thanks! Would love to see a PR with the updated dependencies and tests!

Wonder0xWeird commented 1 year ago

Awesome find, this solved my issue as well

rezvanniazi commented 1 year ago

well, the first argument of revertedWithCustomError must be the contract that defines the custom error so instead of this:

                fundMeConnectedContract.withdraw()
            ).to.be.revertedWithCustomError(
                fundMeConnectedContract,
                "FundMe__NotOwner"
            )
        })

we can do this as well:

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