mithril_common/messages/
cardano_database_list.rsuse chrono::{DateTime, Utc};
use serde::{Deserialize, Serialize};
use crate::entities::{CardanoDbBeacon, CompressionAlgorithm, Epoch};
pub type CardanoDatabaseSnapshotListMessage = Vec<CardanoDatabaseSnapshotListItemMessage>;
#[derive(Clone, Debug, PartialEq, Eq, Serialize, Deserialize)]
pub struct CardanoDatabaseSnapshotListItemMessage {
pub merkle_root: String,
pub beacon: CardanoDbBeacon,
pub certificate_hash: String,
pub total_db_size_uncompressed: u64,
pub compression_algorithm: CompressionAlgorithm,
pub cardano_node_version: String,
pub created_at: DateTime<Utc>,
}
impl CardanoDatabaseSnapshotListItemMessage {
pub fn dummy() -> Self {
Self {
merkle_root: "c8224920b9f5ad7377594eb8a15f34f08eb3103cc5241d57cafc5638403ec7c6"
.to_string(),
beacon: CardanoDbBeacon {
epoch: Epoch(123),
immutable_file_number: 2345,
},
certificate_hash: "f6c01b373bafc4e039844071d5da3ace4a9c0745b9e9560e3e2af01823e9abfb"
.to_string(),
total_db_size_uncompressed: 800796318,
created_at: DateTime::parse_from_rfc3339("2023-01-19T13:43:05.618857482Z")
.unwrap()
.with_timezone(&Utc),
compression_algorithm: CompressionAlgorithm::default(),
cardano_node_version: "0.0.1".to_string(),
}
}
}
#[cfg(test)]
mod tests {
use super::*;
const ACTUAL_JSON: &str = r#"
[
{
"merkle_root": "c8224920b9f5ad7377594eb8a15f34f08eb3103cc5241d57cafc5638403ec7c6",
"beacon": {
"epoch": 123,
"immutable_file_number": 2345
},
"certificate_hash": "f6c01b373bafc4e039844071d5da3ace4a9c0745b9e9560e3e2af01823e9abfb",
"total_db_size_uncompressed": 800796318,
"compression_algorithm": "gzip",
"cardano_node_version": "0.0.1",
"created_at": "2023-01-19T13:43:05.618857482Z"
}
]"#;
fn golden_actual_message() -> CardanoDatabaseSnapshotListMessage {
vec![CardanoDatabaseSnapshotListItemMessage {
merkle_root: "c8224920b9f5ad7377594eb8a15f34f08eb3103cc5241d57cafc5638403ec7c6"
.to_string(),
beacon: CardanoDbBeacon {
epoch: Epoch(123),
immutable_file_number: 2345,
},
certificate_hash: "f6c01b373bafc4e039844071d5da3ace4a9c0745b9e9560e3e2af01823e9abfb"
.to_string(),
total_db_size_uncompressed: 800796318,
created_at: DateTime::parse_from_rfc3339("2023-01-19T13:43:05.618857482Z")
.unwrap()
.with_timezone(&Utc),
compression_algorithm: CompressionAlgorithm::default(),
cardano_node_version: "0.0.1".to_string(),
}]
}
#[test]
fn test_actual_json_deserialized_into_actual_message() {
let json = ACTUAL_JSON;
let message: CardanoDatabaseSnapshotListMessage = serde_json::from_str(json).expect(
"This JSON is expected to be successfully parsed into a CardanoDatabaseSnapshotListMessage instance.",
);
assert_eq!(golden_actual_message(), message);
}
}