|
1 | | -use crate::{Cheatcode, Cheatcodes, CheatcodesExecutor, CheatsCtxt, DatabaseExt, Result, Vm::*}; |
| 1 | +use crate::{ |
| 2 | + json::json_value_to_token, Cheatcode, Cheatcodes, CheatcodesExecutor, CheatsCtxt, DatabaseExt, |
| 3 | + Result, Vm::*, |
| 4 | +}; |
2 | 5 | use alloy_dyn_abi::DynSolValue; |
3 | 6 | use alloy_primitives::{B256, U256}; |
4 | 7 | use alloy_provider::Provider; |
@@ -375,18 +378,25 @@ fn rpc_call(url: &str, method: &str, params: &str) -> Result { |
375 | 378 | let result = |
376 | 379 | foundry_common::block_on(provider.raw_request(method.to_string().into(), params_json)) |
377 | 380 | .map_err(|err| fmt_err!("{method:?}: {err}"))?; |
| 381 | + let result_as_tokens = convert_to_bytes( |
| 382 | + &json_value_to_token(&result).map_err(|err| fmt_err!("failed to parse result: {err}"))?, |
| 383 | + ); |
378 | 384 |
|
379 | | - let result_as_tokens = match crate::json::json_value_to_token(&result) |
380 | | - .map_err(|err| fmt_err!("failed to parse result: {err}"))? |
381 | | - { |
382 | | - // Convert fixed bytes to bytes to prevent encoding issues. |
| 385 | + Ok(result_as_tokens.abi_encode()) |
| 386 | +} |
| 387 | + |
| 388 | +/// Convert fixed bytes and address values to bytes in order to prevent encoding issues. |
| 389 | +fn convert_to_bytes(token: &DynSolValue) -> DynSolValue { |
| 390 | + match token { |
| 391 | + // Convert fixed bytes to prevent encoding issues. |
383 | 392 | // See: <https://github.com/foundry-rs/foundry/issues/8287> |
384 | 393 | DynSolValue::FixedBytes(bytes, size) => { |
385 | | - DynSolValue::Bytes(bytes.as_slice()[..size].to_vec()) |
| 394 | + DynSolValue::Bytes(bytes.as_slice()[..*size].to_vec()) |
386 | 395 | } |
387 | 396 | DynSolValue::Address(addr) => DynSolValue::Bytes(addr.to_vec()), |
388 | | - val => val, |
389 | | - }; |
390 | | - |
391 | | - Ok(result_as_tokens.abi_encode()) |
| 397 | + // Convert tuple values to prevent encoding issues. |
| 398 | + // See: <https://github.com/foundry-rs/foundry/issues/7858> |
| 399 | + DynSolValue::Tuple(vals) => DynSolValue::Tuple(vals.iter().map(convert_to_bytes).collect()), |
| 400 | + val => val.clone(), |
| 401 | + } |
392 | 402 | } |
0 commit comments