Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix: Hex serde deserialize #1396

Merged
merged 1 commit into from
Sep 4, 2023
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
17 changes: 16 additions & 1 deletion protocol/src/types/primitive.rs
Original file line number Diff line number Diff line change
Expand Up @@ -152,7 +152,8 @@ impl<'de> Deserialize<'de> for Hex {
where
D: de::Deserializer<'de>,
{
Ok(Hex(withpfx_lowercase::deserialize(deserializer)?))
String::deserialize(deserializer)
.and_then(|s| Hex::from_str(&s).map_err(serde::de::Error::custom))
}
}

Expand Down Expand Up @@ -534,6 +535,20 @@ mod tests {
);
}

#[test]
fn test_hex_serde_deserialize() {
#[derive(Deserialize)]
struct Params {
key: Hex,
}
let test_params: &str = r#"
key = "0x1234"
"#;
let params: Params = toml::from_str(test_params).unwrap();
let expected = Hex::from_str("0x1234").unwrap();
assert_eq!(params.key, expected);
}

#[test]
fn test_default_values() {
let bytes = Hex::empty();
Expand Down
Loading