Closed Sabnock01 closed 2 years ago
We haven't investigated and I haven't been using the feature. @odyslam @mds1 would know if there's a reason, otherwise PR welcome!
Did a bit more digging and it looks like while they are correctly encoded for the types bytes32
and bytes32[]
, they aren't for the others.
The encoding for a bytes6[]
containing 3 elements 0x111111111111
, 0x222222222222
, and 0x333333333333
would be:
0x00000000000000000000000000000000000000000000000000000000000000200000000000000000000000000000000000000000000000000000000000000003111111111111000000000000000000000000000000000000000000000000000022222222222200000000000000000000000000000000000000000000000000003333333333330000000000000000000000000000000000000000000000000000
Yet parseJson
returns instead:
0x00000000000000000000000000000000000000000000000000000000000000200000000000000000000000000000000000000000000000000000000000000003000000000000000000000000000000000000000000000000000000000000006000000000000000000000000000000000000000000000000000000000000000a000000000000000000000000000000000000000000000000000000000000000e0000000000000000000000000000000000000000000000000000000000000000611111111111100000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000006222222222222000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000063333333333330000000000000000000000000000000000000000000000000000
Hey @Sabnock01,
Sorry for not responding over Twitter. Devcon has been overly chaotic.
The cheatcode doesn't recognize bytesbytes
, except if it's len=32, which is returned as a bytes32. The reason is that bytes32 is a very common structure while most bytes
It's not possible to know whether something should be a bytes[], where the len of the bytes happens to be 6 or bytes6[]. The only reason we make the explicit decision is with bytes32, for the reason I mentioned above.
I would advise simply parsing it as bytes[] and then making a helper function (as I have created in forge-std for other things) that goes over the array and converts it to the type you want.
I think it's better to keep the cheatcode as-is
Ah, I hadn't yet thought of that but it's super easy. Will close the issue now. Thank you for clearing that up!
Component
Forge
Have you ensured that all of these are up to date?
What version of Foundry are you on?
forge 0.2.0 (28312e7 2022-10-13T00:10:05.477412592Z)
What command(s) is the bug in?
No response
Operating System
Linux
Describe the bug
JSON parsing does not appear to work for values of types
bytes6
andbytes6[]
.When trying to parse either of these types with
forge test
it results in anEVM Error: Revert
. I noticed there's no tests forbytes<x>
in the tests inJson.t.sol
and that there's no helper functions for this type in theStdJson
library inforge-std
.Is there some reason that it can't be used for this type?