Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat(abi): Implement UIfmt for DSTest console logs #10185

Merged
merged 1 commit into from
Apr 9, 2025
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
43 changes: 22 additions & 21 deletions crates/evm/abi/src/console/ds.rs
Original file line number Diff line number Diff line change
Expand Up @@ -4,78 +4,79 @@ use super::{format_units_int, format_units_uint};
use alloy_primitives::hex;
use alloy_sol_types::sol;
use derive_more::Display;
use foundry_common_fmt::UIfmt;
use itertools::Itertools;

// TODO: Use `UiFmt`
// Using UIfmt for consistent and user-friendly formatting

sol! {
#[sol(abi)]
#[derive(Display)]
interface Console {
#[display("{val}")]
#[display("{}", val.pretty())]
event log(string val);

#[display("{}", hex::encode_prefixed(val))]
event logs(bytes val);

#[display("{val}")]
#[display("{}", val.pretty())]
event log_address(address val);

#[display("{val}")]
#[display("{}", val.pretty())]
event log_bytes32(bytes32 val);

#[display("{val}")]
#[display("{}", val.pretty())]
event log_int(int val);

#[display("{val}")]
#[display("{}", val.pretty())]
event log_uint(uint val);

#[display("{}", hex::encode_prefixed(val))]
event log_bytes(bytes val);

#[display("{val}")]
#[display("{}", val.pretty())]
event log_string(string val);

#[display("[{}]", val.iter().format(", "))]
#[display("[{}]", val.iter().map(|v| v.pretty()).format(", "))]
event log_array(uint256[] val);

#[display("[{}]", val.iter().format(", "))]
#[display("[{}]", val.iter().map(|v| v.pretty()).format(", "))]
event log_array(int256[] val);

#[display("[{}]", val.iter().format(", "))]
#[display("[{}]", val.iter().map(|v| v.pretty()).format(", "))]
event log_array(address[] val);

#[display("{key}: {val}")]
#[display("{}: {}", key.pretty(), val.pretty())]
event log_named_address(string key, address val);

#[display("{key}: {val}")]
#[display("{}: {}", key.pretty(), val.pretty())]
event log_named_bytes32(string key, bytes32 val);

#[display("{key}: {}", format_units_int(val, decimals))]
#[display("{}: {}", key.pretty(), format_units_int(val, decimals))]
event log_named_decimal_int(string key, int val, uint decimals);

#[display("{key}: {}", format_units_uint(val, decimals))]
#[display("{}: {}", key.pretty(), format_units_uint(val, decimals))]
event log_named_decimal_uint(string key, uint val, uint decimals);

#[display("{key}: {val}")]
#[display("{}: {}", key.pretty(), val.pretty())]
event log_named_int(string key, int val);

#[display("{key}: {val}")]
#[display("{}: {}", key.pretty(), val.pretty())]
event log_named_uint(string key, uint val);

#[display("{key}: {}", hex::encode_prefixed(val))]
#[display("{}: {}", key.pretty(), hex::encode_prefixed(val))]
event log_named_bytes(string key, bytes val);

#[display("{key}: {val}")]
#[display("{}: {}", key.pretty(), val.pretty())]
event log_named_string(string key, string val);

#[display("{key}: [{}]", val.iter().format(", "))]
#[display("{}: [{}]", key.pretty(), val.iter().map(|v| v.pretty()).format(", "))]
event log_named_array(string key, uint256[] val);

#[display("{key}: [{}]", val.iter().format(", "))]
#[display("{}: [{}]", key.pretty(), val.iter().map(|v| v.pretty()).format(", "))]
event log_named_array(string key, int256[] val);

#[display("{key}: [{}]", val.iter().format(", "))]
#[display("{}: [{}]", key.pretty(), val.iter().map(|v| v.pretty()).format(", "))]
event log_named_array(string key, address[] val);
}
}
Expand Down
Loading