-
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
hardhat chai matchers: emit(...).withArgs
does not properly work with BigInt closeTo
in the callback
#4934
Comments
.withArgs
does not properly work with BigNumber closeTo
assertions.withArgs
does not properly work with BigInt closeTo
assertions
.withArgs
does not properly work with BigInt closeTo
assertionsemit(...).withArgs
does not properly work with BigInt closeTo
assertions
emit(...).withArgs
does not properly work with BigInt closeTo
assertionsemit(...).withArgs
does not properly work with BigInt closeTo
in the callback
@ChristopherDedominici bump on this |
Hi @WardenJakx. I just took a look at the code.
The function is not returning a boolean value, see the docs here If you modify the function to return true, it should work. In case the
|
Hi, thanks for the response. This code block worked with previous versions of hardhat and ethers. Also, any callback for events will fail even if it just returns true so unfortunately your proposed fix does not solve the problem Example:
will still fail @ChristopherDedominici |
Hi @WardenJakx, thanks for getting back to me. Can I ask in which version of Hardhat your code was working? Also, in your last message, you mentioned that your code does not even work if you return true, which makes me wonder: is it possible that there is some logic in your code triggering this weird behavior? Because I cannot reproduce the failure when I return |
Hi @ChristopherDedominici, thanks for the suggestion. I tried it on my codebase and it worked properly. It seems like there was an unwritten change as before i could pass cases where (num => expect(...)) was all the logic there was in the callback However, with some change, this is no longer possible unless you do num => { expect(...); return true; } Not sure if this is a change with the hardhat library or chai library but if it is hardhat related it should be documented somewhere to help others facing this migration issue |
Version of Hardhat
2.20.1
What happened?
I am upgrading my codebase from using ethers v5 and hardhat-toolbox v2 to ethers v6 and hardhat toolbox v4. I have most of the codebase updated, but there is a recurring error with event based tests that keep failing unless I remove the
withArgs
part of the chainIve tried different versions of the packages responsible for this upgrade but still run into issues. Ive run hardhat clean, deleted node_modules, but still run into the issue
When doing
tx.to.emit(...).withArgs( ... (value:bigint) => expect(value).to.be.closeTo(value, delta) )
, the withArgs will not work if with the closeTo callback (even though it should pass)eg:
Reverts with
However, the amount parameter is exactly 1 ETH so this should be passing as true.
If i do
it passes successfully
Is this possibly related to chaijs/chai#1606 ?
Minimal reproduction steps
tx.to.emit(...).withArgs(
...
(amount:bigint) => expect(amount).to.be.closeTo(parseEther("1"), parseUnits("1", "gwei"))
)
Search terms
hardhat-chai-matchers, assertions, closeTo
The text was updated successfully, but these errors were encountered: