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 #132

Open alexchenyu opened 1 year ago

alexchenyu commented 1 year ago

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 commented 1 year ago

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

Any chance you want to make it?

alexchenyu commented 1 year ago

Yes, would like to have a try

BigTava commented 1 year ago

This works, thanks!