You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
When using the sequence await expect(method()).to.be.revertedWith() will miss a revert in a test script.
I am attaching the picture to illustrate the bug. I am also attaching sample project to show the bug. Many test scripts (including the automatic example created by Hardhat itself when initializing the project) first place await keyword, then expect keyword, but using await before expect may lead to incorrect evaluation of unit tests.
Hey @nuliknol, I think everything is working as expected. I'll try to explain what's going on here.
First, your method() function reverts with a "You can't run me" reason string. This means that if you add an assertion for that:
awaitexpect(sample.method()).to.be.revertedWith("You can't run me");
then the test should pass (and it does). You seem to be expecting the test to fail, but that doesn't make sense to me.
The real question is why one of the tests doesn't pass. The reason is that when you do this:
expect(awaitsample.method()).to.be.revertedWith("You can't run me");
the first thing that will be evaluated is await sample.method(). But this function returns a rejected promise, because the method reverts. If you await a rejected promise, and error is thrown; if an error is thrown within a test, then the test fails. await expect(sample.method(), on the other hand, doesn't await the rejected promise, and it handles it internally, so in that case that's not a problem.
Version of Hardhat
2.19.5
What happened?
When using the sequence
await expect(method()).to.be.revertedWith()
will miss a revert in a test script.I am attaching the picture to illustrate the bug. I am also attaching sample project to show the bug. Many test scripts (including the automatic example created by Hardhat itself when initializing the project) first place
await
keyword, thenexpect
keyword, but using await before expect may lead to incorrect evaluation of unit tests.Bug illustration in a github project, just compile and run: https://github.com/nuliknol/await-expect
await-expect.tar.gz
Minimal reproduction steps
already included
Search terms
No response
The text was updated successfully, but these errors were encountered: