Skip to content
This repository has been archived by the owner on May 17, 2024. It is now read-only.

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

Open
alexchenyu opened this issue Jan 10, 2023 · 3 comments

Comments

@alexchenyu
Copy link

alexchenyu commented Jan 10, 2023

In FundMe.test.js, the code below will report the error:
Code:

              it("Only allows the owner to withdraw", async function () {
                  const accounts = await ethers.getSigners()
                  const fundMeConnectedContract = await fundMe.connect(
                      accounts[1]
                  )
                  await expect(
                      fundMeConnectedContract.withdraw()
                  ).to.be.revertedWith("FundMe__NotOwner")
              })

Error:
yarn hardhat test

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

New code:

        it("Only allows the owner to withdraw", async function() {
            const accounts = await ethers.getSigners()
            const attacker = accounts[1]
            const attackerConnectedContract = await fundMe.connect(attacker)
            await expect(
                attackerConnectedContract.withdraw()
            ).to.be.revertedWithCustomError(
                attackerConnectedContract,
                "FundMe__NotOwner"
            )
        })

@PatrickAlphaC maybe you can update your source code as well, thanks

@PatrickAlphaC
Copy link
Owner

PatrickAlphaC commented Jan 17, 2023

Ah, we'd need to update all the packages too. Thanks for this issue!

Any chance you want to make it?

@alexchenyu
Copy link
Author

Yes, would like to have a try

@BigTava
Copy link

BigTava commented Apr 11, 2023

This works, thanks!

Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
None yet
Projects
None yet
Development

No branches or pull requests

3 participants