Skip to content

Commit

Permalink
Change verbosity to > 4 for both cast and forge test, add test, fix ci
Browse files Browse the repository at this point in the history
  • Loading branch information
grandizzy committed Nov 27, 2024
1 parent ca94656 commit 85f9571
Show file tree
Hide file tree
Showing 10 changed files with 244 additions and 181 deletions.
356 changes: 189 additions & 167 deletions Cargo.lock

Large diffs are not rendered by default.

2 changes: 1 addition & 1 deletion crates/cast/bin/cmd/call.rs
Original file line number Diff line number Diff line change
Expand Up @@ -188,7 +188,7 @@ impl CallArgs {
evm_version,
debug,
decode_internal,
shell::verbosity() > 1,
shell::verbosity() > 4,
alphanet,
);

Expand Down
2 changes: 1 addition & 1 deletion crates/cast/bin/cmd/run.rs
Original file line number Diff line number Diff line change
Expand Up @@ -169,7 +169,7 @@ impl RunArgs {
evm_version,
self.debug,
self.decode_internal,
shell::verbosity() > 1,
shell::verbosity() > 4,
alphanet,
);
let mut env =
Expand Down
12 changes: 9 additions & 3 deletions crates/cast/tests/cli/main.rs
Original file line number Diff line number Diff line change
Expand Up @@ -64,7 +64,7 @@ Display options:
- 2 (-vv): Print logs for all tests.
- 3 (-vvv): Print execution traces for failing tests.
- 4 (-vvvv): Print execution traces for all tests, and setup traces for failing tests.
- 5 (-vvvvv): Print execution and setup traces for all tests.
- 5 (-vvvvv): Print execution and setup traces for all tests, including storage changes.
Find more information in the book: http://book.getfoundry.sh/reference/cast/cast.html
Expand Down Expand Up @@ -1714,7 +1714,7 @@ Transaction successfully executed.
"#]]);
});

