From 867286f962b1b0a668015b16d8c0699e202f3e0f Mon Sep 17 00:00:00 2001 From: Jean-Philippe Raynaud Date: Mon, 24 Apr 2023 17:50:18 +0200 Subject: [PATCH] Fix unit & integration tests --- mithril-aggregator/src/dependency.rs | 14 ++++-- mithril-aggregator/src/runtime/runner.rs | 2 +- mithril-aggregator/tests/certificate_chain.rs | 32 ++++++++++-- .../tests/create_certificate.rs | 3 +- .../tests/test_extensions/runtime_tester.rs | 50 ++++++++++++++++--- .../src/entities/certificate_pending.rs | 1 + 6 files changed, 84 insertions(+), 18 deletions(-) diff --git a/mithril-aggregator/src/dependency.rs b/mithril-aggregator/src/dependency.rs index 91856c46d29..f7394e53996 100644 --- a/mithril-aggregator/src/dependency.rs +++ b/mithril-aggregator/src/dependency.rs @@ -194,12 +194,12 @@ impl DependencyManager { } for (epoch, params) in parameters_per_epoch { - self.fill_verification_key_store(epoch, ¶ms.0).await; - self.fill_stakes_store(epoch, params.0.to_vec()).await; self.protocol_parameters_store .save_protocol_parameters(epoch, params.1) .await .expect("save_protocol_parameters should not fail"); + self.fill_verification_key_store(epoch, ¶ms.0).await; + self.fill_stakes_store(epoch, params.0.to_vec()).await; } for certificate in certificate_chain { @@ -237,6 +237,9 @@ impl DependencyManager { second_epoch_signers: Vec, genesis_protocol_parameters: &ProtocolParameters, ) { + self.init_protocol_parameter_store(genesis_protocol_parameters) + .await; + let (work_epoch, epoch_to_sign) = self.get_genesis_epochs().await; for (epoch, signers) in [ (work_epoch, genesis_signers), @@ -245,9 +248,6 @@ impl DependencyManager { self.fill_verification_key_store(epoch, &signers).await; self.fill_stakes_store(epoch, signers).await; } - - self.init_protocol_parameter_store(genesis_protocol_parameters) - .await; } /// `TEST METHOD ONLY` @@ -269,6 +269,10 @@ impl DependencyManager { async fn fill_verification_key_store(&self, target_epoch: Epoch, signers: &[SignerWithStake]) { for signer in signers { + self.signer_recorder + .record_signer_id(signer.party_id.clone()) + .await + .expect("record_signer_id should not fail"); self.verification_key_store .save_verification_key(target_epoch, signer.clone()) .await diff --git a/mithril-aggregator/src/runtime/runner.rs b/mithril-aggregator/src/runtime/runner.rs index 7ce0858dc31..e91beb8d5fd 100644 --- a/mithril-aggregator/src/runtime/runner.rs +++ b/mithril-aggregator/src/runtime/runner.rs @@ -774,7 +774,7 @@ pub mod tests { let runner = AggregatorRunner::new(config, Arc::new(dependencies)); let beacon = fake_data::beacon(); - let mut certificate = fake_data::certificate("certificate_hash".to_string()); + let mut certificate = fake_data::genesis_certificate("certificate_hash".to_string()); certificate.beacon = beacon.clone(); assert!(!runner diff --git a/mithril-aggregator/tests/certificate_chain.rs b/mithril-aggregator/tests/certificate_chain.rs index e8b62e2d9cd..4245e739615 100644 --- a/mithril-aggregator/tests/certificate_chain.rs +++ b/mithril-aggregator/tests/certificate_chain.rs @@ -60,7 +60,11 @@ async fn certificate_chain() { cycle!(tester, "signing"); tester.register_signers(&signers).await.unwrap(); cycle_err!(tester, "signing"); - tester.send_single_signatures(&signers).await.unwrap(); + let signed_entity_type = tester.retrieve_signed_entity_type().await; + tester + .send_single_signatures(&signed_entity_type, &signers) + .await + .unwrap(); comment!("The state machine should have issued a multisignature"); cycle!(tester, "idle"); @@ -76,7 +80,11 @@ async fn certificate_chain() { tester.increase_immutable_number().await.unwrap(); cycle!(tester, "ready"); cycle!(tester, "signing"); - tester.send_single_signatures(&signers).await.unwrap(); + let signed_entity_type = tester.retrieve_signed_entity_type().await; + tester + .send_single_signatures(&signed_entity_type, &signers) + .await + .unwrap(); cycle!(tester, "idle"); let (last_certificates, snapshots) = tester.get_last_certificates_and_snapshots().await.unwrap(); @@ -135,7 +143,11 @@ async fn certificate_chain() { "Signers register & send signatures, the new certificate should be link to the first of the previous epoch" ); tester.register_signers(&new_signers).await.unwrap(); - tester.send_single_signatures(&signers).await.unwrap(); + let signed_entity_type = tester.retrieve_signed_entity_type().await; + tester + .send_single_signatures(&signed_entity_type, &signers) + .await + .unwrap(); cycle!(tester, "idle"); let (last_certificates, snapshots) = tester.get_last_certificates_and_snapshots().await.unwrap(); @@ -170,7 +182,12 @@ async fn certificate_chain() { tester.increase_immutable_number().await.unwrap(); cycle!(tester, "ready"); cycle!(tester, "signing"); - tester.send_single_signatures(&signers).await.unwrap(); + + let signed_entity_type = tester.retrieve_signed_entity_type().await; + tester + .send_single_signatures(&signed_entity_type, &signers) + .await + .unwrap(); cycle!(tester, "idle"); comment!( @@ -182,7 +199,12 @@ async fn certificate_chain() { tester.increase_immutable_number().await.unwrap(); cycle!(tester, "ready"); cycle!(tester, "signing"); - tester.send_single_signatures(&new_signers).await.unwrap(); + let signed_entity_type = tester.retrieve_signed_entity_type().await; + + tester + .send_single_signatures(&signed_entity_type, &new_signers) + .await + .unwrap(); cycle!(tester, "idle"); let (last_certificates, snapshots) = diff --git a/mithril-aggregator/tests/create_certificate.rs b/mithril-aggregator/tests/create_certificate.rs index 609817804c7..c048c33e600 100644 --- a/mithril-aggregator/tests/create_certificate.rs +++ b/mithril-aggregator/tests/create_certificate.rs @@ -67,9 +67,10 @@ async fn create_certificate() { cycle!(tester, "signing"); comment!("signers send their single signature"); + let signed_entity_type = tester.retrieve_signed_entity_type().await; let signers_who_sign = &signers[0..=6]; tester - .send_single_signatures(signers_who_sign) + .send_single_signatures(&signed_entity_type, signers_who_sign) .await .unwrap(); diff --git a/mithril-aggregator/tests/test_extensions/runtime_tester.rs b/mithril-aggregator/tests/test_extensions/runtime_tester.rs index be63a9b4d27..073bd094614 100644 --- a/mithril-aggregator/tests/test_extensions/runtime_tester.rs +++ b/mithril-aggregator/tests/test_extensions/runtime_tester.rs @@ -17,8 +17,8 @@ use mithril_aggregator::{ use mithril_common::crypto_helper::{key_encode_hex, ProtocolClerk, ProtocolGenesisSigner}; use mithril_common::digesters::DumbImmutableFileObserver; use mithril_common::entities::{ - Certificate, Epoch, ImmutableFileNumber, SignerWithStake, SingleSignatures, Snapshot, - StakeDistribution, + Certificate, Epoch, ImmutableFileNumber, SignedEntityType, SignerWithStake, SingleSignatures, + Snapshot, StakeDistribution, }; use mithril_common::{chain_observer::FakeObserver, digesters::DumbImmutableDigester}; @@ -148,6 +148,13 @@ impl RuntimeTester { .get_current_beacon() .await .map_err(|e| format!("Querying the current beacon should not fail: {e:?}"))?; + self.deps_builder + .get_certifier_service() + .await + .unwrap() + .inform_epoch(beacon.epoch) + .await + .expect("inform_epoch should not fail"); let protocol_parameters = self .deps_builder .get_protocol_parameters_store() @@ -221,6 +228,13 @@ impl RuntimeTester { .await .ok_or("a new epoch should have been issued")?; self.update_digester_digest().await?; + self.deps_builder + .get_certifier_service() + .await + .unwrap() + .inform_epoch(new_epoch) + .await + .expect("inform_epoch should not fail"); Ok(new_epoch) } @@ -243,8 +257,10 @@ impl RuntimeTester { /// "Send", actually register, the given single signatures in the multi-signers pub async fn send_single_signatures( &mut self, + signed_entity_type: &SignedEntityType, signers: &[SignerFixture], ) -> Result<(), String> { + let certifier_service = self.deps_builder.get_certifier_service().await.unwrap(); let lock = self.deps_builder.get_multi_signer().await.unwrap(); let multisigner = lock.read().await; let message = multisigner @@ -263,8 +279,8 @@ impl RuntimeTester { signature.indexes, ); - multisigner - .register_single_signature(&message, &single_signatures) + certifier_service + .register_single_signature(signed_entity_type, &single_signatures) .await .map_err(|e| { format!("registering a winning lottery signature should not fail: {e:?}") @@ -349,7 +365,7 @@ impl RuntimeTester { Ok(fixture.signers_fixture()) } - // Update the digester result using the current beacon + /// Update the digester result using the current beacon pub async fn update_digester_digest(&mut self) -> Result<(), String> { let beacon = self .deps_builder @@ -370,8 +386,30 @@ impl RuntimeTester { Ok(()) } - // update the Era markers + /// Update the Era markers pub async fn set_era_markers(&self, markers: Vec) { self.era_reader_adapter.set_markers(markers) } + + /// Retrieve signed entity type + pub async fn retrieve_signed_entity_type(&mut self) -> SignedEntityType { + let signer_entity_type_default = SignedEntityType::CardanoImmutableFilesFull( + self.deps_builder + .get_beacon_provider() + .await + .unwrap() + .get_current_beacon() + .await + .unwrap(), + ); + self.deps_builder + .get_certifier_service() + .await + .unwrap() + .get_open_message(&signer_entity_type_default) + .await + .unwrap() + .map(|om| om.signed_entity_type) + .unwrap() + } } diff --git a/mithril-common/src/entities/certificate_pending.rs b/mithril-common/src/entities/certificate_pending.rs index 9013df6dca0..d779476700d 100644 --- a/mithril-common/src/entities/certificate_pending.rs +++ b/mithril-common/src/entities/certificate_pending.rs @@ -10,6 +10,7 @@ pub struct CertificatePending { pub beacon: Beacon, /// Signed entity type + #[serde(rename = "entity_type")] pub signed_entity_type: SignedEntityType, /// Current Protocol parameters