Skip to content

Commit b574cfe

Browse files
committed
fix(forge): reject opcodes for non-trace output
1 parent 08f8f8d commit b574cfe

3 files changed

Lines changed: 28 additions & 6 deletions

File tree

crates/evm/traces/src/lib.rs

Lines changed: 15 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -215,11 +215,21 @@ pub fn render_trace_arena_inner(
215215
if with_storage_changes {
216216
append_tempo_channel_storage_decodes(&mut tempo_changes, &resolved);
217217

218-
// Remove storage text that is already represented by an opcode line.
219-
for node in resolved.to_mut().nodes_mut() {
220-
for step in &mut node.trace.steps {
221-
if matches!(step.decoded.as_deref(), Some(DecodedTraceStep::Line(_))) {
222-
step.storage_change = None;
218+
let needs_dedup = resolved.as_ref().nodes().iter().any(|node| {
219+
node.trace.steps.iter().any(|step| {
220+
step.storage_change.is_some()
221+
&& matches!(step.decoded.as_deref(), Some(DecodedTraceStep::Line(_)))
222+
})
223+
});
224+
if needs_dedup {
225+
// Remove storage text that is already represented by an opcode line.
226+
for node in resolved.to_mut().nodes_mut() {
227+
for step in &mut node.trace.steps {
228+
if step.storage_change.is_some()
229+
&& matches!(step.decoded.as_deref(), Some(DecodedTraceStep::Line(_)))
230+
{
231+
step.storage_change = None;
232+
}
223233
}
224234
}
225235
}

crates/forge/src/cmd/test/mod.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -592,7 +592,7 @@ pub struct TestArgs {
592592
/// Accepts a comma-separated list of opcode names, e.g.
593593
/// `--opcodes SLOAD,MLOAD,SSTORE`. Names are in uppercase.
594594
/// Requires `-vvvvv` to render.
595-
#[arg(long, value_parser = parse_opcode, value_delimiter(','))]
595+
#[arg(long, value_parser = parse_opcode, value_delimiter(','), conflicts_with_all = ["json", "junit", "list"])]
596596
pub opcodes: Vec<OpCode>,
597597

598598
/// Print test summary table.

crates/forge/tests/cli/test_cmd/mod.rs

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3999,6 +3999,18 @@ Error: Not enough verbosity. Use -vvvvv to show opcodes.
39993999
"#]]);
40004000
});
40014001

4002+
forgetest_init!(opcodes_conflict_with_non_trace_outputs, |prj, cmd| {
4003+
prj.initialize_default_contracts();
4004+
for flag in ["--json", "--junit", "--list"] {
4005+
let output =
4006+
cmd.forge_fuse().args(["test", "-vvvvv", "--opcodes", "SLOAD", flag]).assert_failure();
4007+
let stderr = String::from_utf8_lossy(&output.get_output().stderr);
4008+
assert!(stderr.contains("--opcodes"), "stderr should mention --opcodes: {stderr}");
4009+
assert!(stderr.contains(flag), "stderr should mention {flag}: {stderr}");
4010+
assert!(stderr.contains("cannot be used with"), "stderr should explain conflict: {stderr}");
4011+
}
4012+
});
4013+
40024014
// Tests that the test file path is not swallowed by the --opcodes flag
40034015
forgetest_init!(opcodes_path_after_flag, |prj, cmd| {
40044016
prj.initialize_default_contracts();

0 commit comments

Comments
 (0)