mithril_common/messages/
cardano_transaction_snapshot_list.rs

1use chrono::{DateTime, Utc};
2use serde::{Deserialize, Serialize};
3
4use crate::entities::{BlockNumber, Epoch};
5
6/// Message structure of a Cardano Transactions Snapshots list
7pub type CardanoTransactionSnapshotListMessage = Vec<CardanoTransactionSnapshotListItemMessage>;
8
9/// Message structure of a Cardano Transactions Snapshot list item
10#[derive(Clone, Debug, PartialEq, Eq, Serialize, Deserialize)]
11pub struct CardanoTransactionSnapshotListItemMessage {
12    /// Merkle root of the Cardano transactions snapshot
13    pub merkle_root: String,
14
15    /// Epoch of the Cardano transactions snapshot
16    pub epoch: Epoch,
17
18    /// Block number of the Cardano transactions snapshot
19    pub block_number: BlockNumber,
20
21    /// Hash of the Cardano Transactions snapshot
22    pub hash: String,
23
24    /// Hash of the associated certificate
25    pub certificate_hash: String,
26
27    /// DateTime of creation
28    pub created_at: DateTime<Utc>,
29}
30
31#[cfg(test)]
32mod tests {
33    use super::*;
34
35    fn golden_message_current() -> CardanoTransactionSnapshotListMessage {
36        vec![CardanoTransactionSnapshotListItemMessage {
37            merkle_root: "mkroot-123".to_string(),
38            epoch: Epoch(7),
39            block_number: BlockNumber(5),
40            hash: "hash-123".to_string(),
41            certificate_hash: "certificate-hash-123".to_string(),
42            created_at: DateTime::parse_from_rfc3339("2023-01-19T13:43:05.618857482Z")
43                .unwrap()
44                .with_timezone(&Utc),
45        }]
46    }
47
48    const CURRENT_JSON: &str = r#"[{
49        "merkle_root": "mkroot-123",
50        "epoch": 7,
51        "block_number": 5,
52        "hash": "hash-123",
53        "certificate_hash": "certificate-hash-123",
54        "created_at": "2023-01-19T13:43:05.618857482Z"
55    }]"#;
56
57    #[test]
58    fn test_current_json_deserialized_into_current_message() {
59        let json = CURRENT_JSON;
60        let message: CardanoTransactionSnapshotListMessage = serde_json::from_str(json).expect(
61                    "This JSON is expected to be successfully parsed into a CardanoTransactionSnapshotListMessage instance.",
62                );
63        assert_eq!(golden_message_current(), message);
64    }
65}