Skip to content

Commit

Permalink
feat: more flexible JSON parsing (#8345)
Browse files Browse the repository at this point in the history
* 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
  • Loading branch information
klkvr authored Jul 11, 2024
1 parent d0ba6a2 commit cfba82c
Show file tree
Hide file tree
Showing 29 changed files with 1,513 additions and 119 deletions.
1 change: 1 addition & 0 deletions Cargo.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 2 additions & 0 deletions Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -261,3 +261,5 @@ tower = "0.4"
tower-http = "0.5"
# soldeer
soldeer = "0.2.17"

proptest = "1"
3 changes: 3 additions & 0 deletions crates/cheatcodes/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -53,3 +53,6 @@ semver.workspace = true
rustc-hash.workspace = true
dialoguer = "0.11.0"
rand = "0.8"

[dev-dependencies]
proptest.workspace = true
100 changes: 100 additions & 0 deletions crates/cheatcodes/assets/cheatcodes.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

24 changes: 24 additions & 0 deletions crates/cheatcodes/spec/src/vm.rs
Original file line number Diff line number Diff line change
Expand Up @@ -1878,6 +1878,19 @@ interface Vm {
pure
returns (bytes32[] memory);

/// Parses a string of JSON data and coerces it to type corresponding to `typeDescription`.
#[cheatcode(group = Json)]
function parseJsonType(string calldata json, string calldata typeDescription) external pure returns (bytes memory);
/// Parses a string of JSON data at `key` and coerces it to type corresponding to `typeDescription`.
#[cheatcode(group = Json)]
function parseJsonType(string calldata json, string calldata key, string calldata typeDescription) external pure returns (bytes memory);
/// Parses a string of JSON data at `key` and coerces it to type array corresponding to `typeDescription`.
#[cheatcode(group = Json)]
function parseJsonTypeArray(string calldata json, string calldata key, string calldata typeDescription)
external
pure
returns (bytes memory);

/// Returns an array of all the keys in a JSON object.
#[cheatcode(group = Json)]
function parseJsonKeys(string calldata json, string calldata key) external pure returns (string[] memory keys);
Expand Down Expand Up @@ -1968,6 +1981,17 @@ interface Vm {
function serializeBytes(string calldata objectKey, string calldata valueKey, bytes[] calldata values)
external
returns (string memory json);
/// See `serializeJson`.
#[cheatcode(group = Json)]
function serializeJsonType(string calldata typeDescription, bytes memory value)
external
pure
returns (string memory json);
/// See `serializeJson`.
#[cheatcode(group = Json)]
function serializeJsonType(string calldata objectKey, string calldata valueKey, string calldata typeDescription, bytes memory value)
external
returns (string memory json);

// NOTE: Please read https://book.getfoundry.sh/cheatcodes/write-json to understand how
// to use the JSON writing cheats.
Expand Down
1 change: 1 addition & 0 deletions crates/cheatcodes/src/error.rs
Original file line number Diff line number Diff line change
Expand Up @@ -286,6 +286,7 @@ macro_rules! impl_from {

impl_from!(
alloy_sol_types::Error,
alloy_dyn_abi::Error,
alloy_primitives::SignatureError,
FsPathError,
hex::FromHexError,
Expand Down
Loading

0 comments on commit cfba82c

Please sign in to comment.