Skip to content

Commit e536027

Browse files
dlachaumesfauvel
andcommitted
test: refactor integration test to simplify understanding
Co-authored-by: Sébastien Fauvel <[email protected]>
1 parent 663cd96 commit e536027

File tree

3 files changed

+51
-24
lines changed

3 files changed

+51
-24
lines changed

mithril-signer/tests/create_cardano_transaction_single_signature.rs

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -58,20 +58,20 @@ 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().await.unwrap()
61+
.cycle_ready_to_sign_no_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()
65-
.cycle_ready_to_sign().await.unwrap()
65+
.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().await.unwrap()
69-
.cycle_ready_to_sign().await.unwrap()
68+
.cycle_ready_to_sign_no_registration().await.unwrap()
69+
.cycle_ready_to_sign_no_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()
7373
.cardano_chain_send_rollback(SlotNumber(205), BlockNumber(230)).await.unwrap()
74-
.cycle_ready_to_sign().await.unwrap()
74+
.cycle_ready_to_sign_with_signature_registration().await.unwrap()
7575

7676
.comment("metrics should be correctly computed")
7777
.check_metrics(total_signer_registrations_expected,total_signature_registrations_expected).await.unwrap()

mithril-signer/tests/create_immutable_files_full_single_signature.rs

Lines changed: 10 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -81,38 +81,29 @@ async fn test_create_immutable_files_full_single_signature() {
8181
.cycle_unregistered().await.unwrap()
8282
.check_era_checker_last_updated_at(Epoch(4)).await.unwrap()
8383

84-
.comment("creating a new certificate pending with new signers and new beacon → ReadyToSign")
85-
.cycle_ready_to_sign().await.unwrap()
84+
.comment("signer can now create a single signature → ReadyToSign")
85+
.cycle_ready_to_sign_no_registration().await.unwrap()
8686
.check_protocol_initializer(Epoch(4)).await.unwrap()
8787

88-
.comment("signer can now create a single signature → ReadyToSign")
89-
.cycle_ready_to_sign().await.unwrap()
9088
.comment("signer signs a single signature = ReadyToSign")
91-
.cycle_ready_to_sign().await.unwrap()
92-
// TODO?
93-
// .expect_new_signature()
89+
.cycle_ready_to_sign_with_signature_registration().await.unwrap()
9490

95-
// Should we remove this case?
96-
//.comment("more cycles do not change the state = ReadyToSign")
97-
//.cycle_ready_to_sign().await.unwrap()
98-
// .cycle_ready_to_sign().await.unwrap()
91+
.comment("more cycles do not change the state = ReadyToSign")
92+
.cycle_ready_to_sign_no_registration().await.unwrap()
9993

10094
.comment("new immutable means a new signature with the same stake distribution → ReadyToSign")
10195
.increase_immutable(1, 9).await.unwrap()
102-
.cycle_ready_to_sign().await.unwrap()
103-
// TODO?
104-
// .expect_new_signature()
96+
.cycle_ready_to_sign_with_signature_registration().await.unwrap()
10597

10698
.comment("changing epoch changes the state → Unregistered")
10799
.increase_epoch(5).await.unwrap()
108100
.cycle_unregistered().await.unwrap()
109101
.check_era_checker_last_updated_at(Epoch(5)).await.unwrap()
110102
.comment("signer should be able to create a single signature → ReadyToSign")
111-
.cycle_ready_to_sign().await.unwrap()
112-
.cycle_ready_to_sign().await.unwrap()
113-
// TODO?
114-
// .expect_new_signature()
115-
//.check_total_signature_registrations_metrics(3).await.unwrap()
103+
104+
.check_total_signature_registrations_metrics(2).unwrap()
105+
.cycle_ready_to_sign_no_registration().await.unwrap()
106+
.cycle_ready_to_sign_with_signature_registration().await.unwrap()
116107
.check_protocol_initializer(Epoch(5)).await.unwrap()
117108

118109
.comment("metrics should be correctly computed")

mithril-signer/tests/test_extensions/state_machine_tester.rs

Lines changed: 36 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -334,6 +334,28 @@ impl StateMachineTester {
334334
)
335335
}
336336

337+
pub async fn cycle_ready_to_sign_no_registration(&mut self) -> Result<&mut Self> {
338+
let metric_before = self
339+
.metrics_service
340+
.signature_registration_success_since_startup_counter_get();
341+
342+
self.cycle_ready_to_sign().await?;
343+
344+
let expected_metric = metric_before;
345+
self.check_total_signature_registrations_metrics(expected_metric)
346+
}
347+
348+
pub async fn cycle_ready_to_sign_with_signature_registration(&mut self) -> Result<&mut Self> {
349+
let metric_before = self
350+
.metrics_service
351+
.signature_registration_success_since_startup_counter_get();
352+
353+
self.cycle_ready_to_sign().await?;
354+
355+
let expected_metric = metric_before + 1;
356+
self.check_total_signature_registrations_metrics(expected_metric)
357+
}
358+
337359
/// cycle the state machine and test the resulting state
338360
pub async fn cycle_registered_not_able_to_sign(&mut self) -> Result<&mut Self> {
339361
self.cycle().await?;
@@ -623,6 +645,20 @@ impl StateMachineTester {
623645
.collect::<BTreeMap<_, _>>())
624646
}
625647

648+
pub fn check_total_signature_registrations_metrics(
649+
&mut self,
650+
expected_metric: u32,
651+
) -> Result<&mut Self> {
652+
let metric = self
653+
.metrics_service
654+
.signature_registration_success_since_startup_counter_get();
655+
656+
self.assert(
657+
expected_metric == metric,
658+
format!("Total signature registrations metric: given {metric:?}, expected {expected_metric:?}"),
659+
)
660+
}
661+
626662
// Check that the metrics service exports the expected metrics
627663
pub async fn check_metrics(
628664
&mut self,

0 commit comments

Comments
 (0)