mithril_common/messages/
cardano_stake_distribution_list.rs1use chrono::{DateTime, Utc};
2use serde::{Deserialize, Serialize};
3
4use crate::entities::Epoch;
5
6pub type CardanoStakeDistributionListMessage = Vec<CardanoStakeDistributionListItemMessage>;
8
9#[derive(Clone, Debug, PartialEq, Eq, Default, Serialize, Deserialize)]
11pub struct CardanoStakeDistributionListItemMessage {
12 pub epoch: Epoch,
14
15 pub hash: String,
17
18 pub certificate_hash: String,
20
21 pub created_at: DateTime<Utc>,
23}
24
25#[cfg(test)]
26mod tests {
27 use super::*;
28
29 fn golden_message_current() -> CardanoStakeDistributionListMessage {
30 vec![CardanoStakeDistributionListItemMessage {
31 epoch: Epoch(1),
32 hash: "hash-123".to_string(),
33 certificate_hash: "cert-hash-123".to_string(),
34 created_at: DateTime::parse_from_rfc3339("2024-07-29T16:15: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": "cert-hash-123",
44 "created_at": "2024-07-29T16:15:05.618857482Z"
45 }]"#;
46
47 #[test]
48 fn test_current_json_deserialized_into_current_message() {
49 let json = CURRENT_JSON;
50 let message: CardanoStakeDistributionListMessage = serde_json::from_str(json).expect(
51 "This JSON is expected to be successfully parsed into a CardanoStakeDistributionListMessage instance.",
52 );
53
54 assert_eq!(golden_message_current(), message);
55 }
56}