-
Notifications
You must be signed in to change notification settings - Fork 2k
feat(cheatcodes
): add JSON / TOML parsing with default fallbacks
#8900
New issue
Have a question about this project? # for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “#”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? # to your account
Comments
yep, it makes sense |
We are currently using the following implementation function _readOr(string memory json, string memory key, uint256 defaultValue) internal view returns (uint256) {
return vm.keyExists(json, key) ? stdJson.readUint(json, key) : defaultValue;
} So not super opinionated on this needing to be a native cheat or not |
foundry-rs/forge-std#605 will add this functionality to forge-std, but without the native cheats. Therefore I transferred this issue to the upstream foundry repo. Once the native cheats are added we can simply replace the implementations of the new methods in |
cheatcodes
): add JSON / TOML parsing with default fallbacks
Mind if I take this issue? |
Would love to tackle this! |
Hola I'm Tobias. Can I take over this particular issue? I've recently learned Cairo and Rust plus I have contributed to some projects recently and I have experience in building web apps from handling projects In university |
It would be really convenient to be able to set default values in the JSON parsing helpers with a third argument that return the default value when the key is not present in the passed in JSON string.
An example:
This would be similar to the UX of
vm.envOr
which reads an env var and then returns the default value if it doesn't exist. I am not particular about using overloading or following theOr
suffix naming scheme. This would prevent parsing errors for when keys are not present in the JSON. I think it could be implemented by wrapping the low level vm JSON calls withtry/catch
The text was updated successfully, but these errors were encountered: