abstract_std/objects/
ans_asset.rs1use std::fmt;
2
3use cosmwasm_std::Uint128;
4use schemars::JsonSchema;
5use serde::{Deserialize, Serialize};
6
7use super::AssetEntry;
8
9#[derive(Serialize, Deserialize, Clone, Debug, PartialEq, Eq, JsonSchema)]
10pub struct AnsAsset {
11 pub name: AssetEntry,
12 pub amount: Uint128,
13}
14
15impl AnsAsset {
16 pub fn new(name: impl Into<AssetEntry>, amount: impl Into<Uint128>) -> Self {
17 AnsAsset {
18 name: name.into(),
19 amount: amount.into(),
20 }
21 }
22}
23
24impl fmt::Display for AnsAsset {
25 fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result {
26 write!(f, "{}:{}", self.name, self.amount)
27 }
28}
29
30#[cfg(test)]
31mod test {
32 #![allow(clippy::needless_borrows_for_generic_args)]
33
34 use super::*;
35
36 #[coverage_helper::test]
37 fn test_new() {
38 let AnsAsset { name, amount } = AnsAsset::new("crab", 100u128);
39
40 assert_eq!(name, AssetEntry::new("crab"));
41 assert_eq!(amount, Uint128::new(100));
42 }
43
44 #[coverage_helper::test]
45 fn test_to_string() {
46 let asset = AnsAsset::new("crab", 100u128);
47
48 assert_eq!(asset.to_string(), "crab:100".to_string());
49 }
50}