desmos_bindings/relationships/
msg.rs

1//! Contains the messages that can be sent to the chain to interact with the x/relationships module.
2
3use crate::relationships::types::*;
4use cosmwasm_std::Addr;
5
6/// RelationshipsMsg is the builder to generate Desmos x/relationships messages.
7pub struct RelationshipsMsg {}
8
9impl RelationshipsMsg {
10    /// Creates a new instance of [`MsgCreateRelationship`].
11    ///
12    /// * `signer` - Address of who wants to create the relationship.
13    /// * `counterparty` - Address of the counterparty.
14    /// * `subspace_id` - Subspace in which will be created the relationship.
15    pub fn create_relationship(
16        signer: Addr,
17        counterparty: Addr,
18        subspace_id: u64,
19    ) -> MsgCreateRelationship {
20        MsgCreateRelationship {
21            signer: signer.into(),
22            counterparty: counterparty.into(),
23            subspace_id,
24        }
25    }
26
27    /// Creates a new instance of [`MsgDeleteRelationship`].
28    ///
29    /// * `signer` - Address of who wants to delete the relationship.
30    /// * `counterparty` - Address of the counterparty.
31    /// * `subspace_id` - Subspace in which will be deleted the relationship.
32    pub fn delete_relationship(
33        signer: Addr,
34        counterparty: Addr,
35        subspace_id: u64,
36    ) -> MsgDeleteRelationship {
37        MsgDeleteRelationship {
38            signer: signer.into(),
39            counterparty: counterparty.into(),
40            subspace_id,
41        }
42    }
43
44    /// Creates a new instance of [`MsgBlockUser`].
45    ///
46    /// * `blocker` - Address of wants to create the block.
47    /// * `blocked` - Address of the user that will be blocker from `blocker`.
48    /// * `reason` - Reason of the block.
49    /// * `subspace_id` - Subspace on which will be created the block.
50    pub fn block_user(
51        blocker: Addr,
52        blocked: Addr,
53        reason: &str,
54        subspace_id: u64,
55    ) -> MsgBlockUser {
56        MsgBlockUser {
57            blocker: blocker.into(),
58            blocked: blocked.into(),
59            reason: reason.into(),
60            subspace_id,
61        }
62    }
63
64    /// Creates a new instance of [`MsgUnblockUser`].
65    ///
66    /// * `blocker` - Address of who wants to delete the block.
67    /// * `blocked` - Address of the user that will be unblocked from `blocker`.
68    /// * `subspace_id` - Subspace in which will be deleted the block.
69    pub fn unblock_user(blocker: Addr, blocked: Addr, subspace_id: u64) -> MsgUnblockUser {
70        MsgUnblockUser {
71            blocker: blocker.into(),
72            blocked: blocked.into(),
73            subspace_id,
74        }
75    }
76}
77
78#[cfg(test)]
79mod tests {
80    use super::*;
81
82    #[test]
83    fn test_create_relationship() {
84        let msg = RelationshipsMsg::create_relationship(
85            Addr::unchecked("user"),
86            Addr::unchecked("conterparty"),
87            1,
88        );
89        let expected = MsgCreateRelationship {
90            signer: "user".into(),
91            counterparty: "conterparty".into(),
92            subspace_id: 1,
93        };
94        assert_eq!(expected, msg)
95    }
96
97    #[test]
98    fn test_delete_relationship() {
99        let msg = RelationshipsMsg::delete_relationship(
100            Addr::unchecked("user"),
101            Addr::unchecked("conterparty"),
102            1,
103        );
104        let expected = MsgDeleteRelationship {
105            signer: "user".into(),
106            counterparty: "conterparty".into(),
107            subspace_id: 1,
108        };
109        assert_eq!(expected, msg)
110    }
111
112    #[test]
113    fn test_block_user() {
114        let msg = RelationshipsMsg::block_user(
115            Addr::unchecked("user"),
116            Addr::unchecked("counterparty"),
117            "test".into(),
118            1,
119        );
120        let expected = MsgBlockUser {
121            blocker: "user".into(),
122            blocked: "counterparty".into(),
123            reason: "test".into(),
124            subspace_id: 1,
125        };
126        assert_eq!(expected, msg)
127    }
128
129    #[test]
130    fn test_unblock_user() {
131        let msg = RelationshipsMsg::unblock_user(
132            Addr::unchecked("user"),
133            Addr::unchecked("counterparty"),
134            1,
135        );
136        let expected = MsgUnblockUser {
137            blocker: "user".into(),
138            blocked: "counterparty".into(),
139            subspace_id: 1,
140        };
141        assert_eq!(expected, msg)
142    }
143}