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

metadata: add tests for decoding failure when asset_id and denom don't match and simple roundtrip encoding test #4289

Merged
merged 1 commit into from
Apr 30, 2024
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
29 changes: 29 additions & 0 deletions crates/core/asset/src/asset/denom_metadata.rs
Original file line number Diff line number Diff line change
Expand Up @@ -545,6 +545,8 @@ impl Display for Unit {

#[cfg(test)]
mod tests {
use std::sync::Arc;

#[test]
fn can_parse_metadata_from_chain_registry() {
const SOME_COSMOS_JSON: &str = r#"
Expand Down Expand Up @@ -590,4 +592,31 @@ mod tests {
//let json2 = serde_json::to_string_pretty(&_metadata).unwrap();
//println!("{}", json2);
}

#[test]
fn encoding_round_trip_succeeds() {
let metadata = super::Metadata::try_from("upenumbra").unwrap();

let proto = super::pb::Metadata::from(metadata.clone());

let metadata_2 = super::Metadata::try_from(proto).unwrap();

assert_eq!(metadata, metadata_2);
}

#[test]
#[should_panic]
fn changing_asset_id_without_changing_denom_fails_decoding() {
let mut metadata = super::Metadata::try_from("upenumbra").unwrap();

let inner = Arc::get_mut(&mut metadata.inner).unwrap();

inner.id = super::Id::from_raw_denom("uusd");

let proto = super::pb::Metadata::from(metadata);

// This should throw an error, because the asset ID and denom are now inconsistent.

let _domain_type = super::Metadata::try_from(proto).unwrap();
}
}
Loading