abstract_core/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 use speculoos::prelude::*;
33
34 use super::*;
35
36 #[test]
37 fn test_new() {
38 let AnsAsset { name, amount } = AnsAsset::new("crab", 100u128);
39
40 assert_that!(name).is_equal_to(AssetEntry::new("crab"));
41 assert_that!(amount).is_equal_to(Uint128::new(100));
42 }
43
44 #[test]
45 fn test_to_string() {
46 let asset = AnsAsset::new("crab", 100u128);
47
48 assert_that!(asset.to_string()).is_equal_to("crab:100".to_string());
49 }
50}