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

revertedWith().withArgs fails for uint values exceeding JavaScript's max int limit #785

Closed
iconofsin opened this issue Aug 9, 2022 · 2 comments · Fixed by #786
Closed
Labels
bug Something isn't working

Comments

@iconofsin
Copy link
Contributor

iconofsin commented Aug 9, 2022

Describe the bug

Capturing a revertsWith('customError').withArgs(n) where n is a BigNumber too large to be consumed by BigNumber.from as an integer (vs as a string, which would work) fails conversion and results in the following BigNumber error:

Error: overflow [ See: https://links.ethers.org/v5-errors-NUMERIC_FAULT-overflow ] (fault="overflow", operation="BigNumber.from", value=1000000000000000000, code=NUMERIC_FAULT, version=bignumber/5.6.0)

To Reproduce

  1. clone https://github.com/iconofsin/Waffle-revertsWith-withArgs-Overflow
  2. run yarn install
  3. run npx hardhat test

Software versions

  • ethereum-waffle 4.0.2
  • @nomiclabs/hardhat-waffle 2.0.3
  • hardhat 2.10.1
  • Package manager: yarn 1.22.10
  • Node version v16.3.0
  • Solidity version: > 0.8.4

Additional context
As a dirty workaround, I patched decodeHardhatError in waffle-chai/src/matchers/revertedWith.ts.
L68

context.args = [JSON.parse(`[${matches[2]}]`)];

->

context.args = [JSON.parse(`[${matches[2].replace(/(\b\d{15,}\b)/g, '"$1"')}]`)];

which essentially quotes any potential BigNumber.

This results in matcher working, but it's obviously not the way to solve the issue.

@iconofsin iconofsin added the bug Something isn't working label Aug 9, 2022
@rzadp
Copy link
Contributor

rzadp commented Aug 10, 2022

@iconofsin Do you have @nomiclabs/hardhat-ethers installed? What is it's version?

I added a test for it: #786
Which shows that the matcher works fine for:

  • hardhat@2.10.1
  • @nomiclabs/hardhat-ethers@2.1.0
  • @nomiclabs/hardhat-waffle@2.0.3

And fails (your error reproduced) for:

  • hardhat@2.9.2
  • @nomiclabs/hardhat-ethers@2.0.3
  • @nomiclabs/hardhat-waffle@2.0.3

But I have not been able to reproduce the error with hardhat@2.10.1, even with @nomiclabs/hardhat-ethers@2.0.3.

@iconofsin
Copy link
Contributor Author

iconofsin commented Aug 10, 2022

Per my package.json, the versions of these packages are as follows:

  "@nomiclabs/hardhat-ethers": "^2.1.0",
  "@nomiclabs/hardhat-waffle": "^2.0.3",
  "hardhat": "^2.10.1"

...and to confirm:

yarn list --pattern hardhat
yarn list v1.22.10
├─ @nomiclabs/hardhat-ethers@2.1.0
├─ @nomiclabs/hardhat-waffle@2.0.3
├─ @typechain/hardhat@6.1.2
└─ hardhat@2.10.1

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Something isn't working
Projects
None yet
Development

Successfully merging a pull request may close this issue.

2 participants