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