desmos_bindings/reports/
msg.rs

1//! Contains the messages that can be sent to the chain to interact with the x/reports module.
2
3use crate::reports::types::ReportTarget;
4use crate::reports::types::*;
5use cosmwasm_std::Addr;
6
7/// ReportsMsg is the builder to generate Desmos x/reports messages.
8pub enum ReportsMsg {}
9
10impl ReportsMsg {
11    /// Creates an instance of [`MsgCreateReport`].
12    ///
13    /// * `subspace_id` - Id of the subspace for which the report should be stored.
14    /// * `reasons_ids` - Id of the reason this report has been created for.
15    /// * `message` - Message attached to this report.
16    /// * `reporter` - Address of the reporter.
17    /// * `target` - Target of the report.
18    pub fn create_report(
19        subspace_id: u64,
20        reasons_ids: Vec<u32>,
21        message: &str,
22        reporter: Addr,
23        target: ReportTarget,
24    ) -> MsgCreateReport {
25        MsgCreateReport {
26            subspace_id: subspace_id.into(),
27            reasons_ids,
28            message: message.into(),
29            reporter: reporter.into(),
30            target: Some(target.into()),
31        }
32    }
33
34    /// Creates an instance of [`MsgDeleteReport`].
35    ///
36    /// * `subspace_id` - Id of the subspace that contains the report to be deleted.
37    /// * `report_id` - Id of the report to be deleted.
38    /// * `signer` - Address of the user deleting the report.
39    pub fn delete_report(subspace_id: u64, report_id: u64, signer: Addr) -> MsgDeleteReport {
40        MsgDeleteReport {
41            subspace_id,
42            report_id,
43            signer: signer.into(),
44        }
45    }
46
47    /// Creates an instance of [`MsgSupportStandardReason`].
48    ///
49    /// * `subspace_id` - Id of the subspace for which to support the reason
50    /// * `standard_reason_id` - Id of the reason that should be supported
51    /// * `signer` - Address of the user signing the message.
52    pub fn support_standard_reason(
53        subspace_id: u64,
54        standard_reason_id: u32,
55        signer: Addr,
56    ) -> MsgSupportStandardReason {
57        MsgSupportStandardReason {
58            subspace_id,
59            standard_reason_id,
60            signer: signer.into(),
61        }
62    }
63
64    /// Creates a new instance of [`MsgAddReason`].
65    ///
66    /// * `subspace_id` - Id of the subspace for which to add the reason.
67    /// * `title` - Title of the reason.
68    /// * `description` - Extended description of the reason and the cases it applies to.
69    /// * `signer` - Address of the user adding the supported reason.
70    pub fn add_reason(
71        subspace_id: u64,
72        title: &str,
73        description: &str,
74        signer: Addr,
75    ) -> MsgAddReason {
76        MsgAddReason {
77            subspace_id,
78            title: title.into(),
79            description: description.into(),
80            signer: signer.into(),
81        }
82    }
83
84    /// Creates a new instance of [`MsgRemoveReason`].
85    ///
86    /// * `subspace_id` - Id of the subspace from which to remove the reason.
87    /// * `reason_id` - Id of the reason to be deleted.
88    /// * `signer` - Address of the user removing the supported reason.
89    pub fn remove_reason(subspace_id: u64, reason_id: u32, signer: Addr) -> MsgRemoveReason {
90        MsgRemoveReason {
91            subspace_id,
92            reason_id,
93            signer: signer.into(),
94        }
95    }
96}
97
98#[cfg(test)]
99mod test {
100    use super::*;
101
102    #[test]
103    fn test_create_report() {
104        let msg = ReportsMsg::create_report(
105            1,
106            vec![0],
107            "test",
108            Addr::unchecked("reporter"),
109            ReportTarget::Post(PostTarget { post_id: 1 }),
110        );
111
112        let expected = MsgCreateReport {
113            subspace_id: 1,
114            reasons_ids: vec![0],
115            message: "test".into(),
116            reporter: "reporter".into(),
117            target: Some(ReportTarget::Post(PostTarget { post_id: 1 }).into()),
118        };
119
120        assert_eq!(expected, msg);
121    }
122
123    #[test]
124    fn test_delete_report() {
125        let msg = ReportsMsg::delete_report(1, 2, Addr::unchecked("reporter"));
126
127        let expected = MsgDeleteReport {
128            subspace_id: 1,
129            report_id: 2,
130            signer: "reporter".into(),
131        };
132
133        assert_eq!(expected, msg);
134    }
135
136    #[test]
137    fn support_standard_reason() {
138        let msg = ReportsMsg::support_standard_reason(1, 2, Addr::unchecked("reporter"));
139
140        let expected = MsgSupportStandardReason {
141            subspace_id: 1,
142            standard_reason_id: 2,
143            signer: "reporter".into(),
144        };
145
146        assert_eq!(expected, msg);
147    }
148
149    #[test]
150    fn test_add_reason() {
151        let msg = ReportsMsg::add_reason(
152            1,
153            "test reason",
154            "Test description",
155            Addr::unchecked("reporter"),
156        );
157
158        let expected = MsgAddReason {
159            subspace_id: 1,
160            title: "test reason".into(),
161            description: "Test description".into(),
162            signer: "reporter".into(),
163        };
164
165        assert_eq!(expected, msg);
166    }
167
168    #[test]
169    fn test_remove_reason() {
170        let msg = ReportsMsg::remove_reason(1, 2, Addr::unchecked("reporter"));
171
172        let expected = MsgRemoveReason {
173            subspace_id: 1,
174            reason_id: 2,
175            signer: "reporter".into(),
176        };
177
178        assert_eq!(expected, msg);
179    }
180}