mithril_common/messages/
mithril_stake_distribution_list.rs1use chrono::{DateTime, Utc};
2use serde::{Deserialize, Serialize};
3
4use crate::entities::Epoch;
5
6pub type MithrilStakeDistributionListMessage = Vec<MithrilStakeDistributionListItemMessage>;
8
9#[derive(Clone, Debug, PartialEq, Eq, Default, Serialize, Deserialize)]
11pub struct MithrilStakeDistributionListItemMessage {
12 pub epoch: Epoch,
14
15 pub hash: String,
17
18 pub certificate_hash: String,
20
21 pub created_at: DateTime<Utc>,
23}
24
25impl MithrilStakeDistributionListItemMessage {
26 pub fn dummy() -> Self {
28 Self {
29 epoch: Epoch(1),
30 hash: "hash-123".to_string(),
31 certificate_hash: "certificate-hash-123".to_string(),
32 created_at: DateTime::parse_from_rfc3339("2023-01-19T13:43:05.618857482Z")
33 .unwrap()
34 .with_timezone(&Utc),
35 }
36 }
37}
38
39#[cfg(test)]
40mod tests {
41 use super::*;
42
43 fn golden_message_current() -> MithrilStakeDistributionListMessage {
44 vec![MithrilStakeDistributionListItemMessage {
45 epoch: Epoch(1),
46 hash: "hash-123".to_string(),
47 certificate_hash: "certificate-hash-123".to_string(),
48 created_at: DateTime::parse_from_rfc3339("2023-01-19T13:43:05.618857482Z")
49 .unwrap()
50 .with_timezone(&Utc),
51 }]
52 }
53
54 const CURRENT_JSON: &str = r#"[{
55 "epoch": 1,
56 "hash": "hash-123",
57 "certificate_hash": "certificate-hash-123",
58 "created_at": "2023-01-19T13:43:05.618857482Z"
59 }]"#;
60
61 #[test]
62 fn test_current_json_deserialized_into_current_message() {
63 let json = CURRENT_JSON;
64 let message: MithrilStakeDistributionListMessage = serde_json::from_str(json).expect(
65 "This JSON is expected to be successfully parsed into a MithrilStakeDistributionListMessage instance.",
66 );
67
68 assert_eq!(golden_message_current(), message);
69 }
70}