Skip to content

feat(cast): add flag to disable alias #10924

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

Merged
merged 5 commits into from
Jul 7, 2025
Merged
Show file tree
Hide file tree
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
7 changes: 7 additions & 0 deletions crates/cast/src/cmd/call.rs
Original file line number Diff line number Diff line change
Expand Up @@ -85,6 +85,11 @@ pub struct CallArgs {
#[arg(long, default_value_t = false)]
trace: bool,

/// Disables the labels in the traces.
/// Can only be set with `--trace`.
#[arg(long, default_value_t = false, requires = "trace")]
disable_labels: bool,

/// Opens an interactive debugger.
/// Can only be used with `--trace`.
#[arg(long, requires = "trace")]
Expand Down Expand Up @@ -207,6 +212,7 @@ impl CallArgs {
labels,
data,
with_local_artifacts,
disable_labels,
..
} = self;

Expand Down Expand Up @@ -324,6 +330,7 @@ impl CallArgs {
with_local_artifacts,
debug,
decode_internal,
Some(disable_labels),
)
.await?;

Expand Down
1 change: 1 addition & 0 deletions crates/cast/src/cmd/run.rs
Original file line number Diff line number Diff line change
Expand Up @@ -286,6 +286,7 @@ impl RunArgs {
self.with_local_artifacts,
self.debug,
self.decode_internal,
None,
)
.await?;

Expand Down
102 changes: 102 additions & 0 deletions crates/cast/tests/cli/main.rs
Original file line number Diff line number Diff line change
Expand Up @@ -2611,6 +2611,108 @@ forgetest_async!(cast_call_custom_chain_id, |_prj, cmd| {
.assert_success();
});

// https://github.com/foundry-rs/foundry/issues/10848
forgetest_async!(cast_call_disable_labels, |prj, cmd| {
let (_, handle) = anvil::spawn(NodeConfig::test()).await;

foundry_test_utils::util::initialize(prj.root());
prj.add_source(
"Counter",
r#"
contract Counter {
uint256 public number;

function getBalance(address target) public returns (uint256) {
return target.balance;
}
}
"#,
)
.unwrap();

// Deploy counter contract.
cmd.args([
"script",
"--private-key",
"0xac0974bec39a17e36ba4a6b4d238ff944bacb478cbed5efcae784d7bf4f2ff80",
"--rpc-url",
&handle.http_endpoint(),
"--broadcast",
"CounterScript",
])
.assert_success();

// Override state, `number()` should return overridden value.
cmd.cast_fuse()
.args([
"call",
"0x5FbDB2315678afecb367f032d93F642f64180aa3",
"--rpc-url",
&handle.http_endpoint(),
"--override-state",
"0x5FbDB2315678afecb367f032d93F642f64180aa3:0x0:0x1234",
"number()(uint256)",
])
.assert_success()
.stdout_eq(str![[r#"
4660

"#]]);

// Override state, `number()` should return overridden value.
cmd.cast_fuse()
.args([
"call",
"0x5FbDB2315678afecb367f032d93F642f64180aa3",
"--labels",
"0x5FbDB2315678afecb367f032d93F642f64180aa3:WETH",
"--rpc-url",
&handle.http_endpoint(),
"--override-state",
"0x5FbDB2315678afecb367f032d93F642f64180aa3:0x0:0x1234",
"number()(uint256)",
"--trace",
])
.assert_success()
.stdout_eq(str![[r#"
Traces:
[2402] WETH::number()
└─ ← [Return] 0x0000000000000000000000000000000000000000000000000000000000001234


Transaction successfully executed.
[GAS]

"#]]);

// Override state, `number()` with `disable_labels`.
cmd.cast_fuse()
.args([
"call",
"0x5FbDB2315678afecb367f032d93F642f64180aa3",
"--labels",
"0x5FbDB2315678afecb367f032d93F642f64180aa3:WETH",
"--rpc-url",
&handle.http_endpoint(),
"--override-state",
"0x5FbDB2315678afecb367f032d93F642f64180aa3:0x0:0x1234",
"number()(uint256)",
"--trace",
"--disable-labels",
])
.assert_success()
.stdout_eq(str![[r#"
Traces:
[2402] 0x5FbDB2315678afecb367f032d93F642f64180aa3::number()
└─ ← [Return] 0x0000000000000000000000000000000000000000000000000000000000001234


Transaction successfully executed.
[GAS]

"#]]);
});

// https://github.com/foundry-rs/foundry/issues/10189
forgetest_async!(cast_call_custom_override, |prj, cmd| {
let (_, handle) = anvil::spawn(NodeConfig::test()).await;
Expand Down
4 changes: 3 additions & 1 deletion crates/cli/src/utils/cmd.rs
Original file line number Diff line number Diff line change
Expand Up @@ -343,6 +343,7 @@ pub async fn handle_traces(
with_local_artifacts: bool,
debug: bool,
decode_internal: bool,
disable_label: Option<bool>,
) -> Result<()> {
let (known_contracts, mut sources) = if with_local_artifacts {
let _ = sh_println!("Compiling project to generate artifacts");
Expand Down Expand Up @@ -373,7 +374,8 @@ pub async fn handle_traces(

let mut builder = CallTraceDecoderBuilder::new()
.with_labels(labels.chain(config_labels))
.with_signature_identifier(SignaturesIdentifier::from_config(config)?);
.with_signature_identifier(SignaturesIdentifier::from_config(config)?)
.with_label_disabled(disable_label.unwrap_or_default());
let mut identifier = TraceIdentifiers::new().with_etherscan(config, chain)?;
if let Some(contracts) = &known_contracts {
builder = builder.with_known_contracts(contracts);
Expand Down
19 changes: 18 additions & 1 deletion crates/evm/traces/src/decoder/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -89,6 +89,13 @@ impl CallTraceDecoderBuilder {
self
}

/// Sets the signature identifier for events and functions.
#[inline]
pub fn with_label_disabled(mut self, disable_alias: bool) -> Self {
self.decoder.disable_labels = disable_alias;
self
}

/// Sets the debug identifier for the decoder.
#[inline]
pub fn with_debug_identifier(mut self, identifier: DebugTraceIdentifier) -> Self {
Expand Down Expand Up @@ -143,6 +150,9 @@ pub struct CallTraceDecoder {

/// Optional identifier of individual trace steps.
pub debug_identifier: Option<DebugTraceIdentifier>,

/// Disable showing of labels.
pub disable_labels: bool,
}

impl CallTraceDecoder {
Expand Down Expand Up @@ -198,6 +208,8 @@ impl CallTraceDecoder {
verbosity: 0,

debug_identifier: None,

disable_labels: false,
}
}

Expand Down Expand Up @@ -263,6 +275,10 @@ impl CallTraceDecoder {
self.revert_decoder.push_error(error);
}

pub fn without_label(&mut self, disable: bool) {
self.disable_labels = disable;
}

fn collect_identified_addresses(&mut self, mut addrs: Vec<IdentifiedAddress<'_>>) {
addrs.sort_by_key(|identity| identity.address);
addrs.dedup_by_key(|identity| identity.address);
Expand Down Expand Up @@ -338,7 +354,8 @@ impl CallTraceDecoder {

/// Decodes a call trace.
pub async fn decode_function(&self, trace: &CallTrace) -> DecodedCallTrace {
let label = self.labels.get(&trace.address).cloned();
let label =
if self.disable_labels { None } else { self.labels.get(&trace.address).cloned() };

if trace.kind.is_any_create() {
return DecodedCallTrace { label, ..Default::default() };
Expand Down