PatrickAlphaC / hardhat-fund-me-fcc

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

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

ZiJun0819 opened this issue · comments

commented
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"
            )
        })

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

commented

Awesome find, this solved my issue as well

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"
            )
        })