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 21, 2023
1 parent 9c5c9eb commit 9b0358a
Show file tree
Hide file tree
Showing 4 changed files with 28 additions and 12 deletions.
4 changes: 2 additions & 2 deletions mithril-aggregator/src/database/provider/open_message.rs
Original file line number Diff line number Diff line change
Expand Up @@ -439,7 +439,7 @@ impl SqLiteEntity for OpenMessageWithSingleSignatures {
("protocol_message", "{:open_message:}.protocol_message", "text"),
("is_certified", "{:open_message:}.is_certified", "bool"),
("created_at", "{:open_message:}.created_at", "text"),
("single_signatures", "json_group_array(json_object('signer_id', {:single_signature:}.signer_id, 'signature', {:single_signature:}.signature, 'won_indexes', {:single_signature:}.lottery_indexes))", "text")
("single_signatures", "case when {:single_signature:}.signer_id is null then '[]' else json_group_array(json_object('signer_id', {:single_signature:}.signer_id, 'signature', {:single_signature:}.signature, 'won_indexes', {:single_signature:}.lottery_indexes)) end", "text")
])
}
}
Expand Down Expand Up @@ -509,7 +509,7 @@ mod tests {
]);

assert_eq!(
"open_message.open_message_id as open_message_id, open_message.epoch_setting_id as epoch_setting_id, open_message.beacon as beacon, open_message.signed_entity_type_id as signed_entity_type_id, open_message.protocol_message as protocol_message, open_message.is_certified as is_certified, open_message.created_at as created_at, json_group_array(json_object('signer_id', single_signature.signer_id, 'signature', single_signature.signature, 'won_indexes', single_signature.lottery_indexes)) as single_signatures".to_string(),
"open_message.open_message_id as open_message_id, open_message.epoch_setting_id as epoch_setting_id, open_message.beacon as beacon, open_message.signed_entity_type_id as signed_entity_type_id, open_message.protocol_message as protocol_message, open_message.is_certified as is_certified, open_message.created_at as created_at, case when single_signature.signer_id is null then '[]' else json_group_array(json_object('signer_id', single_signature.signer_id, 'signature', single_signature.signature, 'won_indexes', single_signature.lottery_indexes)) end as single_signatures".to_string(),
projection.expand(aliases)
)
}
Expand Down
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
8 changes: 3 additions & 5 deletions mithril-aggregator/src/runtime/runner.rs
Original file line number Diff line number Diff line change
Expand Up @@ -713,12 +713,10 @@ pub mod tests {
};
use crate::{MithrilSignerRegisterer, ProtocolParametersStorer, SignerRegistrationRound};
use mithril_common::chain_observer::FakeObserver;
use mithril_common::crypto_helper::{
tests_setup::setup_certificate_chain, };
use mithril_common::crypto_helper::tests_setup::setup_certificate_chain;
use mithril_common::digesters::DumbImmutableFileObserver;
use mithril_common::entities::{
Beacon, CertificatePending, ProtocolMessage, SignedEntityType,
StakeDistribution,
Beacon, CertificatePending, ProtocolMessage, SignedEntityType, StakeDistribution,
};
use mithril_common::store::StakeStorer;
use mithril_common::test_utils::MithrilFixtureBuilder;
Expand Down Expand Up @@ -757,7 +755,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
14 changes: 14 additions & 0 deletions mithril-aggregator/tests/test_extensions/runtime_tester.rs
Original file line number Diff line number Diff line change
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 Down

0 comments on commit 9b0358a

Please sign in to comment.