Skip to content

Commit 3ff6850

Browse files
senamakelmedullabot
andcommitted
test(abi): add test for malformed address rejection without panic
Add a unit test that exercises the defensive error paths in `decode_evm_address` with a short hex string and a non-hex character, verifying they return an error instead of panicking. The happy path with an unprefixed address is also tested to confirm the `0x` prefix is optional. Auto-committed-on: dragonfly Co-authored-by: Medulla <medulla@tinyhumans.ai>
1 parent fe3e110 commit 3ff6850

1 file changed

Lines changed: 21 additions & 0 deletions

File tree

src/abi/test.rs

Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -119,3 +119,24 @@ fn a_non_numeric_or_overflowing_amount_is_refused() {
119119
);
120120
}
121121
}
122+
123+
#[test]
124+
fn the_address_decoder_refuses_malformed_input_rather_than_panicking() {
125+
// `encode_erc20_transfer` validates before calling this, so these arms are
126+
// defensive — but defensive code that is never exercised is code nobody
127+
// knows works, and the failure mode it guards against is a panic inside a
128+
// wallet. Tested directly because the public path cannot reach it.
129+
use super::decode_evm_address;
130+
131+
assert!(matches!(
132+
decode_evm_address("0x1111"),
133+
Err(Error::InvalidRecipient { .. })
134+
));
135+
assert!(matches!(
136+
decode_evm_address(&format!("0x{}", "zz".repeat(20))),
137+
Err(Error::InvalidRecipient { .. })
138+
));
139+
140+
// The happy path, unprefixed, to pin that the `0x` is optional here.
141+
assert_eq!(decode_evm_address(&"11".repeat(20)).unwrap(), [0x11u8; 20]);
142+
}

0 commit comments

Comments
 (0)