smartcontractkit / full-blockchain-solidity-course-js

Learn Blockchain, Solidity, and Full Stack Web3 Development with Javascript
12.4k stars 2.98k forks source link

Shouldn't revertedWithCustomError() be used instead of revertedWith()? #5521

Closed morbius13 closed 1 year ago

morbius13 commented 1 year ago

Describe the enhancement

I kept getting errors when I used revertedWith() on custom errors. Only when I replaced it to revertedWithCustomError() it worked.

For example:

Instead of:

it("reverts when checkupkeep is false", async () => {
       await expect(
          raffle.performUpkeep([])
       ).to.be.revertedWith("Raffle__UpkeepNotNeeded");
});

This:

 it("reverts when checkupkeep is false", async () => {
        await expect(
           raffle.performUpkeep([])
        ).to.be.revertedWithCustomError(raffle, "Raffle__UpkeepNotNeeded");
});
aaankeet commented 1 year ago

revertedWith() takes one argument i.e some error string that you want to assert for while revertedWithCustomError() takes two argument contract and CustomError

alymurtazamemon commented 1 year ago

@morbius13 Yes, in the latest versions of hardhat errors are considered as Custom Error and for handling them we need to use revertedWithCustomError()