abstract_std/objects/
ans_asset.rs

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
use std::fmt;

use cosmwasm_std::Uint128;
use schemars::JsonSchema;
use serde::{Deserialize, Serialize};

use super::AssetEntry;

#[derive(Serialize, Deserialize, Clone, Debug, PartialEq, Eq, JsonSchema)]
pub struct AnsAsset {
    pub name: AssetEntry,
    pub amount: Uint128,
}

impl AnsAsset {
    pub fn new(name: impl Into<AssetEntry>, amount: impl Into<Uint128>) -> Self {
        AnsAsset {
            name: name.into(),
            amount: amount.into(),
        }
    }
}

impl fmt::Display for AnsAsset {
    fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result {
        write!(f, "{}:{}", self.name, self.amount)
    }
}

#[cfg(test)]
mod test {
    #![allow(clippy::needless_borrows_for_generic_args)]

    use super::*;

    #[coverage_helper::test]
    fn test_new() {
        let AnsAsset { name, amount } = AnsAsset::new("crab", 100u128);

        assert_eq!(name, AssetEntry::new("crab"));
        assert_eq!(amount, Uint128::new(100));
    }

    #[coverage_helper::test]
    fn test_to_string() {
        let asset = AnsAsset::new("crab", 100u128);

        assert_eq!(asset.to_string(), "crab:100".to_string());
    }
}