Skip to content

Commit

Permalink
fix testool yaml parsing for access-list (scroll-tech#1074)
Browse files Browse the repository at this point in the history
* Fix testool access-list parsing for yaml.

* Fix yaml parsing.
  • Loading branch information
silathdiir authored Jan 4, 2024
1 parent d005096 commit 8736818
Showing 1 changed file with 19 additions and 11 deletions.
30 changes: 19 additions & 11 deletions testool/src/statetest/yaml.rs
Original file line number Diff line number Diff line change
Expand Up @@ -445,25 +445,33 @@ fn parse_raw_access_list(access_list: Option<&Yaml>) -> Result<Option<parse::Raw
item.as_hash().map_or(
Err(anyhow!("Parsed access list item must be a hash")),
|item| {
let address = if let Some(Yaml::String(address)) =
item.get(&Yaml::String("address".to_string()))
{
address.to_string()
} else {
bail!("Parsed access list address must be a string");
let address = match item.get(&Yaml::String("address".to_string())) {
Some(Yaml::Integer(i)) => format!("{i:x}"),
Some(Yaml::String(s)) => {
assert!(s.starts_with("0x"));
s[2..].to_string()
}
val => bail!("Failed to parse access list address = {val:?}"),
};
let address = format!("0x{:0>40}", address);

let storage_keys = if let Some(Yaml::Array(storage_keys)) =
item.get(&Yaml::String("storageKeys".to_string()))
{
storage_keys
.iter()
.map(|key| {
if let Yaml::Integer(key) = key {
Ok(format!("0x{:064x}", key))
} else {
bail!("Parsed access list storage key must be an integer");
}
let key = match key {
Yaml::Integer(i) => format!("{i:x}"),
Yaml::String(s) => {
assert!(s.starts_with("0x"));
s[2..].to_string()
}
val => bail!(
"Failed to parse access list storage key = {val:?}"
),
};
Ok(format!("0x{:0>64}", key))
})
.collect::<Result<_>>()?
} else {
Expand Down

0 comments on commit 8736818

Please sign in to comment.