From 682286017eea36ee6309fc659a41167f265c56db Mon Sep 17 00:00:00 2001 From: DaniPopes <57450786+DaniPopes@users.noreply.github.com> Date: Sun, 28 Jul 2024 12:18:09 +0200 Subject: [PATCH] fix(cheatcodes): get artifact code panic (#8546) --- crates/cheatcodes/src/fs.rs | 13 ++++++------- 1 file changed, 6 insertions(+), 7 deletions(-) diff --git a/crates/cheatcodes/src/fs.rs b/crates/cheatcodes/src/fs.rs index 129f8a22e939..177037c905b6 100644 --- a/crates/cheatcodes/src/fs.rs +++ b/crates/cheatcodes/src/fs.rs @@ -387,10 +387,10 @@ fn get_artifact_code(state: &Cheatcodes, path: &str, deployed: bool) -> Result>(); - let artifact = match filtered.len() { - 0 => Err(fmt_err!("No matching artifact found")), - 1 => Ok(filtered[0]), - _ => { + let artifact = match &filtered[..] { + [] => Err(fmt_err!("No matching artifact found")), + [artifact] => Ok(artifact), + filtered => { // If we know the current script/test contract solc version, try to filter by it state .config @@ -398,11 +398,10 @@ fn get_artifact_code(state: &Cheatcodes, path: &str, deployed: bool) -> Result>(); - - (filtered.len() == 1).then_some(filtered[0]) + (filtered.len() == 1).then(|| filtered[0]) }) .ok_or_else(|| fmt_err!("Multiple matching artifacts found")) }