[feat] cast call --trace (& code reuse in cast run)#5477
[feat] cast call --trace (& code reuse in cast run)#5477Evalir merged 44 commits intofoundry-rs:masterfrom
cast call --trace (& code reuse in cast run)#5477Conversation
|
hi, so this PR is fully implemented as a extension to i only say this because now, Making lots of this code is shared with |
mattsse
left a comment
There was a problem hiding this comment.
great feature,
I think having it as flag in cast call is the best approach
I wonder if we can unify a lot of stuff with cast run
but perhaps not really possible since cast run behaves slightly differently
wdyt @Evalir
only glanced over the changes, looks promising
I'd like to move the TracingExecutor and the standalone functions to a separate file though
cli/src/cmd/cast/call.rs
Outdated
| struct TracingExecutor { | ||
| executor: Executor, | ||
| } | ||
|
|
||
| impl TracingExecutor { | ||
| pub async fn new( | ||
| config: &foundry_config::Config, | ||
| version: Option<EvmVersion>, | ||
| rpc_opts: RpcOpts, | ||
| debug: bool, | ||
| ) -> eyre::Result<(Self, EvmOpts)> { | ||
| // todo:n find out what this is | ||
| let figment = | ||
| Config::figment_with_root(find_project_root_path(None).unwrap()).merge(rpc_opts); | ||
|
|
||
| let mut evm_opts = figment.extract::<EvmOpts>()?; | ||
|
|
||
| evm_opts.fork_url = Some(config.get_rpc_url_or_localhost_http()?.into_owned()); | ||
| evm_opts.fork_block_number = config.fork_block_number; | ||
|
|
||
| // Set up the execution environment | ||
| let env = evm_opts.evm_env().await; | ||
|
|
||
| let db = Backend::spawn(evm_opts.get_fork(&config, env.clone())).await; | ||
|
|
||
| // configures a bare version of the evm executor: no cheatcode inspector is enabled, | ||
| // tracing will be enabled only for the targeted transaction | ||
| let builder = ExecutorBuilder::default() | ||
| .with_config(env) | ||
| .with_spec(evm_spec(&version.unwrap_or(config.evm_version))); | ||
|
|
||
| let mut executor = builder.build(db); | ||
|
|
||
| executor.set_tracing(true).set_debugger(debug); | ||
|
|
||
| Ok((Self { executor }, evm_opts)) | ||
| } | ||
| } | ||
|
|
||
| impl std::ops::Deref for TracingExecutor { | ||
| type Target = Executor; | ||
|
|
||
| fn deref(&self) -> &Self::Target { | ||
| &self.executor | ||
| } | ||
| } | ||
|
|
||
| impl DerefMut for TracingExecutor { | ||
| fn deref_mut(&mut self) -> &mut Self::Target { | ||
| &mut self.executor | ||
| } | ||
| } |
There was a problem hiding this comment.
i like this. wdyt about moving it to the evm crate? that way we have executors all in one place—we can do the config stuff before building the executor and therefore not depend on the config
cli/src/cmd/cast/call.rs
Outdated
| Ok(DeployResult { gas_used, traces, debug: run_debug, .. }) => { | ||
| TraceResult { | ||
| success: true, | ||
| traces: vec![(TraceKind::Execution, traces.unwrap_or_default())], |
There was a problem hiding this comment.
hmm, as traces are enabled by default, is there any situation where we do not want to error if we can't unwrap the traces? thinking it might be better to just bail here if not
cli/src/cmd/cast/call.rs
Outdated
| } | ||
|
|
||
| builder.set_data(data); | ||
| // fill it last because we dont need anything from the built one |
There was a problem hiding this comment.
can we make this comment a tad clearer? can't easily figure out what you mean without context 😄
cli/src/cmd/cast/call.rs
Outdated
| } | ||
| _ => { | ||
| builder.value(tx.value); | ||
| // fill it first becasue builder parses args / addr |
There was a problem hiding this comment.
| // fill it first becasue builder parses args / addr | |
| // fill it first because builder parses args / addr |
|
hi @Evalir i addressed your requests in the more recent commits, as well as moved the As well all items mentioned can by re used in |
Evalir
left a comment
There was a problem hiding this comment.
lgtm bar few doc comments! can't push to your branch as it's protected (master)
i think we can do the other stuff in a followup pr if you're up for it 🙏
|
@nhtyy nice! should we fix the failing tests on this pr and open that one here? |
|
@Evalir hmm sorry im not sure how to open both of them at the same time on this repo |
|
maybe we should just merge them all here? diff shouldnt be to bad, sent you an invite to my repo as well |
|
sure! let's merge them all here then, and update the pr description accordingly |
cast call --tracecast call --trace (& code reuse in cast run)
|
re-requesting review since there was some merge conflicts blocking |
Evalir
left a comment
There was a problem hiding this comment.
lgtm! thank you! just needs fmt, but can't push to your branch since this is on master. let's fix ci then we can send it
|
was missing this feature a lot! great stuff 🚀 |
#5461
Forks remote rpc, executes a call and prints a trace
edit: this PR also touches on
cast runjust to dedup some code we copyMotivation
I come up needing something like this quite often, using a forge test on the fly rn with calldata