mithril_common/messages/
snapshot_list.rs1use chrono::{DateTime, Utc};
2use serde::{Deserialize, Serialize};
3
4use crate::entities::{CardanoDbBeacon, CompressionAlgorithm};
5
6pub type SnapshotListMessage = Vec<SnapshotListItemMessage>;
8
9#[derive(Clone, Debug, PartialEq, Eq, Serialize, Deserialize)]
11pub struct SnapshotListItemMessage {
12 pub digest: String,
14
15 pub network: String,
17
18 pub beacon: CardanoDbBeacon,
20
21 pub certificate_hash: String,
23
24 pub size: u64,
26
27 #[serde(skip_serializing_if = "Option::is_none")]
29 pub ancillary_size: Option<u64>,
30
31 pub created_at: DateTime<Utc>,
33
34 pub locations: Vec<String>,
36
37 #[serde(skip_serializing_if = "Option::is_none")]
39 pub ancillary_locations: Option<Vec<String>>,
40
41 pub compression_algorithm: CompressionAlgorithm,
43
44 pub cardano_node_version: String,
46}
47
48#[cfg(test)]
49mod tests {
50 use crate::entities::Epoch;
51
52 use super::*;
53
54 pub type SnapshotListMessageUntilV0_1_47 = Vec<SnapshotListItemMessageUntilV0_1_47>;
55
56 #[derive(Clone, Debug, PartialEq, Eq, Serialize, Deserialize)]
57 pub struct SnapshotListItemMessageUntilV0_1_47 {
58 pub digest: String,
59 pub network: String,
60 pub beacon: CardanoDbBeacon,
61 pub certificate_hash: String,
62 pub size: u64,
63 pub created_at: DateTime<Utc>,
64 pub locations: Vec<String>,
65 pub compression_algorithm: CompressionAlgorithm,
66 pub cardano_node_version: String,
67 }
68
69 const CURRENT_JSON: &str = r#"[{
70 "digest": "0b9f5ad7f33cc523775c82249294eb8a1541d54f08eb3107cafc5638403ec7c6",
71 "network": "preview",
72 "beacon": {
73 "epoch": 86,
74 "immutable_file_number": 1728
75 },
76 "certificate_hash": "d5daf6c03ace4a9c074e951844075b9b373bafc4e039160e3e2af01823e9abfb",
77 "size": 807803196,
78 "ancillary_size": 123456789,
79 "created_at": "2023-01-19T13:43:05.618857482Z",
80 "locations": [
81 "https://host/certificate.tar.gz"
82 ],
83 "ancillary_locations": [
84 "https://host/ancillary.tar.gz"
85 ],
86 "compression_algorithm": "zstandard",
87 "cardano_node_version": "1.0.0"
88 }]"#;
89
90 fn golden_message_until_open_api_0_1_47() -> SnapshotListMessageUntilV0_1_47 {
91 vec![SnapshotListItemMessageUntilV0_1_47 {
92 digest: "0b9f5ad7f33cc523775c82249294eb8a1541d54f08eb3107cafc5638403ec7c6".to_string(),
93 network: "preview".to_string(),
94 beacon: CardanoDbBeacon {
95 epoch: Epoch(86),
96 immutable_file_number: 1728,
97 },
98 certificate_hash: "d5daf6c03ace4a9c074e951844075b9b373bafc4e039160e3e2af01823e9abfb"
99 .to_string(),
100 size: 807803196,
101 created_at: DateTime::parse_from_rfc3339("2023-01-19T13:43:05.618857482Z")
102 .unwrap()
103 .with_timezone(&Utc),
104 locations: vec!["https://host/certificate.tar.gz".to_string()],
105 compression_algorithm: CompressionAlgorithm::Zstandard,
106 cardano_node_version: "1.0.0".to_string(),
107 }]
108 }
109
110 fn golden_message_current() -> SnapshotListMessage {
111 vec![SnapshotListItemMessage {
112 digest: "0b9f5ad7f33cc523775c82249294eb8a1541d54f08eb3107cafc5638403ec7c6".to_string(),
113 network: "preview".to_string(),
114 beacon: CardanoDbBeacon {
115 epoch: Epoch(86),
116 immutable_file_number: 1728,
117 },
118 certificate_hash: "d5daf6c03ace4a9c074e951844075b9b373bafc4e039160e3e2af01823e9abfb"
119 .to_string(),
120 size: 807803196,
121 ancillary_size: Some(123456789),
122 created_at: DateTime::parse_from_rfc3339("2023-01-19T13:43:05.618857482Z")
123 .unwrap()
124 .with_timezone(&Utc),
125 locations: vec!["https://host/certificate.tar.gz".to_string()],
126 ancillary_locations: Some(vec!["https://host/ancillary.tar.gz".to_string()]),
127 compression_algorithm: CompressionAlgorithm::Zstandard,
128 cardano_node_version: "1.0.0".to_string(),
129 }]
130 }
131
132 #[test]
133 fn test_current_json_deserialized_into_message_supported_until_open_api_0_1_47() {
134 let json = CURRENT_JSON;
135 let message: SnapshotListMessageUntilV0_1_47 = serde_json::from_str(json).unwrap();
136
137 assert_eq!(golden_message_until_open_api_0_1_47(), message);
138 }
139
140 #[test]
141 fn test_current_json_deserialized_into_current_message() {
142 let json = CURRENT_JSON;
143 let message: SnapshotListMessage = serde_json::from_str(json).unwrap();
144
145 assert_eq!(golden_message_current(), message);
146 }
147}