Skip to content

Commit 2564718

Browse files
authored
test: add a test case for RevertDecoder (#10294)
1 parent 8f38753 commit 2564718

File tree

1 file changed

+32
-0
lines changed

1 file changed

+32
-0
lines changed

crates/evm/core/src/decode.rs

Lines changed: 32 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -245,6 +245,7 @@ fn trimmed_hex(s: &[u8]) -> String {
245245
#[cfg(test)]
246246
mod tests {
247247
use super::*;
248+
248249
#[test]
249250
fn test_trimmed_hex() {
250251
assert_eq!(trimmed_hex(&hex::decode("1234567890").unwrap()), "1234567890");
@@ -253,4 +254,35 @@ mod tests {
253254
"49207769736820727573742073757070…6865722d6b696e646564207479706573 (41 bytes)"
254255
);
255256
}
257+
258+
// https://github.com/foundry-rs/foundry/issues/10162
259+
#[test]
260+
fn partial_decode() {
261+
/*
262+
error ValidationFailed(bytes);
263+
error InvalidNonce();
264+
*/
265+
let mut decoder = RevertDecoder::default();
266+
decoder.push_error("ValidationFailed(bytes)".parse().unwrap());
267+
268+
/*
269+
abi.encodeWithSelector(ValidationFailed.selector, InvalidNonce.selector)
270+
*/
271+
let data = &hex!(
272+
"0xe17594de"
273+
"756688fe00000000000000000000000000000000000000000000000000000000"
274+
);
275+
assert_eq!(decoder.decode(data, None), "ValidationFailed(0x)");
276+
277+
/*
278+
abi.encodeWithSelector(ValidationFailed.selector, abi.encodeWithSelector(InvalidNonce.selector))
279+
*/
280+
let data = &hex!(
281+
"0xe17594de"
282+
"0000000000000000000000000000000000000000000000000000000000000020"
283+
"0000000000000000000000000000000000000000000000000000000000000004"
284+
"756688fe00000000000000000000000000000000000000000000000000000000"
285+
);
286+
assert_eq!(decoder.decode(data, None), "ValidationFailed(0x756688fe)");
287+
}
256288
}

0 commit comments

Comments
 (0)