mithril_common/messages/
snapshot_download.rsuse serde::{Deserialize, Serialize};
use crate::entities::{CompressionAlgorithm, Epoch};
use crate::messages::CardanoDbBeaconMessagePart;
#[derive(Clone, Debug, PartialEq, Eq, Serialize, Deserialize)]
pub struct SnapshotDownloadMessage {
pub digest: String,
pub network: String,
pub beacon: CardanoDbBeaconMessagePart,
pub size: u64,
pub locations: Vec<String>,
pub compression_algorithm: CompressionAlgorithm,
pub cardano_node_version: String,
}
impl SnapshotDownloadMessage {
pub fn dummy() -> Self {
Self {
digest: "0b9f5ad7f33cc523775c82249294eb8a1541d54f08eb3107cafc5638403ec7c6".to_string(),
network: "preview".to_string(),
beacon: CardanoDbBeaconMessagePart {
network: Some("preview".to_string()),
epoch: Epoch(86),
immutable_file_number: 1728,
},
size: 807803196,
locations: vec!["https://host/certificate.tar.gz".to_string()],
compression_algorithm: CompressionAlgorithm::Gzip,
cardano_node_version: "0.0.1".to_string(),
}
}
}
#[cfg(test)]
mod tests {
use super::*;
use crate::messages::CardanoDbBeaconMessagePart;
const ACTUAL_JSON: &str = r#"{
"digest": "0b9f5ad7f33cc523775c82249294eb8a1541d54f08eb3107cafc5638403ec7c6",
"network": "preview",
"beacon": {
"network": "preview",
"epoch": 86,
"immutable_file_number": 1728
},
"size": 807803196,
"locations": [
"https://host/certificate.tar.gz"
],
"compression_algorithm": "gzip",
"cardano_node_version": "0.0.1"
}"#;
fn golden_message_actual() -> SnapshotDownloadMessage {
SnapshotDownloadMessage {
digest: "0b9f5ad7f33cc523775c82249294eb8a1541d54f08eb3107cafc5638403ec7c6".to_string(),
network: "preview".to_string(),
beacon: CardanoDbBeaconMessagePart {
network: Some("preview".to_string()),
epoch: Epoch(86),
immutable_file_number: 1728,
},
size: 807803196,
locations: vec!["https://host/certificate.tar.gz".to_string()],
compression_algorithm: CompressionAlgorithm::Gzip,
cardano_node_version: "0.0.1".to_string(),
}
}
#[test]
fn test_actual_json_deserialized_into_actual_message() {
let json = ACTUAL_JSON;
let message: SnapshotDownloadMessage = serde_json::from_str(json).unwrap();
assert_eq!(golden_message_actual(), message);
}
}