Skip to content

Commit cfba82c

Browse files
authored
feat: more flexible JSON parsing (#8345)
* support struct parsing * wip * support eip712 strings * feat: "vm.parseJsonType" * chore: docs * clippy * serialize * forge bind-json * make lib internal * fixes * fix docs * rm redundant filter * clippy * generate more helpers * add test * typo * refactor a bit * fmt * config section * add out arg * rm cfg(ignore) * increase depth for failing test * move proptest to workspace * use write * review fixes * fix tests * use GlobMatcher in config * fix tests * fmt
1 parent d0ba6a2 commit cfba82c

File tree

29 files changed

+1513
-119
lines changed

29 files changed

+1513
-119
lines changed

Cargo.lock

Lines changed: 1 addition & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

Cargo.toml

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -261,3 +261,5 @@ tower = "0.4"
261261
tower-http = "0.5"
262262
# soldeer
263263
soldeer = "0.2.17"
264+
265+
proptest = "1"

crates/cheatcodes/Cargo.toml

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -53,3 +53,6 @@ semver.workspace = true
5353
rustc-hash.workspace = true
5454
dialoguer = "0.11.0"
5555
rand = "0.8"
56+
57+
[dev-dependencies]
58+
proptest.workspace = true

crates/cheatcodes/assets/cheatcodes.json

Lines changed: 100 additions & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

crates/cheatcodes/spec/src/vm.rs

Lines changed: 24 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1878,6 +1878,19 @@ interface Vm {
18781878
pure
18791879
returns (bytes32[] memory);
18801880

1881+
/// Parses a string of JSON data and coerces it to type corresponding to `typeDescription`.
1882+
#[cheatcode(group = Json)]
1883+
function parseJsonType(string calldata json, string calldata typeDescription) external pure returns (bytes memory);
1884+
/// Parses a string of JSON data at `key` and coerces it to type corresponding to `typeDescription`.
1885+
#[cheatcode(group = Json)]
1886+
function parseJsonType(string calldata json, string calldata key, string calldata typeDescription) external pure returns (bytes memory);
1887+
/// Parses a string of JSON data at `key` and coerces it to type array corresponding to `typeDescription`.
1888+
#[cheatcode(group = Json)]
1889+
function parseJsonTypeArray(string calldata json, string calldata key, string calldata typeDescription)
1890+
external
1891+
pure
1892+
returns (bytes memory);
1893+
18811894
/// Returns an array of all the keys in a JSON object.
18821895
#[cheatcode(group = Json)]
18831896
function parseJsonKeys(string calldata json, string calldata key) external pure returns (string[] memory keys);
@@ -1968,6 +1981,17 @@ interface Vm {
19681981
function serializeBytes(string calldata objectKey, string calldata valueKey, bytes[] calldata values)
19691982
external
19701983
returns (string memory json);
1984+
/// See `serializeJson`.
1985+
#[cheatcode(group = Json)]
1986+
function serializeJsonType(string calldata typeDescription, bytes memory value)
1987+
external
1988+
pure
1989+
returns (string memory json);
1990+
/// See `serializeJson`.
1991+
#[cheatcode(group = Json)]
1992+
function serializeJsonType(string calldata objectKey, string calldata valueKey, string calldata typeDescription, bytes memory value)
1993+
external
1994+
returns (string memory json);
19711995

19721996
// NOTE: Please read https://book.getfoundry.sh/cheatcodes/write-json to understand how
19731997
// to use the JSON writing cheats.

crates/cheatcodes/src/error.rs

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -286,6 +286,7 @@ macro_rules! impl_from {
286286

287287
impl_from!(
288288
alloy_sol_types::Error,
289+
alloy_dyn_abi::Error,
289290
alloy_primitives::SignatureError,
290291
FsPathError,
291292
hex::FromHexError,

0 commit comments

Comments
 (0)