Skip to content

Commit

Permalink
metadata: add tests for decoding failure when asset_id and denom don'…
Browse files Browse the repository at this point in the history
…t match and simple roundtrip encoding test
  • Loading branch information
aubrika committed Apr 29, 2024
1 parent 8d3f4f9 commit 8793c53
Showing 1 changed file with 29 additions and 0 deletions.
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();
}
}

0 comments on commit 8793c53

Please sign in to comment.