Skip to content

Commit

Permalink
fix: print actual length in bytes in trimmed_hex (#6919)
Browse files Browse the repository at this point in the history
  • Loading branch information
kcsongor committed Jan 27, 2024
1 parent 1839c72 commit 47e458b
Showing 1 changed file with 21 additions and 4 deletions.
25 changes: 21 additions & 4 deletions crates/evm/core/src/decode.rs
Original file line number Diff line number Diff line change
Expand Up @@ -124,11 +124,28 @@ pub fn maybe_decode_revert(
}

fn trimmed_hex(s: &[u8]) -> String {
let s = hex::encode(s);
let n = 32 * 2;
let n = 32;
if s.len() <= n {
s
hex::encode(s)
} else {
format!("{}…{} ({} bytes)", &s[..n / 2], &s[s.len() - n / 2..], s.len())
format!(
"{}…{} ({} bytes)",
&hex::encode(&s[..n / 2]),
&hex::encode(&s[s.len() - n / 2..]),
s.len()
)
}
}

#[cfg(test)]
mod tests {
use super::*;
#[test]
fn test_trimmed_hex() {
assert_eq!(trimmed_hex(&hex::decode("1234567890").unwrap()), "1234567890");
assert_eq!(
trimmed_hex(&hex::decode("492077697368207275737420737570706F72746564206869676865722D6B696E646564207479706573").unwrap()),
"49207769736820727573742073757070…6865722d6b696e646564207479706573 (41 bytes)"
);
}
}

0 comments on commit 47e458b

Please sign in to comment.