Skip to content
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

to.be.reverted to not work as expected in your example #79

Closed
InfectedIsm opened this issue Nov 26, 2022 · 2 comments
Closed

to.be.reverted to not work as expected in your example #79

InfectedIsm opened this issue Nov 26, 2022 · 2 comments

Comments

@InfectedIsm
Copy link

Hi, I've used your boilerplate for a personal project, but I found out that VM revert are not caught correctly.

Reproduce steps :

await expect(
hardhatToken.connect(addr1).transfer(owner.address, 1)
).to.be.revertedWith("Not enough tokens");

Remove to.be.revertedWith :

      await expect(
        hardhatToken.connect(addr1).transfer(owner.address, 1)
      );

Test still passes :
✔ Should fail if sender doesn't have enough tokens

Any idea why ? I found your boilerplate code really useful, too bad I cannot use it

Thanks

@fvictorio
Copy link
Member

fvictorio commented Nov 27, 2022

If you do await expect(...something...), the promise returned inside the expect will be captured by Chai. If you then don't assert anything on that promise, then the result will be discarded and the test will pass.

To check that the transaction indeed fails, remove the expect too:

await hardhatToken.connect(addr1).transfer(owner.address, 1)

@InfectedIsm
Copy link
Author

Thanks a lot for taking time to answer ! I had misunderstood its behavior

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

No branches or pull requests

2 participants