// tests cast can decode traces when using project artifacts
// tests cast can decode traces when running with verbosity level > 4
forgetest_async!(show_state_changes_in_traces, |prj, cmd| {
let (api, handle) = anvil::spawn(NodeConfig::test()).await;

Expand Down Expand Up @@ -1754,7 +1754,13 @@ forgetest_async!(show_state_changes_in_traces, |prj, cmd| {

// Assert cast with verbosity displays storage changes.
cmd.cast_fuse()
.args(["run", format!("{tx_hash}").as_str(), "-vv", "--rpc-url", &handle.http_endpoint()])
.args([
"run",
format!("{tx_hash}").as_str(),
"-vvvvv",
"--rpc-url",
&handle.http_endpoint(),
])
.assert_success()
.stdout_eq(str![[r#"
Executing previous transactions from the block.
Expand Down
2 changes: 1 addition & 1 deletion crates/cli/src/opts/global.rs
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@ pub struct GlobalOpts {
/// - 2 (-vv): Print logs for all tests.
/// - 3 (-vvv): Print execution traces for failing tests.
/// - 4 (-vvvv): Print execution traces for all tests, and setup traces for failing tests.
/// - 5 (-vvvvv): Print execution and setup traces for all tests.
/// - 5 (-vvvvv): Print execution and setup traces for all tests, including storage changes.
#[arg(help_heading = "Display options", global = true, short, long, verbatim_doc_comment, conflicts_with = "quiet", action = ArgAction::Count)]
verbosity: Verbosity,

Expand Down
2 changes: 1 addition & 1 deletion crates/cli/src/utils/cmd.rs
Original file line number Diff line number Diff line change
Expand Up @@ -449,7 +449,7 @@ pub async fn handle_traces(
decoder.debug_identifier = Some(DebugTraceIdentifier::new(sources));
}

print_traces(&mut result, &decoder, shell::verbosity() > 0, shell::verbosity() > 1).await?;
print_traces(&mut result, &decoder, shell::verbosity() > 0, shell::verbosity() > 4).await?;

Ok(())
}
Expand Down
8 changes: 4 additions & 4 deletions crates/forge/bin/cmd/test/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@ use forge::{
debug::{ContractSources, DebugTraceIdentifier},
decode_trace_arena, folded_stack_trace,
identifier::SignaturesIdentifier,
render_trace_arena, CallTraceDecoderBuilder, InternalTraceMode, TraceKind,
CallTraceDecoderBuilder, InternalTraceMode, TraceKind,
},
MultiContractRunner, MultiContractRunnerBuilder, TestFilter, TestOptions, TestOptionsBuilder,
};
Expand Down Expand Up @@ -56,7 +56,7 @@ use summary::TestSummaryReporter;

use crate::cmd::test::summary::print_invariant_metrics;
pub use filter::FilterArgs;
use forge::result::TestKind;
use forge::{result::TestKind, traces::render_trace_arena_inner};

// Loads project's figment and merges the build cli arguments into it
foundry_config::merge_impl_figment_convert!(TestArgs, opts, evm_opts);
Expand Down Expand Up @@ -652,7 +652,7 @@ impl TestArgs {
// - 0..3: nothing
// - 3: only display traces for failed tests
// - 4: also display the setup trace for failed tests
// - 5..: display all traces for all tests
// - 5..: display all traces for all tests, including storage changes
let should_include = match kind {
TraceKind::Execution => {
(verbosity == 3 && result.status.is_failure()) || verbosity >= 4
Expand All @@ -665,7 +665,7 @@ impl TestArgs {

if should_include {
decode_trace_arena(arena, &decoder).await?;
decoded_traces.push(render_trace_arena(arena));
decoded_traces.push(render_trace_arena_inner(arena, false, verbosity > 4));
}
}

Expand Down
5 changes: 3 additions & 2 deletions crates/forge/src/multi_runner.rs
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ use crate::{
use alloy_json_abi::{Function, JsonAbi};
use alloy_primitives::{Address, Bytes, U256};
use eyre::Result;
use foundry_common::{get_contract_name, ContractsByArtifact, TestFunctionExt};
use foundry_common::{get_contract_name, shell::verbosity, ContractsByArtifact, TestFunctionExt};
use foundry_compilers::{
artifacts::Libraries, compilers::Compiler, Artifact, ArtifactId, ProjectCompileOutput,
};
Expand Down Expand Up @@ -249,7 +249,8 @@ impl MultiContractRunner {
let trace_mode = TraceMode::default()
.with_debug(self.debug)
.with_decode_internal(self.decode_internal)
.with_verbosity(self.evm_opts.verbosity);
.with_verbosity(self.evm_opts.verbosity)
.with_state_changes(verbosity() > 4);

let executor = ExecutorBuilder::new()
.inspectors(|stack| {
Expand Down
2 changes: 1 addition & 1 deletion crates/forge/tests/cli/cmd.rs
Original file line number Diff line number Diff line change
Expand Up @@ -67,7 +67,7 @@ Display options:
- 2 (-vv): Print logs for all tests.
- 3 (-vvv): Print execution traces for failing tests.
- 4 (-vvvv): Print execution traces for all tests, and setup traces for failing tests.
- 5 (-vvvvv): Print execution and setup traces for all tests.
- 5 (-vvvvv): Print execution and setup traces for all tests, including storage changes.
Find more information in the book: http://book.getfoundry.sh/reference/forge/forge.html
Expand Down
34 changes: 34 additions & 0 deletions crates/forge/tests/cli/test_cmd.rs
Original file line number Diff line number Diff line change
Expand Up @@ -2665,3 +2665,37 @@ Suite result: FAILED. 0 passed; 1 failed; 0 skipped; [ELAPSED]
"#]]);
});

// Tests that test traces display state changes when running with verbosity.
forgetest_init!(should_show_state_changes, |prj, cmd| {
cmd.args(["test", "--mt", "test_Increment", "-vvvvv"]).assert_success().stdout_eq(str![[r#"
...
Ran 1 test for test/Counter.t.sol:CounterTest
[PASS] test_Increment() ([GAS])
Traces:
[87464] CounterTest::setUp()
├─ [47297] → new Counter@0x5615dEB798BB3E4dFa0139dFa1b3D433Cc23b72f
│ └─ ← [Return] 236 bytes of code
├─ [2387] Counter::setNumber(0)
│ └─ ← [Stop]
└─ ← [Stop]
[31293] CounterTest::test_Increment()
├─ [22337] Counter::increment()
│ ├─ storage changes:
│ │ @ 0: 0 → 1
│ └─ ← [Stop]
├─ [281] Counter::number() [staticcall]
│ └─ ← [Return] 1
├─ [0] VM::assertEq(1, 1) [staticcall]
│ └─ ← [Return]
├─ storage changes:
│ @ 0: 0 → 1
└─ ← [Stop]
Suite result: ok. 1 passed; 0 failed; 0 skipped; [ELAPSED]
Ran 1 test suite [ELAPSED]: 1 tests passed, 0 failed, 0 skipped (1 total tests)
"#]]);
});

0 comments on commit 85f9571

Please sign in to comment.