mithril_common/messages/message_parts/
certificate_metadata.rs1use crate::entities::{ProtocolParameters, ProtocolVersion, StakeDistributionParty};
2
3use chrono::{DateTime, Utc};
4use serde::{Deserialize, Serialize};
5
6#[derive(Clone, Debug, PartialEq, Serialize, Deserialize)]
8pub struct CertificateMetadataMessagePart {
9 pub network: String,
12
13 #[serde(rename = "version")]
17 pub protocol_version: ProtocolVersion,
18
19 #[serde(rename = "parameters")]
22 pub protocol_parameters: ProtocolParameters,
23
24 pub initiated_at: DateTime<Utc>,
28
29 pub sealed_at: DateTime<Utc>,
33
34 pub signers: Vec<StakeDistributionParty>,
37}
38
39#[cfg(test)]
40mod tests {
41 use super::*;
42
43 fn golden_message_current() -> CertificateMetadataMessagePart {
44 CertificateMetadataMessagePart {
45 network: "testnet".to_string(),
46 protocol_version: "0.1.0".to_string(),
47 protocol_parameters: ProtocolParameters::new(1000, 100, 0.123),
48 initiated_at: DateTime::parse_from_rfc3339("2024-02-12T13:11:47Z")
49 .unwrap()
50 .with_timezone(&Utc),
51 sealed_at: DateTime::parse_from_rfc3339("2024-02-12T13:12:57Z")
52 .unwrap()
53 .with_timezone(&Utc),
54 signers: vec![
55 StakeDistributionParty {
56 party_id: "1".to_string(),
57 stake: 10,
58 },
59 StakeDistributionParty {
60 party_id: "2".to_string(),
61 stake: 20,
62 },
63 ],
64 }
65 }
66
67 const CURRENT_JSON: &str = r#"{
68 "network": "testnet",
69 "version": "0.1.0",
70 "parameters": {
71 "k": 1000,
72 "m": 100,
73 "phi_f": 0.123
74 },
75 "initiated_at": "2024-02-12T13:11:47Z",
76 "sealed_at": "2024-02-12T13:12:57Z",
77 "signers": [
78 {
79 "party_id": "1",
80 "stake": 10
81 },
82 {
83 "party_id": "2",
84 "stake": 20
85 }
86 ]
87 }"#;
88
89 #[test]
90 fn test_current_json_deserialized_into_current_message() {
91 let json = CURRENT_JSON;
92 let message: CertificateMetadataMessagePart = serde_json::from_str(json).expect(
93 "This JSON is expected to be successfully parsed into a CertificateMetadataMessagePart instance.",
94 );
95
96 assert_eq!(golden_message_current(), message);
97 }
98}