use super::*; use std::fs; use std::path::Path; pub fn yaml_decode(string: &str) -> Result { serde_yaml::from_str(string).map_err(|e| Error::FailedToParseTest(format!("{:?}", e))) } pub fn yaml_decode_file(path: &Path) -> Result { fs::read_to_string(path) .map_err(|e| { Error::FailedToParseTest(format!("Unable to load {}: {:?}", path.display(), e)) }) .and_then(|s| yaml_decode(&s)) } pub fn ssz_decode_file(path: &Path) -> Result { fs::read(path) .map_err(|e| { Error::FailedToParseTest(format!("Unable to load {}: {:?}", path.display(), e)) }) .and_then(|s| { T::from_ssz_bytes(&s).map_err(|e| { match e { // NOTE: this is a bit hacky, but seemingly better than the alternatives ssz::DecodeError::BytesInvalid(message) if message.contains("Blst") || message.contains("Milagro") => { Error::InvalidBLSInput(message) } e => Error::FailedToParseTest(format!( "Unable to parse SSZ at {}: {:?}", path.display(), e )), } }) }) }