diff --git a/evm-adapters/src/sputnik/cheatcodes/cheatcode_handler.rs b/evm-adapters/src/sputnik/cheatcodes/cheatcode_handler.rs index cdd26b12e..c72d8594b 100644 --- a/evm-adapters/src/sputnik/cheatcodes/cheatcode_handler.rs +++ b/evm-adapters/src/sputnik/cheatcodes/cheatcode_handler.rs @@ -113,11 +113,17 @@ pub(crate) fn convert_log(log: Log) -> Option { LogNamedBytes32Filter(inner) => { format!("{}: 0x{}", inner.key, hex::encode(inner.val)) } - LogNamedDecimalIntFilter(inner) => format!( - "{}: {:?}", - inner.key, - ethers::utils::parse_units(inner.val, inner.decimals.as_u32()).unwrap() - ), + LogNamedDecimalIntFilter(inner) => { + let val: String = inner.val.to_string(); + let neg = val.trim().starts_with('-'); + let val = val.trim().trim_start_matches('-'); + format!( + "{}: {}{:?}", + inner.key, + if neg { "-" } else { "" }, + ethers::utils::parse_units(val, inner.decimals.as_u32()).unwrap() + ) + } LogNamedDecimalUintFilter(inner) => { format!( "{}: {}", @@ -1701,6 +1707,7 @@ mod tests { "addr: 0x2222222222222222222222222222222222222222", "key: 0x41b1a0649752af1b28b3dc29a1556eee781e4a4c3a1f7f53f90fa834de098c4d", "key: 123000000000000000000", + "key: -123000000000000000000", "key: 0.000000000000001234", "key: 123", "key: 1234", diff --git a/evm-adapters/testdata/DebugLogs.sol b/evm-adapters/testdata/DebugLogs.sol index 146b0eb3f..400aa81ba 100644 --- a/evm-adapters/testdata/DebugLogs.sol +++ b/evm-adapters/testdata/DebugLogs.sol @@ -15,6 +15,7 @@ contract DebugLogs is DSTest { emit log_named_address("addr", 0x2222222222222222222222222222222222222222); emit log_named_bytes32("key", keccak256(abi.encodePacked("foo"))); emit log_named_decimal_int("key", 123, 18); + emit log_named_decimal_int("key", -123, 18); emit log_named_decimal_uint("key", 1234, 18); emit log_named_int("key", 123); emit log_named_uint("key", 1234);