mithril_common/messages/
cardano_transaction_snapshot.rs

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