Skip to content

Commit c7ce4e3

Browse files
committed
refacto: function renaming and clean imports
1 parent e7ee8a8 commit c7ce4e3

File tree

4 files changed

+21
-27
lines changed

4 files changed

+21
-27
lines changed

mithril-signer/src/runtime/runner.rs

Lines changed: 2 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -2,9 +2,7 @@ use anyhow::Context;
22
use async_trait::async_trait;
33
use slog_scope::{debug, info, warn};
44
use thiserror::Error;
5-
6-
#[cfg(test)]
7-
use mockall::automock;
5+
use tokio::sync::RwLockReadGuard;
86

97
use mithril_common::crypto_helper::{KESPeriod, OpCert, ProtocolOpCert, SerDeShelleyFileFormat};
108
use mithril_common::entities::{
@@ -13,7 +11,6 @@ use mithril_common::entities::{
1311
};
1412
use mithril_common::StdResult;
1513
use mithril_persistence::store::StakeStorer;
16-
use tokio::sync::RwLockReadGuard;
1714

1815
use crate::dependency_injection::SignerDependencyContainer;
1916
use crate::services::{EpochService, MithrilProtocolInitializerBuilder};
@@ -121,7 +118,7 @@ impl SignerRunner {
121118
}
122119
}
123120

124-
#[cfg_attr(test, automock)]
121+
#[cfg_attr(test, mockall::automock)]
125122
#[async_trait]
126123
impl Runner for SignerRunner {
127124
async fn get_epoch_settings(&self) -> StdResult<Option<EpochSettings>> {

mithril-signer/src/runtime/state_machine.rs

Lines changed: 13 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -25,15 +25,15 @@ pub enum SignerState {
2525

2626
/// `ReadyToSign` state. The signer is registered and ready to sign new messages.
2727
ReadyToSign {
28-
/// Epoch when signer transited to the state.
28+
/// Epoch when signer transitioned to the state.
2929
epoch: Epoch,
3030
/// Last signed entity type that the signer signed on this epoch.
3131
last_signed_entity_type: Option<SignedEntityType>,
3232
},
3333

3434
/// `RegisteredNotAbleToSign` state. The signer is registered but not able to sign for the duration of the epoch.
3535
RegisteredNotAbleToSign {
36-
/// Epoch when signer transited to the state.
36+
/// Epoch when signer transitioned to the state.
3737
epoch: Epoch,
3838
},
3939
}
@@ -46,23 +46,17 @@ impl SignerState {
4646

4747
/// Returns `true` if the state in `Unregistered`
4848
pub fn is_unregistered(&self) -> bool {
49-
matches!(*self, SignerState::Unregistered { epoch: _ })
49+
matches!(*self, SignerState::Unregistered { .. })
5050
}
5151

5252
/// Returns `true` if the state in `ReadyToSign`
5353
pub fn is_ready_to_sign(&self) -> bool {
54-
matches!(
55-
*self,
56-
SignerState::ReadyToSign {
57-
epoch: _,
58-
last_signed_entity_type: _
59-
}
60-
)
54+
matches!(*self, SignerState::ReadyToSign { .. })
6155
}
6256

6357
/// Returns `true` if the state in `RegisteredNotAbleToSign`
6458
pub fn is_registered_not_able_to_sign(&self) -> bool {
65-
matches!(*self, SignerState::RegisteredNotAbleToSign { epoch: _ })
59+
matches!(*self, SignerState::RegisteredNotAbleToSign { .. })
6660
}
6761
}
6862

@@ -678,12 +672,13 @@ mod tests {
678672
.await
679673
.expect("Cycling the state machine should not fail");
680674

681-
if !state_machine.get_state().await.is_ready_to_sign() {
682-
panic!(
683-
"state machine did not return a ReadyToSign state but {:?}",
684-
state_machine.get_state().await
685-
);
686-
}
675+
assert_eq!(
676+
SignerState::ReadyToSign {
677+
epoch: TimePoint::dummy().epoch,
678+
last_signed_entity_type: None
679+
},
680+
state_machine.get_state().await
681+
);
687682
}
688683

689684
#[tokio::test]
@@ -815,7 +810,7 @@ mod tests {
815810
}
816811

817812
#[tokio::test]
818-
async fn ready_to_sign_to_ready_to_sign_when_same_state_than_previous_one() {
813+
async fn ready_to_sign_to_ready_to_sign_when_same_signed_entity_type() {
819814
let time_point = TimePoint::dummy();
820815
let certificate_pending = CertificatePending {
821816
epoch: time_point.clone().epoch,

mithril-signer/tests/create_cardano_transaction_single_signature.rs

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -58,15 +58,15 @@ async fn test_create_cardano_transaction_single_signature() {
5858
.cycle_unregistered().await.unwrap()
5959

6060
.comment("signer can now create a single signature → ReadyToSign")
61-
.cycle_ready_to_sign_no_registration().await.unwrap()
61+
.cycle_ready_to_sign_without_signature_registration().await.unwrap()
6262

6363
.comment("creating a new certificate pending with a cardano transaction signed entity → ReadyToSign")
6464
.increase_block_number_and_slot_number(70, SlotNumber(80), BlockNumber(170)).await.unwrap()
6565
.cycle_ready_to_sign_with_signature_registration().await.unwrap()
6666

6767
.comment("more cycles do not change the state = ReadyToSign")
68-
.cycle_ready_to_sign_no_registration().await.unwrap()
69-
.cycle_ready_to_sign_no_registration().await.unwrap()
68+
.cycle_ready_to_sign_without_signature_registration().await.unwrap()
69+
.cycle_ready_to_sign_without_signature_registration().await.unwrap()
7070

7171
.comment("new blocks means a new signature with the same stake distribution → ReadyToSign")
7272
.increase_block_number_and_slot_number(125, SlotNumber(205), BlockNumber(295)).await.unwrap()

mithril-signer/tests/test_extensions/state_machine_tester.rs

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -321,7 +321,9 @@ impl StateMachineTester {
321321
)
322322
}
323323

324-
pub async fn cycle_ready_to_sign_no_registration(&mut self) -> Result<&mut Self> {
324+
pub async fn cycle_ready_to_sign_without_signature_registration(
325+
&mut self,
326+
) -> Result<&mut Self> {
325327
let metric_before = self
326328
.metrics_service
327329
.signature_registration_success_since_startup_counter_get();

0 commit comments

Comments
 (0)