@@ -66,7 +66,8 @@ pub struct CertificateListItemMessage {
66
66
67
67
/// Mithril beacon on the Cardano chain
68
68
#[ deprecated( since = "0.3.25" , note = "use epoch and/or signed_entity_type instead" ) ]
69
- pub beacon : CardanoDbBeacon ,
69
+ #[ serde( skip_serializing_if = "Option::is_none" ) ]
70
+ pub beacon : Option < CardanoDbBeacon > ,
70
71
71
72
/// Certificate metadata
72
73
/// aka METADATA(p,n)
@@ -106,7 +107,7 @@ impl CertificateListItemMessage {
106
107
previous_hash : "previous_hash" . to_string ( ) ,
107
108
epoch,
108
109
signed_entity_type : SignedEntityType :: MithrilStakeDistribution ( epoch) ,
109
- beacon : CardanoDbBeacon :: new ( "testnet" , * epoch, 100 ) ,
110
+ beacon : Some ( CardanoDbBeacon :: new ( "testnet" , * epoch, 100 ) ) ,
110
111
metadata : CertificateListItemMessageMetadata {
111
112
network : "testnet" . to_string ( ) ,
112
113
protocol_version : "0.1.0" . to_string ( ) ,
@@ -161,7 +162,23 @@ impl Debug for CertificateListItemMessage {
161
162
mod tests {
162
163
use super :: * ;
163
164
164
- fn golden_message ( ) -> CertificateListMessage {
165
+ type CertificateListMessagePreviousVersion = Vec < CertificateListItemMessagePreviousVersion > ;
166
+
167
+ #[ derive( Debug , Clone , PartialEq , Serialize , Deserialize ) ]
168
+ struct CertificateListItemMessagePreviousVersion {
169
+ pub hash : String ,
170
+ pub previous_hash : String ,
171
+ pub epoch : Epoch ,
172
+ pub signed_entity_type : SignedEntityType ,
173
+ #[ deprecated( since = "0.3.25" , note = "use epoch and/or signed_entity_type instead" ) ]
174
+ pub beacon : CardanoDbBeacon ,
175
+ pub metadata : CertificateListItemMessageMetadata ,
176
+ pub protocol_message : ProtocolMessage ,
177
+ pub signed_message : String ,
178
+ pub aggregate_verification_key : String ,
179
+ }
180
+
181
+ fn golden_previous_message ( ) -> CertificateListItemMessagePreviousVersion {
165
182
let mut protocol_message = ProtocolMessage :: new ( ) ;
166
183
protocol_message. set_message_part (
167
184
ProtocolMessagePartKey :: SnapshotDigest ,
@@ -173,37 +190,69 @@ mod tests {
173
190
) ;
174
191
let epoch = Epoch ( 10 ) ;
175
192
176
- vec ! [
177
- #[ allow( deprecated) ]
178
- CertificateListItemMessage {
179
- hash: "hash" . to_string( ) ,
180
- previous_hash: "previous_hash" . to_string( ) ,
181
- epoch,
182
- signed_entity_type: SignedEntityType :: MithrilStakeDistribution ( epoch) ,
183
- beacon: CardanoDbBeacon :: new( "testnet" , * epoch, 100 ) ,
184
- metadata: CertificateListItemMessageMetadata {
185
- network: "testnet" . to_string( ) ,
186
- protocol_version: "0.1.0" . to_string( ) ,
187
- protocol_parameters: ProtocolParameters :: new( 1000 , 100 , 0.123 ) ,
188
- initiated_at: DateTime :: parse_from_rfc3339( "2024-02-12T13:11:47Z" )
189
- . unwrap( )
190
- . with_timezone( & Utc ) ,
191
- sealed_at: DateTime :: parse_from_rfc3339( "2024-02-12T13:12:57Z" )
192
- . unwrap( )
193
- . with_timezone( & Utc ) ,
194
- total_signers: 2 ,
195
- } ,
196
- protocol_message: protocol_message. clone( ) ,
197
- signed_message: "signed_message" . to_string( ) ,
198
- aggregate_verification_key: "aggregate_verification_key" . to_string( ) ,
193
+ #[ allow( deprecated) ]
194
+ CertificateListItemMessagePreviousVersion {
195
+ hash : "hash" . to_string ( ) ,
196
+ previous_hash : "previous_hash" . to_string ( ) ,
197
+ epoch,
198
+ signed_entity_type : SignedEntityType :: MithrilStakeDistribution ( epoch) ,
199
+ beacon : CardanoDbBeacon :: new ( "testnet" , * epoch, 100 ) ,
200
+ metadata : CertificateListItemMessageMetadata {
201
+ network : "testnet" . to_string ( ) ,
202
+ protocol_version : "0.1.0" . to_string ( ) ,
203
+ protocol_parameters : ProtocolParameters :: new ( 1000 , 100 , 0.123 ) ,
204
+ initiated_at : DateTime :: parse_from_rfc3339 ( "2024-02-12T13:11:47Z" )
205
+ . unwrap ( )
206
+ . with_timezone ( & Utc ) ,
207
+ sealed_at : DateTime :: parse_from_rfc3339 ( "2024-02-12T13:12:57Z" )
208
+ . unwrap ( )
209
+ . with_timezone ( & Utc ) ,
210
+ total_signers : 2 ,
199
211
} ,
200
- ]
212
+ protocol_message : protocol_message. clone ( ) ,
213
+ signed_message : "signed_message" . to_string ( ) ,
214
+ aggregate_verification_key : "aggregate_verification_key" . to_string ( ) ,
215
+ }
201
216
}
202
217
203
- // Test the retro compatibility with possible future upgrades.
204
- #[ test]
205
- fn test_v1 ( ) {
206
- let json = r#"[{
218
+ fn golden_actual_message ( ) -> CertificateListItemMessage {
219
+ let mut protocol_message = ProtocolMessage :: new ( ) ;
220
+ protocol_message. set_message_part (
221
+ ProtocolMessagePartKey :: SnapshotDigest ,
222
+ "snapshot-digest-123" . to_string ( ) ,
223
+ ) ;
224
+ protocol_message. set_message_part (
225
+ ProtocolMessagePartKey :: NextAggregateVerificationKey ,
226
+ "next-avk-123" . to_string ( ) ,
227
+ ) ;
228
+ let epoch = Epoch ( 10 ) ;
229
+
230
+ #[ allow( deprecated) ]
231
+ CertificateListItemMessage {
232
+ hash : "hash" . to_string ( ) ,
233
+ previous_hash : "previous_hash" . to_string ( ) ,
234
+ epoch,
235
+ signed_entity_type : SignedEntityType :: MithrilStakeDistribution ( epoch) ,
236
+ beacon : Some ( CardanoDbBeacon :: new ( "testnet" , * epoch, 100 ) ) ,
237
+ metadata : CertificateListItemMessageMetadata {
238
+ network : "testnet" . to_string ( ) ,
239
+ protocol_version : "0.1.0" . to_string ( ) ,
240
+ protocol_parameters : ProtocolParameters :: new ( 1000 , 100 , 0.123 ) ,
241
+ initiated_at : DateTime :: parse_from_rfc3339 ( "2024-02-12T13:11:47Z" )
242
+ . unwrap ( )
243
+ . with_timezone ( & Utc ) ,
244
+ sealed_at : DateTime :: parse_from_rfc3339 ( "2024-02-12T13:12:57Z" )
245
+ . unwrap ( )
246
+ . with_timezone ( & Utc ) ,
247
+ total_signers : 2 ,
248
+ } ,
249
+ protocol_message : protocol_message. clone ( ) ,
250
+ signed_message : "signed_message" . to_string ( ) ,
251
+ aggregate_verification_key : "aggregate_verification_key" . to_string ( ) ,
252
+ }
253
+ }
254
+
255
+ const ACTUAL_JSON : & str = r#"[{
207
256
"hash": "hash",
208
257
"previous_hash": "previous_hash",
209
258
"epoch": 10,
@@ -235,10 +284,61 @@ mod tests {
235
284
"aggregate_verification_key": "aggregate_verification_key"
236
285
}]"# ;
237
286
287
+ #[ test]
288
+ fn test_actual_json_deserialized_into_previous_message ( ) {
289
+ let json = ACTUAL_JSON ;
290
+ let message: CertificateListMessagePreviousVersion = serde_json:: from_str ( json) . unwrap ( ) ;
291
+
292
+ assert_eq ! ( vec![ golden_previous_message( ) ] , message) ;
293
+ }
294
+
295
+ #[ test]
296
+ fn test_actual_json_deserialized_into_actual_message ( ) {
297
+ let json = ACTUAL_JSON ;
298
+ let message: CertificateListMessage = serde_json:: from_str ( json) . unwrap ( ) ;
299
+
300
+ assert_eq ! ( vec![ golden_actual_message( ) ] , message) ;
301
+ }
302
+
303
+ #[ test]
304
+ fn test_json_next_version_deserialized_into_actual_message ( ) {
305
+ let json = r#"[{
306
+ "hash": "hash",
307
+ "previous_hash": "previous_hash",
308
+ "epoch": 10,
309
+ "signed_entity_type": { "MithrilStakeDistribution": 10 },
310
+ "metadata": {
311
+ "network": "testnet",
312
+ "version": "0.1.0",
313
+ "parameters": {
314
+ "k": 1000,
315
+ "m": 100,
316
+ "phi_f": 0.123
317
+ },
318
+ "initiated_at": "2024-02-12T13:11:47Z",
319
+ "sealed_at": "2024-02-12T13:12:57Z",
320
+ "total_signers": 2
321
+ },
322
+ "protocol_message": {
323
+ "message_parts": {
324
+ "snapshot_digest": "snapshot-digest-123",
325
+ "next_aggregate_verification_key": "next-avk-123"
326
+ }
327
+ },
328
+ "signed_message": "signed_message",
329
+ "aggregate_verification_key": "aggregate_verification_key"
330
+ }]"# ;
331
+
238
332
let message: CertificateListMessage = serde_json:: from_str ( json) . expect (
239
333
"This JSON is expected to be succesfully parsed into a CertificateListMessage instance." ,
240
334
) ;
241
335
242
- assert_eq ! ( golden_message( ) , message) ;
336
+ #[ allow( deprecated) ]
337
+ let golden_message = vec ! [ CertificateListItemMessage {
338
+ beacon: None ,
339
+ ..golden_actual_message( )
340
+ } ] ;
341
+
342
+ assert_eq ! ( golden_message, message) ;
243
343
}
244
344
}
0 commit comments