Skip to content
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

feat(cheatcode): UintToHex cheatcode #7767

Merged
merged 1 commit into from
Apr 23, 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
20 changes: 20 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.

5 changes: 5 additions & 0 deletions crates/cheatcodes/spec/src/vm.rs
Original file line number Diff line number Diff line change
Expand Up @@ -1865,6 +1865,11 @@ interface Vm {
returns (string memory json);
/// See `serializeJson`.
#[cheatcode(group = Json)]
function serializeUintToHex(string calldata objectKey, string calldata valueKey, uint256 value)
external
returns (string memory json);
/// See `serializeJson`.
#[cheatcode(group = Json)]
function serializeInt(string calldata objectKey, string calldata valueKey, int256 value)
external
returns (string memory json);
Expand Down
8 changes: 8 additions & 0 deletions crates/cheatcodes/src/json.rs
Original file line number Diff line number Diff line change
Expand Up @@ -248,6 +248,14 @@ impl Cheatcode for serializeBytes_1Call {
}
}

impl Cheatcode for serializeUintToHexCall {
fn apply(&self, state: &mut Cheatcodes) -> Result {
let Self { objectKey, valueKey, value } = self;
let hex = format!("0x{:x}", value);
serialize_json(state, objectKey, Some(valueKey), &hex)
}
}

impl Cheatcode for writeJson_0Call {
fn apply(&self, state: &mut Cheatcodes) -> Result {
let Self { json, path } = self;
Expand Down
1 change: 1 addition & 0 deletions crates/evm/traces/src/decoder/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -441,6 +441,7 @@ impl CallTraceDecoder {
"keyExistsJson" |
"serializeBool" |
"serializeUint" |
"serializeUintToHex" |
"serializeInt" |
"serializeAddress" |
"serializeBytes32" |
Expand Down
1 change: 1 addition & 0 deletions testdata/cheats/Vm.sol

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

1 change: 1 addition & 0 deletions testdata/default/cheats/Json.t.sol
Original file line number Diff line number Diff line change
Expand Up @@ -224,6 +224,7 @@ contract WriteJsonTest is DSTest {
vm.serializeBool(json1, "boolean", true);
vm.serializeInt(json2, "key2", -234);
vm.serializeUint(json2, "deploy", uint256(254));
vm.serializeUintToHex(json2, "hexUint", uint256(255));
string memory data = vm.serializeBool(json2, "boolean", true);
vm.serializeString(json2, "json1", data);
emit log(data);
Expand Down
Loading