diff --git a/crates/forge/tests/cli/script.rs b/crates/forge/tests/cli/script.rs index a2d4dc4fb625..8af676efd0dd 100644 --- a/crates/forge/tests/cli/script.rs +++ b/crates/forge/tests/cli/script.rs @@ -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()")); +}); diff --git a/crates/script/src/execute.rs b/crates/script/src/execute.rs index d89461c9e9f1..7a2546ec822c 100644 --- a/crates/script/src/execute.rs +++ b/crates/script/src/execute.rs @@ -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}, @@ -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) )); } @@ -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) )); }