mithril_common/test/double/
dummies.rs

1use chrono::{DateTime, Utc};
2
3use crate::test::double::{Dummy, fake_data, fake_keys};
4
5mod entities {
6    use crate::crypto_helper::MKTreeStoreInMemory;
7    use crate::entities::*;
8    use crate::test::entities_extensions::CardanoTransactionsSetProofTestExtension;
9
10    use super::*;
11
12    impl Dummy for ChainPoint {
13        /// Return a dummy [ChainPoint] (test-only).
14        fn dummy() -> Self {
15            Self {
16                slot_number: SlotNumber(100),
17                block_number: BlockNumber(0),
18                block_hash: "block_hash-50".to_string(),
19            }
20        }
21    }
22
23    impl Dummy for CardanoTransactionsSetProof {
24        /// Return a dummy [CardanoTransactionsSetProof] (test-only).
25        fn dummy() -> Self {
26            let leaves = vec![
27                (BlockNumber(0), "tx-1".to_string()),
28                (BlockNumber(1), "tx-2".to_string()),
29                (BlockNumber(1), "tx-3".to_string()),
30                (BlockNumber(10), "tx-4".to_string()),
31                (BlockNumber(20), "tx-5".to_string()),
32                (BlockNumber(22), "tx-6".to_string()),
33            ];
34
35            Self::from_leaves::<MKTreeStoreInMemory>(&leaves).unwrap()
36        }
37    }
38
39    impl Dummy for SignedEntityConfig {
40        /// Return a dummy [SignedEntityConfig] (test-only).
41        fn dummy() -> Self {
42            Self {
43                allowed_discriminants: SignedEntityTypeDiscriminants::all(),
44                cardano_transactions_signing_config: Some(CardanoTransactionsSigningConfig::dummy()),
45                cardano_blocks_transactions_signing_config: Some(
46                    CardanoBlocksTransactionsSigningConfig::dummy(),
47                ),
48            }
49        }
50    }
51
52    impl Dummy for CardanoTransactionsSigningConfig {
53        /// Return a dummy [CardanoTransactionsSigningConfig] (test-only).
54        fn dummy() -> Self {
55            Self {
56                security_parameter: BlockNumber(0),
57                step: BlockNumber(15),
58            }
59        }
60    }
61
62    impl Dummy for CardanoBlocksTransactionsSigningConfig {
63        /// Return a dummy [CardanoBlocksTransactionsSigningConfig] (test-only).
64        fn dummy() -> Self {
65            Self {
66                security_parameter: BlockNumber(0),
67                step: BlockNumber(15),
68            }
69        }
70    }
71
72    impl Dummy for SignedEntityType {
73        /// Return a dummy [SignedEntityType] (test-only).
74        fn dummy() -> Self {
75            Self::MithrilStakeDistribution(Epoch(5))
76        }
77    }
78
79    impl Dummy for SupportedEra {
80        /// Return a dummy [SupportedEra] (test-only).
81        fn dummy() -> Self {
82            Self::eras().first().unwrap().to_owned()
83        }
84    }
85
86    impl Dummy for TimePoint {
87        /// Return a dummy [TimePoint] (test-only).
88        fn dummy() -> Self {
89            Self::new(10, 100, ChainPoint::dummy())
90        }
91    }
92
93    impl Dummy for ClientError {
94        /// Return a dummy [ClientError] (test-only).
95        fn dummy() -> Self {
96            Self::new("error", "error message")
97        }
98    }
99
100    impl Dummy for ServerError {
101        /// Return a dummy [ServerError] (test-only).
102        fn dummy() -> Self {
103            Self::new("error")
104        }
105    }
106}
107
108mod messages {
109    use std::collections::BTreeSet;
110
111    use chrono::Duration;
112
113    use mithril_stm::AggregateSignatureType;
114
115    use crate::crypto_helper::KesEvolutions;
116    use crate::entities::{
117        AncillaryLocation, BlockNumber, CardanoBlocksTransactionsSigningConfig, CardanoDbBeacon,
118        CardanoTransactionsSetProof, CardanoTransactionsSigningConfig, CompressionAlgorithm,
119        DigestLocation, Epoch, ImmutablesLocation, MultiFilesUri, ProtocolMessage,
120        ProtocolMessagePartKey, ProtocolParameters, SignedEntityType,
121        SignedEntityTypeDiscriminants, StakeDistribution, StakeDistributionParty, SupportedEra,
122        TemplateUri,
123    };
124    use crate::messages::*;
125
126    use super::*;
127
128    impl Dummy for CardanoTransactionsSetProofMessagePart {
129        /// Return a dummy [CardanoTransactionsSetProofMessagePart] (test-only).
130        fn dummy() -> Self {
131            CardanoTransactionsSetProof::dummy().try_into().unwrap()
132        }
133    }
134
135    impl Dummy for CertificateMetadataMessagePart {
136        /// Return a dummy [CertificateMetadataMessagePart] (test-only).
137        fn dummy() -> Self {
138            let initiated_at = DateTime::parse_from_rfc3339("2024-02-12T13:11:47Z")
139                .unwrap()
140                .with_timezone(&Utc);
141
142            Self {
143                network: "testnet".to_string(),
144                protocol_version: "0.1.0".to_string(),
145                protocol_parameters: ProtocolParameters::new(1000, 100, 0.123),
146                initiated_at,
147                sealed_at: initiated_at + Duration::try_seconds(100).unwrap(),
148                signers: vec![
149                    StakeDistributionParty {
150                        party_id: "1".to_string(),
151                        stake: 10,
152                    },
153                    StakeDistributionParty {
154                        party_id: "2".to_string(),
155                        stake: 20,
156                    },
157                ],
158            }
159        }
160    }
161
162    impl Dummy for SignerWithStakeMessagePart {
163        /// Return a dummy [SignerWithStakeMessagePart] (test-only).
164        fn dummy() -> Self {
165            Self {
166                party_id: "pool1m8crhnqj5k2kyszf5j2scshupystyxc887zdfrpzh6ty6eun4fx".to_string(),
167                verification_key_for_concatenation: fake_keys::signer_verification_key()[0]
168                    .to_string(),
169                verification_key_signature_for_concatenation: Some(
170                    fake_keys::signer_verification_key_signature()[0].to_string(),
171                ),
172                operational_certificate: Some(fake_keys::operational_certificate()[0].to_string()),
173                kes_evolutions: Some(KesEvolutions(6)),
174                stake: 234,
175                #[cfg(feature = "future_snark")]
176                verification_key_for_snark: None,
177                #[cfg(feature = "future_snark")]
178                verification_key_signature_for_snark: None,
179            }
180        }
181    }
182
183    impl Dummy for SignerMessagePart {
184        /// Return a dummy [SignerMessagePart] (test-only).
185        fn dummy() -> Self {
186            Self {
187                party_id: "pool1m8crhnqj5k2kyszf5j2scshupystyxc887zdfrpzh6ty6eun4fx".to_string(),
188                verification_key_for_concatenation: fake_keys::signer_verification_key()[0]
189                    .to_string(),
190                verification_key_signature_for_concatenation: Some(
191                    fake_keys::signer_verification_key_signature()[0].to_string(),
192                ),
193                operational_certificate: Some(fake_keys::operational_certificate()[0].to_string()),
194                kes_evolutions: Some(KesEvolutions(6)),
195                #[cfg(feature = "future_snark")]
196                verification_key_for_snark: None,
197                #[cfg(feature = "future_snark")]
198                verification_key_signature_for_snark: None,
199            }
200        }
201    }
202
203    impl Dummy for AggregatorFeaturesMessage {
204        /// Return a dummy [AggregatorFeaturesMessage] (test-only).
205        fn dummy() -> Self {
206            AggregatorFeaturesMessage {
207                open_api_version: "0.0.1".to_string(),
208                documentation_url: "https://example.com".to_string(),
209                capabilities: AggregatorCapabilities {
210                    signed_entity_types: BTreeSet::from([
211                        SignedEntityTypeDiscriminants::MithrilStakeDistribution,
212                    ]),
213                    aggregate_signature_type: AggregateSignatureType::Concatenation,
214                    cardano_transactions_prover: None,
215                },
216            }
217        }
218    }
219
220    impl Dummy for AggregatorStatusMessage {
221        /// Return a dummy [AggregatorStatusMessage] (test-only).
222        fn dummy() -> Self {
223            AggregatorStatusMessage {
224                epoch: Epoch(10),
225                cardano_era: "conway".to_string(),
226                cardano_network: "devnet".to_string(),
227                mithril_era: SupportedEra::Pythagoras,
228                cardano_node_version: "10.4.1".to_string(),
229                aggregator_node_version: "0.6.24".to_string(),
230                protocol_parameters: ProtocolParameters::new(1000, 100, 0.123),
231                next_protocol_parameters: ProtocolParameters::new(2000, 200, 0.321),
232                total_signers: 10,
233                total_next_signers: 15,
234                total_stakes_signers: 100_000,
235                total_next_stakes_signers: 150_000,
236                total_cardano_spo: 100,
237                total_cardano_stake: 1_000_000,
238            }
239        }
240    }
241
242    impl Dummy for CardanoDatabaseSnapshotMessage {
243        /// Return a dummy [CardanoDatabaseSnapshotMessage] (test-only).
244        fn dummy() -> Self {
245            Self {
246                hash: "d4071d518a3ace0f6c04a9c0745b9e9560e3e2af1b373bafc4e0398423e9abfb"
247                    .to_string(),
248                merkle_root: "c8224920b9f5ad7377594eb8a15f34f08eb3103cc5241d57cafc5638403ec7c6"
249                    .to_string(),
250                network: "preview".to_string(),
251                beacon: CardanoDbBeacon {
252                    epoch: Epoch(123),
253                    immutable_file_number: 2345,
254                },
255                certificate_hash:
256                    "f6c01b373bafc4e039844071d5da3ace4a9c0745b9e9560e3e2af01823e9abfb".to_string(),
257                total_db_size_uncompressed: 800796318,
258                created_at: DateTime::parse_from_rfc3339("2023-01-19T13:43:05.618857482Z")
259                    .unwrap()
260                    .with_timezone(&Utc),
261                digests: DigestsMessagePart {
262                    size_uncompressed: 1024,
263                    locations: vec![DigestLocation::Aggregator {
264                        uri: "https://host-1/digest-1".to_string(),
265                    }],
266                },
267                immutables: ImmutablesMessagePart {
268                    average_size_uncompressed: 512,
269                    locations: vec![
270                        ImmutablesLocation::CloudStorage {
271                            uri: MultiFilesUri::Template(TemplateUri(
272                                "https://host-1/immutables-2".to_string(),
273                            )),
274                            compression_algorithm: Some(CompressionAlgorithm::Gzip),
275                        },
276                        ImmutablesLocation::CloudStorage {
277                            uri: MultiFilesUri::Template(TemplateUri(
278                                "https://host-2/immutables-2".to_string(),
279                            )),
280                            compression_algorithm: Some(CompressionAlgorithm::Gzip),
281                        },
282                    ],
283                },
284                ancillary: AncillaryMessagePart {
285                    size_uncompressed: 2048,
286                    locations: vec![AncillaryLocation::CloudStorage {
287                        uri: "https://host-1/ancillary-3".to_string(),
288                        compression_algorithm: Some(CompressionAlgorithm::Gzip),
289                    }],
290                },
291                cardano_node_version: "0.0.1".to_string(),
292            }
293        }
294    }
295
296    impl Dummy for CardanoDatabaseDigestListItemMessage {
297        /// Return a dummy [CardanoDatabaseDigestListItemMessage] (test-only).
298        fn dummy() -> Self {
299            Self {
300                immutable_file_name: "06685.chunk".to_string(),
301                digest: "0af556ab2620dd9363bf76963a231abe8948a500ea6be31b131d87907ab09b1e"
302                    .to_string(),
303            }
304        }
305    }
306
307    impl Dummy for CardanoDatabaseImmutableFilesRestoredMessage {
308        /// Return a dummy [CardanoDatabaseImmutableFilesRestoredMessage] (test-only).
309        fn dummy() -> Self {
310            Self {
311                nb_immutable_files: 34,
312            }
313        }
314    }
315
316    impl Dummy for CardanoDatabaseSnapshotListItemMessage {
317        /// Return a dummy [CardanoDatabaseSnapshotListItemMessage] (test-only).
318        fn dummy() -> Self {
319            Self {
320                hash: "d4071d518a3ace0f6c04a9c0745b9e9560e3e2af1b373bafc4e0398423e9abfb"
321                    .to_string(),
322                merkle_root: "c8224920b9f5ad7377594eb8a15f34f08eb3103cc5241d57cafc5638403ec7c6"
323                    .to_string(),
324                beacon: CardanoDbBeacon {
325                    epoch: Epoch(123),
326                    immutable_file_number: 2345,
327                },
328                certificate_hash:
329                    "f6c01b373bafc4e039844071d5da3ace4a9c0745b9e9560e3e2af01823e9abfb".to_string(),
330                total_db_size_uncompressed: 800796318,
331                created_at: DateTime::parse_from_rfc3339("2023-01-19T13:43:05.618857482Z")
332                    .unwrap()
333                    .with_timezone(&Utc),
334                cardano_node_version: "0.0.1".to_string(),
335            }
336        }
337    }
338
339    impl Dummy for CardanoStakeDistributionMessage {
340        /// Return a dummy [CardanoStakeDistributionMessage] (test-only).
341        fn dummy() -> Self {
342            Self {
343                epoch: Epoch(1),
344                hash: "hash-123".to_string(),
345                certificate_hash: "cert-hash-123".to_string(),
346                stake_distribution: StakeDistribution::from([("pool-123".to_string(), 1000)]),
347                created_at: DateTime::parse_from_rfc3339("2024-07-29T16:15:05.618857482Z")
348                    .unwrap()
349                    .with_timezone(&Utc),
350            }
351        }
352    }
353
354    impl Dummy for CardanoStakeDistributionListItemMessage {
355        /// Return a dummy [CardanoStakeDistributionListItemMessage] (test-only).
356        fn dummy() -> Self {
357            Self {
358                epoch: Epoch(1),
359                hash: "hash-123".to_string(),
360                certificate_hash: "certificate-hash-123".to_string(),
361                created_at: DateTime::parse_from_rfc3339("2024-07-29T16:15:05.618857482Z")
362                    .unwrap()
363                    .with_timezone(&Utc),
364            }
365        }
366    }
367
368    impl Dummy for CardanoTransactionSnapshotMessage {
369        /// Return a dummy [CardanoTransactionSnapshotMessage] (test-only).
370        fn dummy() -> Self {
371            Self {
372                merkle_root: "mkroot-123".to_string(),
373                epoch: Epoch(10),
374                block_number: BlockNumber(100),
375                hash: "hash-123".to_string(),
376                certificate_hash: "cert-hash-123".to_string(),
377                created_at: DateTime::parse_from_rfc3339("2023-01-19T13:43:05.618857482Z")
378                    .unwrap()
379                    .with_timezone(&Utc),
380            }
381        }
382    }
383
384    impl Dummy for CardanoTransactionSnapshotListItemMessage {
385        /// Return a dummy [CardanoTransactionSnapshotListItemMessage] (test-only).
386        fn dummy() -> Self {
387            Self {
388                merkle_root: "mkroot-123".to_string(),
389                epoch: Epoch(10),
390                block_number: BlockNumber(100),
391                hash: "hash-123".to_string(),
392                certificate_hash: "cert-hash-123".to_string(),
393                created_at: DateTime::parse_from_rfc3339("2023-01-19T13:43:05.618857482Z")
394                    .unwrap()
395                    .with_timezone(&Utc),
396            }
397        }
398    }
399
400    impl Dummy for CardanoBlocksTransactionsSnapshotMessage {
401        /// Return a dummy [CardanoBlocksTransactionsSnapshotMessage] (test-only).
402        fn dummy() -> Self {
403            Self {
404                merkle_root: "mkroot-123".to_string(),
405                epoch: Epoch(10),
406                block_number_signed: BlockNumber(100),
407                block_number_tip: BlockNumber(115),
408                hash: "hash-123".to_string(),
409                certificate_hash: "cert-hash-123".to_string(),
410                created_at: DateTime::parse_from_rfc3339("2023-01-19T13:43:05.618857482Z")
411                    .unwrap()
412                    .with_timezone(&Utc),
413            }
414        }
415    }
416
417    impl Dummy for CardanoBlocksTransactionsSnapshotListItemMessage {
418        /// Return a dummy [CardanoBlocksTransactionsSnapshotListItemMessage] (test-only).
419        fn dummy() -> Self {
420            Self {
421                merkle_root: "mkroot-123".to_string(),
422                epoch: Epoch(10),
423                block_number_signed: BlockNumber(100),
424                block_number_tip: BlockNumber(115),
425                hash: "hash-123".to_string(),
426                certificate_hash: "cert-hash-123".to_string(),
427                created_at: DateTime::parse_from_rfc3339("2023-01-19T13:43:05.618857482Z")
428                    .unwrap()
429                    .with_timezone(&Utc),
430            }
431        }
432    }
433
434    impl Dummy for CertificateMessage {
435        /// Return a dummy [CertificateMessage] (test-only).
436        fn dummy() -> Self {
437            let mut protocol_message = ProtocolMessage::new();
438            protocol_message.set_message_part(
439                ProtocolMessagePartKey::SnapshotDigest,
440                "snapshot-digest-123".to_string(),
441            );
442            protocol_message.set_message_part(
443                ProtocolMessagePartKey::NextAggregateVerificationKey,
444                fake_keys::aggregate_verification_key_for_concatenation()[1].to_owned(),
445            );
446            let epoch = Epoch(10);
447
448            Self {
449                hash: "hash".to_string(),
450                previous_hash: "previous_hash".to_string(),
451                epoch,
452                signed_entity_type: SignedEntityType::MithrilStakeDistribution(epoch),
453                metadata: CertificateMetadataMessagePart::dummy(),
454                protocol_message: protocol_message.clone(),
455                signed_message: "signed_message".to_string(),
456                aggregate_verification_key:
457                    fake_keys::aggregate_verification_key_for_concatenation()[0].to_owned(),
458                multi_signature: fake_keys::multi_signature()[0].to_owned(),
459                genesis_signature: String::new(),
460            }
461        }
462    }
463
464    impl Dummy for CertificateListItemMessage {
465        /// Return a dummy [CertificateListItemMessage] (test-only).
466        fn dummy() -> Self {
467            let mut protocol_message = ProtocolMessage::new();
468            protocol_message.set_message_part(
469                ProtocolMessagePartKey::SnapshotDigest,
470                "snapshot-digest-123".to_string(),
471            );
472            protocol_message.set_message_part(
473                ProtocolMessagePartKey::NextAggregateVerificationKey,
474                "next-avk-123".to_string(),
475            );
476            let epoch = Epoch(10);
477
478            Self {
479                hash: "hash".to_string(),
480                previous_hash: "previous_hash".to_string(),
481                epoch,
482                signed_entity_type: SignedEntityType::MithrilStakeDistribution(epoch),
483                metadata: CertificateListItemMessageMetadata {
484                    network: "testnet".to_string(),
485                    protocol_version: "0.1.0".to_string(),
486                    protocol_parameters: ProtocolParameters::new(1000, 100, 0.123),
487                    initiated_at: DateTime::parse_from_rfc3339("2024-02-12T13:11:47Z")
488                        .unwrap()
489                        .with_timezone(&Utc),
490                    sealed_at: DateTime::parse_from_rfc3339("2024-02-12T13:12:57Z")
491                        .unwrap()
492                        .with_timezone(&Utc),
493                    total_signers: 2,
494                },
495                protocol_message: protocol_message.clone(),
496                signed_message: "signed_message".to_string(),
497                aggregate_verification_key: "aggregate_verification_key".to_string(),
498            }
499        }
500    }
501
502    impl Dummy for EpochSettingsMessage {
503        /// Return a dummy [EpochSettingsMessage] (test-only).
504        fn dummy() -> Self {
505            #[allow(deprecated)]
506            Self {
507                epoch: Epoch(10),
508                signer_registration_protocol_parameters: Some(ProtocolParameters {
509                    k: 5,
510                    m: 100,
511                    phi_f: 0.65,
512                }),
513                current_signers: [SignerMessagePart::dummy()].to_vec(),
514                next_signers: [SignerMessagePart::dummy()].to_vec(),
515                cardano_transactions_signing_config: Some(CardanoTransactionsSigningConfig::dummy()),
516            }
517        }
518    }
519
520    impl Dummy for ProtocolConfigurationMessage {
521        /// Return a dummy [ProtocolConfigurationMessage] (test-only).
522        fn dummy() -> Self {
523            Self {
524                protocol_parameters: ProtocolParameters {
525                    k: 5,
526                    m: 100,
527                    phi_f: 0.65,
528                },
529                cardano_transactions_signing_config: Some(CardanoTransactionsSigningConfig::dummy()),
530                cardano_blocks_transactions_signing_config: Some(
531                    CardanoBlocksTransactionsSigningConfig::dummy(),
532                ),
533                available_signed_entity_types: SignedEntityTypeDiscriminants::all(),
534            }
535        }
536    }
537
538    impl Dummy for MithrilStakeDistributionMessage {
539        /// Return a dummy [MithrilStakeDistributionMessage] (test-only).
540        fn dummy() -> Self {
541            Self {
542                epoch: Epoch(1),
543                signers_with_stake: vec![SignerWithStakeMessagePart::dummy()],
544                hash: "hash-123".to_string(),
545                certificate_hash: "cert-hash-123".to_string(),
546                created_at: DateTime::parse_from_rfc3339("2023-01-19T13:43:05.618857482Z")
547                    .unwrap()
548                    .with_timezone(&Utc),
549                protocol_parameters: fake_data::protocol_parameters(),
550            }
551        }
552    }
553
554    impl Dummy for MithrilStakeDistributionListItemMessage {
555        /// Return a dummy [MithrilStakeDistributionListItemMessage] (test-only).
556        fn dummy() -> Self {
557            Self {
558                epoch: Epoch(1),
559                hash: "hash-123".to_string(),
560                certificate_hash: "certificate-hash-123".to_string(),
561                created_at: DateTime::parse_from_rfc3339("2023-01-19T13:43:05.618857482Z")
562                    .unwrap()
563                    .with_timezone(&Utc),
564            }
565        }
566    }
567
568    impl Dummy for RegisterSignatureMessageHttp {
569        /// Return a dummy [RegisterSignatureMessageHttp] (test-only).
570        fn dummy() -> Self {
571            use crate::entities::Epoch;
572            Self {
573                signed_entity_type: SignedEntityType::MithrilStakeDistribution(Epoch(5)),
574                party_id: "party_id".to_string(),
575                signature: fake_keys::single_signature()[0].to_string(),
576                won_indexes: vec![1, 3],
577                signed_message: "6a7e737c312972d2346b65ac3075696e04286d046dddaf8004121e3d5e27cc0d"
578                    .to_string(),
579            }
580        }
581    }
582
583    impl Dummy for RegisterSignatureMessageDmq {
584        /// Return a dummy [RegisterSignatureMessageDmq] (test-only).
585        fn dummy() -> Self {
586            use crate::entities::Epoch;
587            Self {
588                signed_entity_type: SignedEntityType::MithrilStakeDistribution(Epoch(5)),
589                signature: fake_keys::single_signature()[0].try_into().unwrap(),
590            }
591        }
592    }
593
594    impl Dummy for RegisterSignerMessage {
595        /// Return a dummy [RegisterSignerMessage] (test-only).
596        fn dummy() -> Self {
597            Self {
598                epoch: Epoch(1),
599                party_id: "pool1m8crhnqj5k2kyszf5j2scshupystyxc887zdfrpzh6ty6eun4fx".to_string(),
600                verification_key_for_concatenation: fake_keys::signer_verification_key()[0]
601                    .to_string(),
602                verification_key_signature_for_concatenation: Some(
603                    fake_keys::signer_verification_key_signature()[0].to_string(),
604                ),
605                operational_certificate: Some(fake_keys::operational_certificate()[0].to_string()),
606                kes_evolutions: Some(KesEvolutions(6)),
607                #[cfg(feature = "future_snark")]
608                verification_key_for_snark: None,
609                #[cfg(feature = "future_snark")]
610                verification_key_signature_for_snark: None,
611            }
612        }
613    }
614
615    impl Dummy for SnapshotMessage {
616        /// Return a dummy [SnapshotMessage] (test-only).
617        fn dummy() -> Self {
618            Self {
619                digest: "0b9f5ad7f33cc523775c82249294eb8a1541d54f08eb3107cafc5638403ec7c6"
620                    .to_string(),
621                network: "preview".to_string(),
622                beacon: CardanoDbBeacon {
623                    epoch: Epoch(86),
624                    immutable_file_number: 1728,
625                },
626                certificate_hash:
627                    "d5daf6c03ace4a9c074e951844075b9b373bafc4e039160e3e2af01823e9abfb".to_string(),
628                size: 807803196,
629                ancillary_size: Some(123456789),
630                created_at: DateTime::parse_from_rfc3339("2023-01-19T13:43:05.618857482Z")
631                    .unwrap()
632                    .with_timezone(&Utc),
633                locations: vec!["https://host/certificate.tar.gz".to_string()],
634                ancillary_locations: Some(vec!["https://host/ancillary.tar.gz".to_string()]),
635                compression_algorithm: CompressionAlgorithm::Gzip,
636                cardano_node_version: "0.0.1".to_string(),
637            }
638        }
639    }
640
641    impl Dummy for SnapshotDownloadMessage {
642        /// Return a dummy [SnapshotDownloadMessage] (test-only).
643        fn dummy() -> Self {
644            Self {
645                digest: "0b9f5ad7f33cc523775c82249294eb8a1541d54f08eb3107cafc5638403ec7c6"
646                    .to_string(),
647                network: "preview".to_string(),
648                beacon: CardanoDbBeacon {
649                    epoch: Epoch(86),
650                    immutable_file_number: 1728,
651                },
652                size: 807803196,
653                ancillary_size: Some(123456789),
654                locations: vec!["https://host/certificate.tar.gz".to_string()],
655                ancillary_locations: Some(vec!["https://host/ancillary.tar.gz".to_string()]),
656                compression_algorithm: CompressionAlgorithm::Gzip,
657                cardano_node_version: "0.0.1".to_string(),
658            }
659        }
660    }
661
662    impl Dummy for SnapshotListItemMessage {
663        /// Return a dummy [SnapshotListItemMessage] (test-only).
664        fn dummy() -> Self {
665            Self {
666                digest: "0b9f5ad7f33cc523775c82249294eb8a1541d54f08eb3107cafc5638403ec7c6"
667                    .to_string(),
668                network: "preview".to_string(),
669                beacon: CardanoDbBeacon {
670                    epoch: Epoch(86),
671                    immutable_file_number: 1728,
672                },
673                certificate_hash:
674                    "d5daf6c03ace4a9c074e951844075b9b373bafc4e039160e3e2af01823e9abfb".to_string(),
675                size: 807803196,
676                ancillary_size: Some(123456789),
677                created_at: DateTime::parse_from_rfc3339("2023-01-19T13:43:05.618857482Z")
678                    .unwrap()
679                    .with_timezone(&Utc),
680                locations: vec!["https://host/certificate.tar.gz".to_string()],
681                ancillary_locations: Some(vec!["https://host/ancillary.tar.gz".to_string()]),
682                compression_algorithm: CompressionAlgorithm::default(),
683                cardano_node_version: "0.0.1".to_string(),
684            }
685        }
686    }
687}
688
689mod signable_builder {
690    use crate::entities::{
691        CardanoBlocksTransactionsSnapshot, CardanoDbBeacon, CardanoStakeDistribution,
692        CardanoTransactionsSnapshot, Epoch, MithrilStakeDistribution, SignedEntityType, Snapshot,
693    };
694    use crate::signable_builder::SignedEntity;
695
696    use super::*;
697
698    impl Dummy for SignedEntity<Snapshot> {
699        /// Create a dummy [SignedEntity] for [Snapshot] entity
700        fn dummy() -> Self {
701            SignedEntity {
702                signed_entity_id: "snapshot-id-123".to_string(),
703                signed_entity_type: SignedEntityType::CardanoImmutableFilesFull(
704                    CardanoDbBeacon::default(),
705                ),
706                certificate_id: "certificate-hash-123".to_string(),
707                artifact: fake_data::snapshot(1),
708                created_at: DateTime::parse_from_rfc3339("2023-01-19T13:43:05.618857482Z")
709                    .unwrap()
710                    .with_timezone(&Utc),
711            }
712        }
713    }
714
715    impl Dummy for SignedEntity<MithrilStakeDistribution> {
716        /// Create a dummy [SignedEntity] for [MithrilStakeDistribution] entity
717        fn dummy() -> Self {
718            SignedEntity {
719                signed_entity_id: "mithril-stake-distribution-id-123".to_string(),
720                signed_entity_type: SignedEntityType::MithrilStakeDistribution(Epoch(1)),
721                certificate_id: "certificate-hash-123".to_string(),
722                artifact: fake_data::mithril_stake_distribution(
723                    Epoch(1),
724                    fake_data::signers_with_stakes(5),
725                ),
726                created_at: DateTime::parse_from_rfc3339("2023-01-19T13:43:05.618857482Z")
727                    .unwrap()
728                    .with_timezone(&Utc),
729            }
730        }
731    }
732
733    impl Dummy for SignedEntity<CardanoTransactionsSnapshot> {
734        /// Create a dummy [SignedEntity] for [CardanoTransactionsSnapshot] entity
735        fn dummy() -> Self {
736            let block_number = crate::entities::BlockNumber(50);
737            SignedEntity {
738                signed_entity_id: "snapshot-id-123".to_string(),
739                signed_entity_type: SignedEntityType::CardanoTransactions(Epoch(5), block_number),
740                certificate_id: "certificate-hash-123".to_string(),
741                artifact: CardanoTransactionsSnapshot::new("mkroot123".to_string(), block_number),
742                created_at: DateTime::parse_from_rfc3339("2023-01-19T13:43:05.618857482Z")
743                    .unwrap()
744                    .with_timezone(&Utc),
745            }
746        }
747    }
748
749    impl Dummy for SignedEntity<CardanoBlocksTransactionsSnapshot> {
750        /// Create a dummy [SignedEntity] for [CardanoBlocksTransactionsSnapshot] entity
751        fn dummy() -> Self {
752            let block_number = crate::entities::BlockNumber(50);
753            SignedEntity {
754                signed_entity_id: "snapshot-id-123".to_string(),
755                signed_entity_type: SignedEntityType::CardanoBlocksTransactions(
756                    Epoch(5),
757                    block_number,
758                ),
759                certificate_id: "certificate-hash-123".to_string(),
760                artifact: fake_data::cardano_blocks_transactions_snapshot(
761                    block_number,
762                    crate::entities::BlockNumber(15),
763                ),
764                created_at: DateTime::parse_from_rfc3339("2023-01-19T13:43:05.618857482Z")
765                    .unwrap()
766                    .with_timezone(&Utc),
767            }
768        }
769    }
770
771    impl Dummy for SignedEntity<CardanoStakeDistribution> {
772        /// Create a dummy [SignedEntity] for [CardanoStakeDistribution] entity
773        fn dummy() -> Self {
774            SignedEntity {
775                signed_entity_id: "cardano-stake-distribution-id-123".to_string(),
776                signed_entity_type: SignedEntityType::CardanoStakeDistribution(Epoch(1)),
777                certificate_id: "certificate-hash-123".to_string(),
778                artifact: fake_data::cardano_stake_distribution(Epoch(1)),
779                created_at: DateTime::parse_from_rfc3339("2024-07-29T16:15:05.618857482Z")
780                    .unwrap()
781                    .with_timezone(&Utc),
782            }
783        }
784    }
785}