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