Skip to content

Commit

Permalink
feat(cheatcode): UintToHex cheatcode (#7767)
Browse files Browse the repository at this point in the history
uintToHex cheatcode
  • Loading branch information
kamuik16 authored Apr 23, 2024
1 parent 6ff4385 commit 21dfde4
Show file tree
Hide file tree
Showing 6 changed files with 36 additions and 0 deletions.
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

0 comments on commit 21dfde4

Please sign in to comment.