-
Notifications
You must be signed in to change notification settings - Fork 1.4k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Add revert matchers #2652
Add revert matchers #2652
Conversation
|
733f7f7
to
8e16667
Compare
HH-583 Detect errors that don't come from a reverted transaction, if possible
Something like this will pass now:
This is important if a transaction fails for some reason unrelated to the actual transaction execution. One option is to check if there's |
5c14654
to
21304fc
Compare
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Still not finished reviewing everything, but wanted to ship you the comments I already have.
packages/hardhat-chai-matchers/test/fixture-projects/hardhat-project/contracts/Matchers.sol
Outdated
Show resolved
Hide resolved
packages/hardhat-chai-matchers/test/fixture-projects/hardhat-project/contracts/Matchers.sol
Outdated
Show resolved
Hide resolved
packages/hardhat-chai-matchers/src/reverted/revertedWithCustomError.ts
Outdated
Show resolved
Hide resolved
packages/hardhat-chai-matchers/src/reverted/revertedWithCustomError.ts
Outdated
Show resolved
Hide resolved
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I love the way you validate the subject in the .reverted
matcher, but is there a reason why you don't do that same validation in the other matchers?
packages/hardhat-chai-matchers/test/reverted/revertedWithCustomError.ts
Outdated
Show resolved
Hide resolved
packages/hardhat-chai-matchers/src/reverted/revertedWithPanic.ts
Outdated
Show resolved
Hide resolved
packages/hardhat-chai-matchers/src/reverted/revertedWithoutReasonString.ts
Outdated
Show resolved
Hide resolved
packages/hardhat-chai-matchers/test/reverted/revertedWithoutReasonString.ts
Show resolved
Hide resolved
packages/hardhat-chai-matchers/test/reverted/revertedWithoutReasonString.ts
Outdated
Show resolved
Hide resolved
packages/hardhat-chai-matchers/test/reverted/revertedWithoutReasonString.ts
Outdated
Show resolved
Hide resolved
8e41d10
to
0887967
Compare
Otherwise, the tests crash after a while for some reason that seems related to undici.
221867d
to
bf50263
Compare
revertedWithPanic
The
.revertedWithPanic
matcher can be used in two ways:This is different than
revertedWith
, which always expects a reason string. I did it that way because adding a reason string to an assertion is quite straightforward, and very useful. On the other hand, adding the proper panic code has more friction, and it seems to me that some users might just want to check that a call panics without checking why.Closes HH-554
Closes HH-579
Closes HH-580
Closes HH-582
Closes HH-583