use chrono::{DateTime, Utc};
use serde::{Deserialize, Serialize};
use crate::entities::Epoch;
pub type MithrilStakeDistributionListMessage = Vec<MithrilStakeDistributionListItemMessage>;
#[derive(Clone, Debug, PartialEq, Eq, Default, Serialize, Deserialize)]
pub struct MithrilStakeDistributionListItemMessage {
pub epoch: Epoch,
pub hash: String,
pub certificate_hash: String,
pub created_at: DateTime<Utc>,
}
impl MithrilStakeDistributionListItemMessage {
pub fn dummy() -> Self {
Self {
epoch: Epoch(1),
hash: "hash-123".to_string(),
certificate_hash: "certificate-hash-123".to_string(),
created_at: DateTime::parse_from_rfc3339("2023-01-19T13:43:05.618857482Z")
.unwrap()
.with_timezone(&Utc),
}
}
}
#[cfg(test)]
mod tests {
use super::*;
fn golden_message() -> MithrilStakeDistributionListMessage {
vec![MithrilStakeDistributionListItemMessage {
epoch: Epoch(1),
hash: "hash-123".to_string(),
certificate_hash: "certificate-hash-123".to_string(),
created_at: DateTime::parse_from_rfc3339("2023-01-19T13:43:05.618857482Z")
.unwrap()
.with_timezone(&Utc),
}]
}
#[test]
fn test_v1() {
let json = r#"[{
"epoch": 1,
"hash": "hash-123",
"certificate_hash": "certificate-hash-123",
"created_at": "2023-01-19T13:43:05.618857482Z"
}]"#;
let message: MithrilStakeDistributionListMessage = serde_json::from_str(json).expect(
"This JSON is expected to be successfully parsed into a MithrilStakeDistributionListMessage instance.",
);
assert_eq!(golden_message(), message);
}
}