Skip to content

Commit

Permalink
fix(cast) cast run panicks when encountering failed contract deploy…
Browse files Browse the repository at this point in the history
…ment (#4871)

* Fix cast run panick when encountering failed contract deployment

* Fix lint failure

* Replace panic! with eyre:bail

Co-authored-by: Matthias Seitz <matthias.seitz@outlook.de>

---------

Co-authored-by: test <test@gmail.com>
Co-authored-by: Matthias Seitz <matthias.seitz@outlook.de>
  • Loading branch information
3 people authored May 3, 2023
1 parent ac19482 commit e807429
Showing 1 changed file with 24 additions and 9 deletions.
33 changes: 24 additions & 9 deletions cli/src/cmd/cast/run.rs
Original file line number Diff line number Diff line change
@@ -1,5 +1,8 @@
use crate::{init_progress, opts::RpcOpts, update_progress, utils};
use cast::trace::{identifier::SignaturesIdentifier, CallTraceDecoder, Traces};
use cast::{
executor::{EvmError, ExecutionErr},
trace::{identifier::SignaturesIdentifier, CallTraceDecoder, Traces},
};
use clap::Parser;
use ethers::{
abi::Address,
Expand Down Expand Up @@ -168,14 +171,26 @@ impl RunArgs {
}
} else {
trace!(tx=?tx.hash, "executing create transaction");
let DeployResult { gas_used, traces, debug: run_debug, .. }: DeployResult =
executor.deploy_with_env(env, None).unwrap();

RunResult {
success: true,
traces: vec![(TraceKind::Execution, traces.unwrap_or_default())],
debug: run_debug.unwrap_or_default(),
gas_used,
match executor.deploy_with_env(env, None) {
Ok(DeployResult { gas_used, traces, debug: run_debug, .. }) => RunResult {
success: true,
traces: vec![(TraceKind::Execution, traces.unwrap_or_default())],
debug: run_debug.unwrap_or_default(),
gas_used,
},
Err(EvmError::Execution(inner)) => {
let ExecutionErr { reverted, gas_used, traces, debug: run_debug, .. } =
*inner;
RunResult {
success: !reverted,
traces: vec![(TraceKind::Execution, traces.unwrap_or_default())],
debug: run_debug.unwrap_or_default(),
gas_used,
}
}
Err(err) => {
eyre::bail!("unexpected error when running create transaction: {:?}", err)
}
}
}
};
Expand Down

0 comments on commit e807429

Please sign in to comment.