Skip to content

Commit

Permalink
fix(script): decode custom error in script fail message (#7563)
Browse files Browse the repository at this point in the history
  • Loading branch information
grandizzy authored and klkvr committed Apr 6, 2024
1 parent 1b846d9 commit 03d900a
Show file tree
Hide file tree
Showing 2 changed files with 37 additions and 3 deletions.
34 changes: 34 additions & 0 deletions crates/forge/tests/cli/script.rs
Original file line number Diff line number Diff line change
Expand Up @@ -1197,3 +1197,37 @@ contract Script {
cmd.arg("script").args([&script.to_string_lossy(), "--sig", "run"]);
assert!(cmd.stderr_lossy().contains("Multiple functions with the same name"));
});

forgetest_async!(can_decode_custom_errors, |prj, cmd| {
cmd.args(["init", "--force"]).arg(prj.root());
cmd.assert_non_empty_stdout();
cmd.forge_fuse();

let script = prj
.add_script(
"CustomErrorScript.s.sol",
r#"
import { Script } from "forge-std/Script.sol";
contract ContractWithCustomError {
error CustomError();
constructor() {
revert CustomError();
}
}
contract CustomErrorScript is Script {
ContractWithCustomError test;
function run() public {
test = new ContractWithCustomError();
}
}
"#,
)
.unwrap();

cmd.arg("script").arg(script).args(["--tc", "CustomErrorScript"]);
assert!(cmd.stderr_lossy().contains("script failed: CustomError()"));
});
6 changes: 3 additions & 3 deletions crates/script/src/execute.rs
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@ use foundry_compilers::artifacts::ContractBytecodeSome;
use foundry_config::{Config, NamedChain};
use foundry_debugger::Debugger;
use foundry_evm::{
decode::{decode_console_logs, RevertDecoder},
decode::decode_console_logs,
inspectors::cheatcodes::{BroadcastableTransaction, BroadcastableTransactions},
traces::{
identifier::{SignaturesIdentifier, TraceIdentifiers},
Expand Down Expand Up @@ -423,7 +423,7 @@ impl PreSimulationState {
if !self.execution_result.success {
return Err(eyre::eyre!(
"script failed: {}",
RevertDecoder::new().decode(&self.execution_result.returned[..], None)
&self.execution_artifacts.decoder.revert_decoder.decode(&result.returned[..], None)
));
}

Expand Down Expand Up @@ -504,7 +504,7 @@ impl PreSimulationState {
if !result.success {
return Err(eyre::eyre!(
"script failed: {}",
RevertDecoder::new().decode(&result.returned[..], None)
&self.execution_artifacts.decoder.revert_decoder.decode(&result.returned[..], None)
));
}

Expand Down

0 comments on commit 03d900a

Please sign in to comment.