Skip to content

Commit e807429

Browse files
ckoopmanntestmattsse
authored
fix(cast) cast run panicks when encountering failed contract deployment (#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>
1 parent ac19482 commit e807429

1 file changed

Lines changed: 24 additions & 9 deletions

File tree

cli/src/cmd/cast/run.rs

Lines changed: 24 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,8 @@
11
use crate::{init_progress, opts::RpcOpts, update_progress, utils};
2-
use cast::trace::{identifier::SignaturesIdentifier, CallTraceDecoder, Traces};
2+
use cast::{
3+
executor::{EvmError, ExecutionErr},
4+
trace::{identifier::SignaturesIdentifier, CallTraceDecoder, Traces},
5+
};
36
use clap::Parser;
47
use ethers::{
58
abi::Address,
@@ -168,14 +171,26 @@ impl RunArgs {
168171
}
169172
} else {
170173
trace!(tx=?tx.hash, "executing create transaction");
171-
let DeployResult { gas_used, traces, debug: run_debug, .. }: DeployResult =
172-
executor.deploy_with_env(env, None).unwrap();
173-
174-
RunResult {
175-
success: true,
176-
traces: vec![(TraceKind::Execution, traces.unwrap_or_default())],
177-
debug: run_debug.unwrap_or_default(),
178-
gas_used,
174+
match executor.deploy_with_env(env, None) {
175+
Ok(DeployResult { gas_used, traces, debug: run_debug, .. }) => RunResult {
176+
success: true,
177+
traces: vec![(TraceKind::Execution, traces.unwrap_or_default())],
178+
debug: run_debug.unwrap_or_default(),
179+
gas_used,
180+
},
181+
Err(EvmError::Execution(inner)) => {
182+
let ExecutionErr { reverted, gas_used, traces, debug: run_debug, .. } =
183+
*inner;
184+
RunResult {
185+
success: !reverted,
186+
traces: vec![(TraceKind::Execution, traces.unwrap_or_default())],
187+
debug: run_debug.unwrap_or_default(),
188+
gas_used,
189+
}
190+
}
191+
Err(err) => {
192+
eyre::bail!("unexpected error when running create transaction: {:?}", err)
193+
}
179194
}
180195
}
181196
};

0 commit comments

Comments
 (0)