@@ -11,7 +11,8 @@ pub struct CertificatePendingMessage {
11
11
12
12
/// Current Beacon
13
13
#[ deprecated( since = "0.3.25" , note = "use epoch instead" ) ]
14
- pub beacon : CardanoDbBeacon ,
14
+ #[ serde( skip_serializing_if = "Option::is_none" ) ]
15
+ pub beacon : Option < CardanoDbBeacon > ,
15
16
16
17
/// Signed entity type
17
18
#[ serde( rename = "entity_type" ) ]
@@ -41,7 +42,7 @@ impl CertificatePendingMessage {
41
42
#[ allow( deprecated) ]
42
43
Self {
43
44
epoch: beacon. epoch,
44
- beacon,
45
+ beacon: None ,
45
46
signed_entity_type: SignedEntityType :: dummy( ) ,
46
47
protocol_parameters: ProtocolParameters {
47
48
k: 5 ,
@@ -62,21 +63,55 @@ impl CertificatePendingMessage {
62
63
63
64
#[ cfg( test) ]
64
65
mod tests {
66
+ #[ derive( Clone , Debug , PartialEq , Serialize , Deserialize ) ]
67
+ pub struct CertificatePendingMessagePreviousVersion {
68
+ /// Current Epoch
69
+ pub epoch : Epoch ,
70
+
71
+ /// Current Beacon
72
+ #[ deprecated( since = "0.3.25" , note = "use epoch instead" ) ]
73
+ pub beacon : CardanoDbBeacon ,
74
+
75
+ /// Signed entity type
76
+ #[ serde( rename = "entity_type" ) ]
77
+ pub signed_entity_type : SignedEntityType ,
78
+
79
+ /// Current Protocol parameters
80
+ #[ serde( rename = "protocol" ) ]
81
+ pub protocol_parameters : ProtocolParameters ,
82
+
83
+ /// Next Protocol parameters
84
+ #[ serde( rename = "next_protocol" ) ]
85
+ pub next_protocol_parameters : ProtocolParameters ,
86
+
87
+ /// Current Signers
88
+ pub signers : Vec < SignerMessagePart > ,
89
+
90
+ /// Signers that will be able to sign on the next epoch
91
+ pub next_signers : Vec < SignerMessagePart > ,
92
+ }
93
+
65
94
use crate :: entities:: Epoch ;
66
95
67
96
use super :: * ;
68
97
69
- fn golden_message ( ) -> CertificatePendingMessage {
98
+ fn golden_previous_message ( ) -> CertificatePendingMessagePreviousVersion {
70
99
let beacon = CardanoDbBeacon {
71
100
network : "preview" . to_string ( ) ,
72
101
epoch : Epoch ( 86 ) ,
73
102
immutable_file_number : 1728 ,
74
103
} ;
75
104
105
+ let deprecated_beacon = CardanoDbBeacon {
106
+ network : "" . to_string ( ) ,
107
+ epoch : Epoch ( 0 ) ,
108
+ immutable_file_number : 0 ,
109
+ } ;
110
+
76
111
#[ allow( deprecated) ]
77
- CertificatePendingMessage {
112
+ CertificatePendingMessagePreviousVersion {
78
113
epoch : beacon. epoch ,
79
- beacon : beacon . clone ( ) ,
114
+ beacon : deprecated_beacon ,
80
115
signed_entity_type : SignedEntityType :: CardanoImmutableFilesFull ( beacon) ,
81
116
protocol_parameters : ProtocolParameters {
82
117
k : 5 ,
@@ -109,14 +144,12 @@ mod tests {
109
144
}
110
145
}
111
146
112
- #[ test]
113
- fn test_v1 ( ) {
114
- let json = r#"{
147
+ const ACTUAL_JSON : & str = r#"{
115
148
"epoch": 86,
116
149
"beacon": {
117
- "network": "preview ",
118
- "epoch": 86 ,
119
- "immutable_file_number": 1728
150
+ "network": "",
151
+ "epoch": 0 ,
152
+ "immutable_file_number": 0
120
153
},
121
154
"entity_type": {
122
155
"CardanoImmutableFilesFull": {
@@ -148,8 +181,113 @@ mod tests {
148
181
}
149
182
]
150
183
}"# ;
184
+
185
+ fn golden_actual_message ( ) -> CertificatePendingMessage {
186
+ let beacon = CardanoDbBeacon {
187
+ network : "preview" . to_string ( ) ,
188
+ epoch : Epoch ( 86 ) ,
189
+ immutable_file_number : 1728 ,
190
+ } ;
191
+ let deprecated_beacon = CardanoDbBeacon {
192
+ network : "" . to_string ( ) ,
193
+ epoch : Epoch ( 0 ) ,
194
+ immutable_file_number : 0 ,
195
+ } ;
196
+
197
+ #[ allow( deprecated) ]
198
+ CertificatePendingMessage {
199
+ epoch : beacon. epoch ,
200
+ beacon : Some ( deprecated_beacon) ,
201
+ signed_entity_type : SignedEntityType :: CardanoImmutableFilesFull ( beacon) ,
202
+ protocol_parameters : ProtocolParameters {
203
+ k : 5 ,
204
+ m : 100 ,
205
+ phi_f : 0.65 ,
206
+ } ,
207
+ next_protocol_parameters : ProtocolParameters {
208
+ k : 50 ,
209
+ m : 1000 ,
210
+ phi_f : 0.65 ,
211
+ } ,
212
+ signers : vec ! [
213
+ SignerMessagePart {
214
+ party_id: "123" . to_string( ) ,
215
+ verification_key: "7b22766b223a5b3134332c3136312c3235352c34382c37382c35372c3230342c3232302c32352c3232312c3136342c3235322c3234382c31342c35362c3132362c3138362c3133352c3232382c3138382c3134352c3138312c35322c3230302c39372c39392c3231332c34362c302c3139392c3139332c38392c3138372c38382c32392c3133352c3137332c3234342c38362c33362c38332c35342c36372c3136342c362c3133372c39342c37322c362c3130352c3132382c3132382c39332c34382c3137362c31312c342c3234362c3133382c34382c3138302c3133332c39302c3134322c3139322c32342c3139332c3131312c3134322c33312c37362c3131312c3131302c3233342c3135332c39302c3230382c3139322c33312c3132342c39352c3130322c34392c3135382c39392c35322c3232302c3136352c39342c3235312c36382c36392c3132312c31362c3232342c3139345d2c22706f70223a5b3136382c35302c3233332c3139332c31352c3133362c36352c37322c3132332c3134382c3132392c3137362c33382c3139382c3230392c34372c32382c3230342c3137362c3134342c35372c3235312c34322c32382c36362c37362c38392c39372c3135382c36332c35342c3139382c3139342c3137362c3133352c3232312c31342c3138352c3139372c3232352c3230322c39382c3234332c37342c3233332c3232352c3134332c3135312c3134372c3137372c3137302c3131372c36362c3136352c36362c36322c33332c3231362c3233322c37352c36382c3131342c3139352c32322c3130302c36352c34342c3139382c342c3136362c3130322c3233332c3235332c3234302c35392c3137352c36302c3131372c3134322c3131342c3134302c3132322c31372c38372c3131302c3138372c312c31372c31302c3139352c3135342c31332c3234392c38362c35342c3232365d7d" . to_string( ) ,
216
+ verification_key_signature: None ,
217
+ operational_certificate: None ,
218
+ kes_period: None
219
+ }
220
+ ] ,
221
+ next_signers : vec ! [
222
+ SignerMessagePart {
223
+ party_id: "123" . to_string( ) ,
224
+ verification_key: "7b22766b223a5b3134332c3136312c3235352c34382c37382c35372c3230342c3232302c32352c3232312c3136342c3235322c3234382c31342c35362c3132362c3138362c3133352c3232382c3138382c3134352c3138312c35322c3230302c39372c39392c3231332c34362c302c3139392c3139332c38392c3138372c38382c32392c3133352c3137332c3234342c38362c33362c38332c35342c36372c3136342c362c3133372c39342c37322c362c3130352c3132382c3132382c39332c34382c3137362c31312c342c3234362c3133382c34382c3138302c3133332c39302c3134322c3139322c32342c3139332c3131312c3134322c33312c37362c3131312c3131302c3233342c3135332c39302c3230382c3139322c33312c3132342c39352c3130322c34392c3135382c39392c35322c3232302c3136352c39342c3235312c36382c36392c3132312c31362c3232342c3139345d2c22706f70223a5b3136382c35302c3233332c3139332c31352c3133362c36352c37322c3132332c3134382c3132392c3137362c33382c3139382c3230392c34372c32382c3230342c3137362c3134342c35372c3235312c34322c32382c36362c37362c38392c39372c3135382c36332c35342c3139382c3139342c3137362c3133352c3232312c31342c3138352c3139372c3232352c3230322c39382c3234332c37342c3233332c3232352c3134332c3135312c3134372c3137372c3137302c3131372c36362c3136352c36362c36322c33332c3231362c3233322c37352c36382c3131342c3139352c32322c3130302c36352c34342c3139382c342c3136362c3130322c3233332c3235332c3234302c35392c3137352c36302c3131372c3134322c3131342c3134302c3132322c31372c38372c3131302c3138372c312c31372c31302c3139352c3135342c31332c3234392c38362c35342c3232365d7d" . to_string( ) ,
225
+ verification_key_signature: None ,
226
+ operational_certificate: None ,
227
+ kes_period: None
228
+ }
229
+ ] ,
230
+ }
231
+ }
232
+
233
+ #[ test]
234
+ fn test_actual_json_deserialized_into_previous_message ( ) {
235
+ let json = ACTUAL_JSON ;
236
+ let message: CertificatePendingMessagePreviousVersion = serde_json:: from_str ( json) . unwrap ( ) ;
237
+
238
+ assert_eq ! ( golden_previous_message( ) , message) ;
239
+ }
240
+
241
+ #[ test]
242
+ fn test_actual_json_deserialized_into_actual_message ( ) {
243
+ let json = ACTUAL_JSON ;
151
244
let message: CertificatePendingMessage = serde_json:: from_str ( json) . unwrap ( ) ;
152
245
153
- assert_eq ! ( golden_message( ) , message) ;
246
+ assert_eq ! ( golden_actual_message( ) , message) ;
247
+ }
248
+
249
+ #[ test]
250
+ fn test_json_next_version_deserialized_into_actual_message ( ) {
251
+ let next_json = r#"{
252
+ "epoch": 86,
253
+ "entity_type": {
254
+ "CardanoImmutableFilesFull": {
255
+ "network": "preview",
256
+ "epoch": 86,
257
+ "immutable_file_number": 1728
258
+ }
259
+ },
260
+ "protocol": {
261
+ "k": 5,
262
+ "m": 100,
263
+ "phi_f": 0.65
264
+ },
265
+ "next_protocol": {
266
+ "k": 50,
267
+ "m": 1000,
268
+ "phi_f": 0.65
269
+ },
270
+ "signers": [
271
+ {
272
+ "party_id": "123",
273
+ "verification_key": "7b22766b223a5b3134332c3136312c3235352c34382c37382c35372c3230342c3232302c32352c3232312c3136342c3235322c3234382c31342c35362c3132362c3138362c3133352c3232382c3138382c3134352c3138312c35322c3230302c39372c39392c3231332c34362c302c3139392c3139332c38392c3138372c38382c32392c3133352c3137332c3234342c38362c33362c38332c35342c36372c3136342c362c3133372c39342c37322c362c3130352c3132382c3132382c39332c34382c3137362c31312c342c3234362c3133382c34382c3138302c3133332c39302c3134322c3139322c32342c3139332c3131312c3134322c33312c37362c3131312c3131302c3233342c3135332c39302c3230382c3139322c33312c3132342c39352c3130322c34392c3135382c39392c35322c3232302c3136352c39342c3235312c36382c36392c3132312c31362c3232342c3139345d2c22706f70223a5b3136382c35302c3233332c3139332c31352c3133362c36352c37322c3132332c3134382c3132392c3137362c33382c3139382c3230392c34372c32382c3230342c3137362c3134342c35372c3235312c34322c32382c36362c37362c38392c39372c3135382c36332c35342c3139382c3139342c3137362c3133352c3232312c31342c3138352c3139372c3232352c3230322c39382c3234332c37342c3233332c3232352c3134332c3135312c3134372c3137372c3137302c3131372c36362c3136352c36362c36322c33332c3231362c3233322c37352c36382c3131342c3139352c32322c3130302c36352c34342c3139382c342c3136362c3130322c3233332c3235332c3234302c35392c3137352c36302c3131372c3134322c3131342c3134302c3132322c31372c38372c3131302c3138372c312c31372c31302c3139352c3135342c31332c3234392c38362c35342c3232365d7d"
274
+ }
275
+ ],
276
+ "next_signers": [
277
+ {
278
+ "party_id": "123",
279
+ "verification_key": "7b22766b223a5b3134332c3136312c3235352c34382c37382c35372c3230342c3232302c32352c3232312c3136342c3235322c3234382c31342c35362c3132362c3138362c3133352c3232382c3138382c3134352c3138312c35322c3230302c39372c39392c3231332c34362c302c3139392c3139332c38392c3138372c38382c32392c3133352c3137332c3234342c38362c33362c38332c35342c36372c3136342c362c3133372c39342c37322c362c3130352c3132382c3132382c39332c34382c3137362c31312c342c3234362c3133382c34382c3138302c3133332c39302c3134322c3139322c32342c3139332c3131312c3134322c33312c37362c3131312c3131302c3233342c3135332c39302c3230382c3139322c33312c3132342c39352c3130322c34392c3135382c39392c35322c3232302c3136352c39342c3235312c36382c36392c3132312c31362c3232342c3139345d2c22706f70223a5b3136382c35302c3233332c3139332c31352c3133362c36352c37322c3132332c3134382c3132392c3137362c33382c3139382c3230392c34372c32382c3230342c3137362c3134342c35372c3235312c34322c32382c36362c37362c38392c39372c3135382c36332c35342c3139382c3139342c3137362c3133352c3232312c31342c3138352c3139372c3232352c3230322c39382c3234332c37342c3233332c3232352c3134332c3135312c3134372c3137372c3137302c3131372c36362c3136352c36362c36322c33332c3231362c3233322c37352c36382c3131342c3139352c32322c3130302c36352c34342c3139382c342c3136362c3130322c3233332c3235332c3234302c35392c3137352c36302c3131372c3134322c3131342c3134302c3132322c31372c38372c3131302c3138372c312c31372c31302c3139352c3135342c31332c3234392c38362c35342c3232365d7d"
280
+ }
281
+ ]
282
+ }"# ;
283
+ let message: CertificatePendingMessage = serde_json:: from_str ( next_json) . unwrap ( ) ;
284
+
285
+ #[ allow( deprecated) ]
286
+ let golden_message = CertificatePendingMessage {
287
+ beacon : None ,
288
+ ..golden_actual_message ( )
289
+ } ;
290
+
291
+ assert_eq ! ( golden_message, message) ;
154
292
}
155
293
}
0 commit comments