Waffle: `to.be.reverted` does not work
I followed the exact syntax in the docs and receive this output.
AssertionError: Expected transaction to be reverted
Expected :not reverted
Actual :reverted
It seems backwards. I can confirm that the tx was reverted. Other expect properties like to.emit seems to work. There is no difference in how I call them. I’m using a Web3Provider connected to an external ganache-cli client.
About this issue
- Original URL
- State: closed
- Created 5 years ago
- Comments: 31 (7 by maintainers)
Commits related to this issue
- fix awaits when checking for reverts (TrueFiEng/Waffle#95) — committed to synapsecns/synapse-contracts by trajan0x 2 years ago
- fix awaits when checking for reverts (TrueFiEng/Waffle#95) — committed to synapsecns/synapse-contracts by trajan0x 2 years ago
- fix awaits when checking for reverts (TrueFiEng/Waffle#95) — committed to synapsecns/synapse-contracts by trajan0x 2 years ago
Found the solution to be the following: instead of
use
Please re-open.
This is correct, if you look at the page for Waffle Chai matchers only the BigNumbers matchers use
expect(await), all other matchers are shown usingawait expect().for some reason doing this works:
In my case doing this is the only way Token.method() actually will work for any other assertions.
I’m using a forked version of ethereum mainnet with hardhat.
Same for
to.be.revertedandto.be.revertedWith(message)I’m afraid.I am 95% this has something to do with the hardhat evm – as the revert statements do work when testing against just a locally deployed evm using a jsonrpc client
Getting rid of the await fixed it. expect(Token.method()).to.be.reverted worked for me as expected.
You’re an actual King…
Commented this on another thread https://github.com/OpenZeppelin/openzeppelin-test-helpers/issues/155#issuecomment-886127598
I was having a similar issue but was able to get it to work by:
chai-as-promisedethereum-wafflechaiwith the following initialization code:The issue I ran into was the
expectobject not having waffle’s matchers. Specifically,expectdidn’t know aboutrevertedwithout havingethereum-waffleinstalled andchaiinitialized withsolidityfromethereum-waffle.For me
.to.be.revertedWithworks, but the message string can be anything and it will still pass. By works I mean, if the method doesn’t revert, the test will fail. So it kind of works, but not fully.As for
.to.be.reverted, no proposed workarounds work…I’m using hardhat v2.2.1
@eherms This works…so simple. thanks!
Also having this issue when testing against rinkeby with hardhat. I find that the revert message is working as intended only for “revert” within a contract, but NOT for “require”.
Have you found a solution to this problem? I have tested both locally, on hardhat, on rinkeby, and to.be.reverted seems to be invisible for Waffle.
I’m getting the same result with
revertedWithwhere it reports a successful revert even if the message doesn’t match with what I’m expecting.Putting the
awaiton the entire expression worked for me; the revert is successfully expected and fails if the revert message does not match:await expect(someFn()).to.be.revertedWith('Some revrt message'); // intentional typo on 'revrt'results in
AssertionError: Expected transaction to be reverted with Some revrt message, but other exception was thrown: Error: VM Exception while processing transaction: reverted with reason string 'Some revert message'This is happening to me non-deterministically. Sometimes changing the test to call a different contract method and then changing it back fixes it. No idea what’s happening but happy to provide more feedback.
Fixed with PR #96