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