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
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}