Skip to content

Commit

Permalink
Fix parsing sequences of H256s in a matchinglist via agent settings (#…
Browse files Browse the repository at this point in the history
…3180)

### Description

Upon trying to use a blacklist with an array of H256s as the
`recipientAddress`, was getting a panic:
```
running 1 test
parse_value: Array [Object {"destinationdomain": Number(11155111), "origindomain": Number(1399811151), "recipientaddress": Array [String("0x6AD4DEBA8A147d000C09de6465267a9047d1c217"), String("0x6AD4DEBA8A147d000C09de6465267a9047d1c218")], "senderaddress": Array [String("0x6AD4DEBA8A147d000C09de6465267a9047d1c217"), String("0x6AD4DEBA8A147d000C09de6465267a9047d1c218")]}] "Expected matching list"
thread 'settings::matching_list::test::supports_sequence_h256s' panicked at 'called `Result::unwrap()` on an `Err` value: ConfigParsingError([(ConfigPath([]), Expected matching list

Caused by:
    invalid type: string "0x6AD4DEBA8A147d000C09de6465267a9047d1c217", expected a borrowed string

Location:
    /Users/trevor/abacus-monorepo/rust/hyperlane-base/src/settings/parser/json_value_parser.rs:259:14)])', agents/relayer/src/settings/matching_list.rs:473:60
stack backtrace:
   0: rust_begin_unwind
             at /rustc/d5c2e9c342b358556da91d61ed4133f6f50fc0c3/library/std/src/panicking.rs:593:5
   1: core::panicking::panic_fmt
             at /rustc/d5c2e9c342b358556da91d61ed4133f6f50fc0c3/library/core/src/panicking.rs:67:14
   2: core::result::unwrap_failed
             at /rustc/d5c2e9c342b358556da91d61ed4133f6f50fc0c3/library/core/src/result.rs:1651:5
   3: core::result::Result<T,E>::unwrap
             at /rustc/d5c2e9c342b358556da91d61ed4133f6f50fc0c3/library/core/src/result.rs:1076:23
   4: relayer::settings::matching_list::test::supports_sequence_h256s
             at ./src/settings/matching_list.rs:473:9
   5: relayer::settings::matching_list::test::supports_sequence_h256s::{{closure}}
             at ./src/settings/matching_list.rs:459:34
   6: core::ops::function::FnOnce::call_once
             at /rustc/d5c2e9c342b358556da91d61ed4133f6f50fc0c3/library/core/src/ops/function.rs:250:5
   7: core::ops::function::FnOnce::call_once
             at /rustc/d5c2e9c342b358556da91d61ed4133f6f50fc0c3/library/core/src/ops/function.rs:250:5
note: Some details are omitted, run with `RUST_BACKTRACE=full` for a verbose backtrace.
test settings::matching_list::test::supports_sequence_h256s ... FAILED
```

Honestly not too sure about the implications of this being a String vs
&str

### Drive-by changes

<!--
Are there any minor or drive-by changes also included?
-->

### Related issues

<!--
- Fixes #[issue number here]
-->

### Backward compatibility

<!--
Are these changes backward compatible? Are there any infrastructure
implications, e.g. changes that would prohibit deploying older commits
using this infra tooling?

Yes/No
-->

### Testing

<!--
What kind of testing have these changes undergone?

None/Manual/Unit Tests
-->
  • Loading branch information
tkporter authored Jan 24, 2024
1 parent 0cad4f7 commit 6845f9f
Showing 1 changed file with 17 additions and 2 deletions.
19 changes: 17 additions & 2 deletions rust/agents/relayer/src/settings/matching_list.rs
Original file line number Diff line number Diff line change
Expand Up @@ -186,8 +186,8 @@ impl<'de> Visitor<'de> for FilterVisitor<H256> {
A: SeqAccess<'de>,
{
let mut values = Vec::new();
while let Some(i) = seq.next_element::<&str>()? {
values.push(parse_addr(i)?)
while let Some(i) = seq.next_element::<String>()? {
values.push(parse_addr(&i)?)
}
Ok(Self::Value::Enumerated(values))
}
Expand Down Expand Up @@ -454,4 +454,19 @@ mod test {
r#"[{"origindomain":1399811151,"senderaddress":"DdTMkk9nuqH5LnD56HLkPiKMV3yB3BNEYSQfgmJHa5i7","destinationdomain":11155111,"recipientaddress":"0x6AD4DEBA8A147d000C09de6465267a9047d1c217"}]"#,
).unwrap();
}

#[test]
fn supports_sequence_h256s() {
let json_str = r#"[{"origindomain":1399811151,"senderaddress":["0x6AD4DEBA8A147d000C09de6465267a9047d1c217","0x6AD4DEBA8A147d000C09de6465267a9047d1c218"],"destinationdomain":11155111,"recipientaddress":["0x6AD4DEBA8A147d000C09de6465267a9047d1c217","0x6AD4DEBA8A147d000C09de6465267a9047d1c218"]}]"#;

// Test parsing directly into MatchingList
serde_json::from_str::<MatchingList>(json_str).unwrap();

// Test parsing into a Value and then into MatchingList, which is the path used
// by the agent config parser.
let val: serde_json::Value = serde_json::from_str(json_str).unwrap();
let value_parser =
hyperlane_base::settings::parser::ValueParser::new(Default::default(), &val);
crate::settings::parse_matching_list(value_parser).unwrap();
}
}

0 comments on commit 6845f9f

Please sign in to comment.