Skip to content

Commit

Permalink
fix(cheatcodes): get artifact code panic (#8546)
Browse files Browse the repository at this point in the history
  • Loading branch information
DaniPopes authored Jul 28, 2024
1 parent 741db53 commit 6822860
Showing 1 changed file with 6 additions and 7 deletions.
13 changes: 6 additions & 7 deletions crates/cheatcodes/src/fs.rs
Original file line number Diff line number Diff line change
Expand Up @@ -387,22 +387,21 @@ fn get_artifact_code(state: &Cheatcodes, path: &str, deployed: bool) -> Result<B
})
.collect::<Vec<_>>();

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
.running_version
.as_ref()
.and_then(|version| {
let filtered = filtered
.into_iter()
.iter()
.filter(|(id, _)| id.version == *version)
.collect::<Vec<_>>();

(filtered.len() == 1).then_some(filtered[0])
(filtered.len() == 1).then(|| filtered[0])
})
.ok_or_else(|| fmt_err!("Multiple matching artifacts found"))
}
Expand Down

0 comments on commit 6822860

Please sign in to comment.