Skip to content

Commit

Permalink
Fix unit & integration tests
Browse files Browse the repository at this point in the history
  • Loading branch information
jpraynaud committed Apr 24, 2023
1 parent c330482 commit 0bb936f
Show file tree
Hide file tree
Showing 6 changed files with 75 additions and 18 deletions.
14 changes: 9 additions & 5 deletions mithril-aggregator/src/dependency.rs
Original file line number Diff line number Diff line change
Expand Up @@ -194,12 +194,12 @@ impl DependencyManager {
}

for (epoch, params) in parameters_per_epoch {
self.fill_verification_key_store(epoch, &params.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, &params.0).await;
self.fill_stakes_store(epoch, params.0.to_vec()).await;
}

for certificate in certificate_chain {
Expand Down Expand Up @@ -237,6 +237,9 @@ impl DependencyManager {
second_epoch_signers: Vec<SignerWithStake>,
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),
Expand All @@ -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`
Expand All @@ -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
Expand Down
2 changes: 1 addition & 1 deletion mithril-aggregator/src/runtime/runner.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
32 changes: 27 additions & 5 deletions mithril-aggregator/tests/certificate_chain.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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.create_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");
Expand All @@ -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.create_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();
Expand Down Expand Up @@ -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.create_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();
Expand Down Expand Up @@ -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.create_signed_entity_type().await;
tester
.send_single_signatures(&signed_entity_type, &signers)
.await
.unwrap();
cycle!(tester, "idle");

comment!(
Expand All @@ -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.create_signed_entity_type().await;

tester
.send_single_signatures(&signed_entity_type, &new_signers)
.await
.unwrap();
cycle!(tester, "idle");

let (last_certificates, snapshots) =
Expand Down
3 changes: 2 additions & 1 deletion mithril-aggregator/tests/create_certificate.rs
Original file line number Diff line number Diff line change
Expand Up @@ -67,9 +67,10 @@ async fn create_certificate() {
cycle!(tester, "signing");

comment!("signers send their single signature");
let signed_entity_type = tester.create_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();

Expand Down
41 changes: 35 additions & 6 deletions mithril-aggregator/tests/test_extensions/runtime_tester.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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};

Expand Down Expand Up @@ -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()
Expand Down Expand Up @@ -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)
}
Expand All @@ -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
Expand All @@ -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:?}")
Expand Down Expand Up @@ -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
Expand All @@ -370,8 +386,21 @@ impl RuntimeTester {
Ok(())
}

// update the Era markers
/// Update the Era markers
pub async fn set_era_markers(&self, markers: Vec<EraMarker>) {
self.era_reader_adapter.set_markers(markers)
}

/// Create signed entity type
pub async fn create_signed_entity_type(&mut self) -> SignedEntityType {
self.deps_builder
.get_certifier_service()
.await
.unwrap()
.get_open_message(&SignedEntityType::dummy())
.await
.unwrap()
.map(|om| om.signed_entity_type)
.unwrap()
}
}
1 change: 1 addition & 0 deletions mithril-common/src/entities/certificate_pending.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down

0 comments on commit 0bb936f

Please sign in to comment.