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