-
Notifications
You must be signed in to change notification settings - Fork 1.8k
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
Broken JSON Parsing of Integers #3754
Comments
cc @odyslam |
Quoted integers are, by design, interpreted as strings and encoded as such. The solution is for the numbers to be type number in the JSON. Everything works as expected.
|
It works as expected up to values of I also don't love that you have to store numbers as type "number", since this causes issues with other tooling. For example ethers.js will throw if you try to parse a number type larger than JS's Perhaps we also need new |
IIRC, I settled for type number because it's a rabbit hole to parse "things" into numbers. It had a false positive with H160 (addresses), and it seemed cleaner to have it that way. I think it's a pretty decent assumption. The u64::MAX is probs a limitation that I should document. For the bytes, we had that discussion due to the 'gas' field a while back, if you remember, and we settled that it's best to leave byte numbers as bytes. The way to interpret a hex number would be to load it as type 'bytes' and then abi.decode it to a number. |
This make sense if you only have a single
It seems:
would not be too difficult to add and resolve the UX issues. @odyslam @apbendi @mattsse lmk what you all think Though, all that aside, still not sure the original question from @apbendi is resolved? 😅 In particular:
So potentially still a bug somewhere? |
@mds1, that sounds good. Will prioritize some time today to address these. Sorry for the delay folks |
Just wanted to chime in that I also encountered this and spent a good part of the day debugging. I found the error message pretty confusing. Would love to see this fixed! Edit: do we have any good workaround for now? Make all values string and call |
So, I spent quite some time exploring the best solution. The TL;DR is the following:
The rust code looks considerable dirtier with the coercion and would rather have the above one-liner in the stdJson |
Chatted with @odyslam a bit, here's what I think is the best path forward:
Let's still fix this. Then: Currently
The first case works for numbers of any size, and can be a helper in forge-std. The second case is riskier, as this can return the wrong value due to incorrect inference depending on the field format, and therefore we don't want users to use this. We can't force users to use the
|
I am on board with the above @mds1, and it should also be pretty clear in the rust code. I will probably use the The next steps are:
|
Component
Forge
Have you ensured that all of these are up to date?
What version of Foundry are you on?
forge 0.2.0 (b28119b 2022-11-23T00:17:21.324951Z)
What command(s) is the bug in?
No response
Operating System
macOS (Apple Silicon)
Describe the bug
Parsing quoted integers from a JSON file using
vm.parseJson
results in incorrect values at runtime. Attempting to parse non-quoted integers causes a revert.To see this, checkout the broken-json-inputs branch of the project. Copy the .env.template file to .env and add a private key to
DEPLOYER_PRIVATE_KEY=
. Runforge test
to see the failing tests.Relevant code:
Unquote the strings in the json file and run
forge test
. You'll receive the following error:The text was updated successfully, but these errors were encountered: