Skip to content

Commit

Permalink
Make libraries optional in YAML
Browse files Browse the repository at this point in the history
  • Loading branch information
axic committed Jan 25, 2020
1 parent e9bb276 commit 8f3afe6
Showing 1 changed file with 13 additions and 10 deletions.
23 changes: 13 additions & 10 deletions src/main.rs
Original file line number Diff line number Diff line change
Expand Up @@ -728,7 +728,7 @@ struct TestLibrary {
#[derive(Debug, PartialEq, Serialize, Deserialize)]
struct TestBeaconState {
execution_scripts: Vec<String>,
libraries: Vec<TestLibrary>,
libraries: Option<Vec<TestLibrary>>,
}

#[derive(Debug, PartialEq, Serialize, Deserialize)]
Expand Down Expand Up @@ -816,16 +816,19 @@ impl TryFrom<TestBeaconState> for BeaconState {
})
})
.collect();
let libraries: Result<Vec<Library>, ScoutError> = input
.libraries
.iter()
.map(|library| {
Ok(Library {
name: library.name.to_string(),
code: std::fs::read(&library.file)?,
let libraries: Result<Vec<Library>, ScoutError> = if let Some(libraries) = input.libraries {
libraries
.iter()
.map(|library| {
Ok(Library {
name: library.name.to_string(),
code: std::fs::read(&library.file)?,
})
})
})
.collect();
.collect()
} else {
Ok(Vec::new())
};
Ok(BeaconState {
execution_scripts: scripts?,
libraries: libraries?,
Expand Down

0 comments on commit 8f3afe6

Please sign in to comment.