Skip to content

feat: more flexible JSON parsing #8345

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

Merged
merged 29 commits into from
Jul 11, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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
Loading