Skip to content

Commit

Permalink
Show storage for verbosity > 1, add test
Browse files Browse the repository at this point in the history
  • Loading branch information
grandizzy committed Nov 27, 2024
1 parent 44fbe73 commit ca94656
Show file tree
Hide file tree
Showing 4 changed files with 61 additions and 17 deletions.
10 changes: 2 additions & 8 deletions crates/cast/bin/cmd/call.rs
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ use foundry_cli::{
opts::{EthereumOpts, TransactionOpts},
utils::{self, handle_traces, parse_ether_value, TraceResult},
};
use foundry_common::ens::NameOrAddress;
use foundry_common::{ens::NameOrAddress, shell};
use foundry_compilers::artifacts::EvmVersion;
use foundry_config::{
figment::{
Expand Down Expand Up @@ -50,10 +50,6 @@ pub struct CallArgs {
#[arg(long, requires = "trace")]
debug: bool,

/// Prints the state changes
#[arg(long)]
with_state_changes: bool,

#[arg(long, requires = "trace")]
decode_internal: bool,

Expand Down Expand Up @@ -132,7 +128,6 @@ impl CallArgs {
trace,
evm_version,
debug,
with_state_changes,
decode_internal,
labels,
data,
Expand Down Expand Up @@ -193,7 +188,7 @@ impl CallArgs {
evm_version,
debug,
decode_internal,
false,
shell::verbosity() > 1,
alphanet,
);

Expand All @@ -220,7 +215,6 @@ impl CallArgs {
with_local_artifacts,
debug,
decode_internal,
with_state_changes,
)
.await?;

Expand Down
7 changes: 1 addition & 6 deletions crates/cast/bin/cmd/run.rs
Original file line number Diff line number Diff line change
Expand Up @@ -50,10 +50,6 @@ pub struct RunArgs {
#[arg(long)]
quick: bool,

/// Prints the state changes
#[arg(long)]
with_state_changes: bool,

/// Label addresses in the trace.
///
/// Example: 0xd8dA6BF26964aF9D7eEd9e03E53415D37aA96045:vitalik.eth
Expand Down Expand Up @@ -173,7 +169,7 @@ impl RunArgs {
evm_version,
self.debug,
self.decode_internal,
self.with_state_changes,
shell::verbosity() > 1,
alphanet,
);
let mut env =
Expand Down Expand Up @@ -265,7 +261,6 @@ impl RunArgs {
self.with_local_artifacts,
self.debug,
self.decode_internal,
self.with_state_changes,
)
.await?;

Expand Down
57 changes: 57 additions & 0 deletions crates/cast/tests/cli/main.rs
Original file line number Diff line number Diff line change
Expand Up @@ -1713,3 +1713,60 @@ Transaction successfully executed.
"#]]);
});

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

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

// Send tx to change counter storage value.
cmd.cast_fuse()
.args([
"send",
"0x5FbDB2315678afecb367f032d93F642f64180aa3",
"setNumber(uint256)",
"111",
"--private-key",
"0xac0974bec39a17e36ba4a6b4d238ff944bacb478cbed5efcae784d7bf4f2ff80",
"--rpc-url",
&handle.http_endpoint(),
])
.assert_success();

let tx_hash = api
.transaction_by_block_number_and_index(BlockNumberOrTag::Latest, Index::from(0))
.await
.unwrap()
.unwrap()
.tx_hash();

// Assert cast with verbosity displays storage changes.
cmd.cast_fuse()
.args(["run", format!("{tx_hash}").as_str(), "-vv", "--rpc-url", &handle.http_endpoint()])
.assert_success()
.stdout_eq(str![[r#"
Executing previous transactions from the block.
Traces:
[22287] 0x5FbDB2315678afecb367f032d93F642f64180aa3::setNumber(111)
├─ storage changes:
│ @ 0: 0 → 111
└─ ← [Stop]
Transaction successfully executed.
[GAS]
"#]]);
});
4 changes: 1 addition & 3 deletions crates/cli/src/utils/cmd.rs
Original file line number Diff line number Diff line change
Expand Up @@ -377,7 +377,6 @@ impl TryFrom<Result<RawCallResult>> for TraceResult {
}

/// labels the traces, conditionally prints them or opens the debugger
#[allow(clippy::too_many_arguments)]
pub async fn handle_traces(
mut result: TraceResult,
config: &Config,
Expand All @@ -386,7 +385,6 @@ pub async fn handle_traces(
with_local_artifacts: bool,
debug: bool,
decode_internal: bool,
with_state_changes: bool,
) -> Result<()> {
let (known_contracts, mut sources) = if with_local_artifacts {
let _ = sh_println!("Compiling project to generate artifacts");
Expand Down Expand Up @@ -451,7 +449,7 @@ pub async fn handle_traces(
decoder.debug_identifier = Some(DebugTraceIdentifier::new(sources));
}

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

Ok(())
}
Expand Down

0 comments on commit ca94656

Please sign in to comment.