Skip to content

Commit a540539

Browse files
odyslamgakonst
authored andcommitted
fix: address false positive (foundry-rs#2914)
* fix: address false positive * fix: refactor for unstable warning * fix: correct encoding of null values * chore: add test for non-address H160 * fix: correct use-case to be string, not bytes * chore: forge fmt Co-authored-by: Georgios Konstantopoulos <[email protected]>
1 parent 1e4785d commit a540539

File tree

4 files changed

+538
-7
lines changed

4 files changed

+538
-7
lines changed

evm/src/executor/inspector/cheatcodes/ext.rs

Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -239,19 +239,19 @@ fn value_to_token(value: &Value) -> Result<Token, Token> {
239239
if let Some(boolean) = value.as_bool() {
240240
Ok(Token::Bool(boolean))
241241
} else if let Some(string) = value.as_str() {
242-
// If it can decoded as an address, it's an address
243-
if let Ok(addr) = H160::from_str(string) {
244-
Ok(Token::Address(addr))
245-
} else if let Some(val) = string.strip_prefix("0x") {
246-
// If incornrect length, pad 0 at the beginning
247-
if hex::decode(val).is_ok() {
242+
if let Some(val) = string.strip_prefix("0x") {
243+
// If it can decoded as an address, it's an address
244+
if let Ok(addr) = H160::from_str(string) {
245+
Ok(Token::Address(addr))
246+
} else if hex::decode(val).is_ok() {
248247
// if length == 32 bytes, then encode as Bytes32, else Bytes
249248
Ok(if val.len() == 64 {
250249
Token::FixedBytes(Vec::from_hex(val).unwrap())
251250
} else {
252251
Token::Bytes(Vec::from_hex(val).unwrap())
253252
})
254253
} else {
254+
// If incornrect length, pad 0 at the beginning
255255
let arr = format!("0{}", val);
256256
Ok(Token::Bytes(Vec::from_hex(arr).unwrap()))
257257
}
@@ -271,7 +271,7 @@ fn value_to_token(value: &Value) -> Result<Token, Token> {
271271
object.values().map(|val| value_to_token(val).unwrap()).collect::<Vec<Token>>();
272272
Ok(Token::Tuple(values))
273273
} else if value.is_null() {
274-
Ok(Token::FixedBytes(Vec::with_capacity(32)))
274+
Ok(Token::FixedBytes(vec![0; 32]))
275275
} else {
276276
Err(Token::String("Could not decode field".to_string()))
277277
}

0 commit comments

Comments
 (0)