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