diff --git a/mithril-signer/src/runtime/runner.rs b/mithril-signer/src/runtime/runner.rs index ded6acfcab..ed6d540ba7 100644 --- a/mithril-signer/src/runtime/runner.rs +++ b/mithril-signer/src/runtime/runner.rs @@ -2,9 +2,7 @@ use anyhow::Context; use async_trait::async_trait; use slog_scope::{debug, info, warn}; use thiserror::Error; - -#[cfg(test)] -use mockall::automock; +use tokio::sync::RwLockReadGuard; use mithril_common::crypto_helper::{KESPeriod, OpCert, ProtocolOpCert, SerDeShelleyFileFormat}; use mithril_common::entities::{ @@ -13,7 +11,6 @@ use mithril_common::entities::{ }; use mithril_common::StdResult; use mithril_persistence::store::StakeStorer; -use tokio::sync::RwLockReadGuard; use crate::dependency_injection::SignerDependencyContainer; use crate::services::{EpochService, MithrilProtocolInitializerBuilder}; @@ -121,7 +118,7 @@ impl SignerRunner { } } -#[cfg_attr(test, automock)] +#[cfg_attr(test, mockall::automock)] #[async_trait] impl Runner for SignerRunner { async fn get_epoch_settings(&self) -> StdResult> { diff --git a/mithril-signer/src/runtime/state_machine.rs b/mithril-signer/src/runtime/state_machine.rs index 0477ff2ede..057254d0a0 100644 --- a/mithril-signer/src/runtime/state_machine.rs +++ b/mithril-signer/src/runtime/state_machine.rs @@ -25,7 +25,7 @@ pub enum SignerState { /// `ReadyToSign` state. The signer is registered and ready to sign new messages. ReadyToSign { - /// Epoch when signer transited to the state. + /// Epoch when signer transitioned to the state. epoch: Epoch, /// Last signed entity type that the signer signed on this epoch. last_signed_entity_type: Option, @@ -33,7 +33,7 @@ pub enum SignerState { /// `RegisteredNotAbleToSign` state. The signer is registered but not able to sign for the duration of the epoch. RegisteredNotAbleToSign { - /// Epoch when signer transited to the state. + /// Epoch when signer transitioned to the state. epoch: Epoch, }, } @@ -46,23 +46,17 @@ impl SignerState { /// Returns `true` if the state in `Unregistered` pub fn is_unregistered(&self) -> bool { - matches!(*self, SignerState::Unregistered { epoch: _ }) + matches!(*self, SignerState::Unregistered { .. }) } /// Returns `true` if the state in `ReadyToSign` pub fn is_ready_to_sign(&self) -> bool { - matches!( - *self, - SignerState::ReadyToSign { - epoch: _, - last_signed_entity_type: _ - } - ) + matches!(*self, SignerState::ReadyToSign { .. }) } /// Returns `true` if the state in `RegisteredNotAbleToSign` pub fn is_registered_not_able_to_sign(&self) -> bool { - matches!(*self, SignerState::RegisteredNotAbleToSign { epoch: _ }) + matches!(*self, SignerState::RegisteredNotAbleToSign { .. }) } } @@ -678,12 +672,13 @@ mod tests { .await .expect("Cycling the state machine should not fail"); - if !state_machine.get_state().await.is_ready_to_sign() { - panic!( - "state machine did not return a ReadyToSign state but {:?}", - state_machine.get_state().await - ); - } + assert_eq!( + SignerState::ReadyToSign { + epoch: TimePoint::dummy().epoch, + last_signed_entity_type: None + }, + state_machine.get_state().await + ); } #[tokio::test] @@ -815,7 +810,7 @@ mod tests { } #[tokio::test] - async fn ready_to_sign_to_ready_to_sign_when_same_state_than_previous_one() { + async fn ready_to_sign_to_ready_to_sign_when_same_signed_entity_type() { let time_point = TimePoint::dummy(); let certificate_pending = CertificatePending { epoch: time_point.clone().epoch, diff --git a/mithril-signer/tests/create_cardano_transaction_single_signature.rs b/mithril-signer/tests/create_cardano_transaction_single_signature.rs index 93a3d6c07e..7b4e665cd0 100644 --- a/mithril-signer/tests/create_cardano_transaction_single_signature.rs +++ b/mithril-signer/tests/create_cardano_transaction_single_signature.rs @@ -58,15 +58,15 @@ async fn test_create_cardano_transaction_single_signature() { .cycle_unregistered().await.unwrap() .comment("signer can now create a single signature → ReadyToSign") - .cycle_ready_to_sign_no_registration().await.unwrap() + .cycle_ready_to_sign_without_signature_registration().await.unwrap() .comment("creating a new certificate pending with a cardano transaction signed entity → ReadyToSign") .increase_block_number_and_slot_number(70, SlotNumber(80), BlockNumber(170)).await.unwrap() .cycle_ready_to_sign_with_signature_registration().await.unwrap() .comment("more cycles do not change the state = ReadyToSign") - .cycle_ready_to_sign_no_registration().await.unwrap() - .cycle_ready_to_sign_no_registration().await.unwrap() + .cycle_ready_to_sign_without_signature_registration().await.unwrap() + .cycle_ready_to_sign_without_signature_registration().await.unwrap() .comment("new blocks means a new signature with the same stake distribution → ReadyToSign") .increase_block_number_and_slot_number(125, SlotNumber(205), BlockNumber(295)).await.unwrap() diff --git a/mithril-signer/tests/test_extensions/state_machine_tester.rs b/mithril-signer/tests/test_extensions/state_machine_tester.rs index 484188f2bd..38ad9d8866 100644 --- a/mithril-signer/tests/test_extensions/state_machine_tester.rs +++ b/mithril-signer/tests/test_extensions/state_machine_tester.rs @@ -321,7 +321,9 @@ impl StateMachineTester { ) } - pub async fn cycle_ready_to_sign_no_registration(&mut self) -> Result<&mut Self> { + pub async fn cycle_ready_to_sign_without_signature_registration( + &mut self, + ) -> Result<&mut Self> { let metric_before = self .metrics_service .signature_registration_success_since_startup_counter_get();