mithril_common/messages/
mithril_stake_distribution_list.rs

1use chrono::{DateTime, Utc};
2use serde::{Deserialize, Serialize};
3
4use crate::entities::Epoch;
5
6/// Message structure of a Mithril Stake Distribution list
7pub type MithrilStakeDistributionListMessage = Vec<MithrilStakeDistributionListItemMessage>;
8
9/// Message structure of a Mithril Stake Distribution list item
10#[derive(Clone, Debug, PartialEq, Eq, Default, Serialize, Deserialize)]
11pub struct MithrilStakeDistributionListItemMessage {
12    /// Epoch at which the Mithril Stake Distribution is created
13    pub epoch: Epoch,
14
15    /// Hash of the Mithril Stake Distribution (different from the AVK).
16    pub hash: String,
17
18    /// Hash of the associated certificate
19    pub certificate_hash: String,
20
21    /// Date and time at which the Mithril Stake Distribution was created
22    pub created_at: DateTime<Utc>,
23}
24
25#[cfg(test)]
26mod tests {
27    use super::*;
28
29    fn golden_message_current() -> MithrilStakeDistributionListMessage {
30        vec![MithrilStakeDistributionListItemMessage {
31            epoch: Epoch(1),
32            hash: "hash-123".to_string(),
33            certificate_hash: "certificate-hash-123".to_string(),
34            created_at: DateTime::parse_from_rfc3339("2023-01-19T13:43:05.618857482Z")
35                .unwrap()
36                .with_timezone(&Utc),
37        }]
38    }
39
40    const CURRENT_JSON: &str = r#"[{
41        "epoch": 1,
42        "hash": "hash-123",
43        "certificate_hash": "certificate-hash-123",
44        "created_at": "2023-01-19T13:43:05.618857482Z"
45        }]"#;
46
47    #[test]
48    fn test_current_json_deserialized_into_current_message() {
49        let json = CURRENT_JSON;
50        let message: MithrilStakeDistributionListMessage = serde_json::from_str(json).expect(
51                    "This JSON is expected to be successfully parsed into a MithrilStakeDistributionListMessage instance.",
52                );
53
54        assert_eq!(golden_message_current(), message);
55    }
56}