Skip to content

Commit 2081055

Browse files
committed
WIP: switch immutableFilesFull to cardanoDatabase and update mock
1 parent 913cf76 commit 2081055

File tree

8 files changed

+114
-94
lines changed

8 files changed

+114
-94
lines changed

mithril-aggregator/src/runtime/runner.rs

Lines changed: 68 additions & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -520,8 +520,8 @@ impl AggregatorRunnerTrait for AggregatorRunner {
520520
pub mod tests {
521521
use async_trait::async_trait;
522522
use chrono::{DateTime, Utc};
523+
use mockall::mock;
523524
use mockall::predicate::eq;
524-
use mockall::{mock, Sequence};
525525
use std::path::PathBuf;
526526
use std::sync::Arc;
527527
use tokio::sync::RwLock;
@@ -665,9 +665,13 @@ pub mod tests {
665665
.returning(|_| Ok(None));
666666
}
667667

668-
fn create_open_message(is_certified: IsCertified, is_expired: IsExpired) -> OpenMessage {
668+
fn create_open_message(
669+
is_certified: IsCertified,
670+
is_expired: IsExpired,
671+
signed_entity_type: SignedEntityType,
672+
) -> OpenMessage {
669673
OpenMessage {
670-
signed_entity_type: SignedEntityType::CardanoImmutableFilesFull(fake_data::beacon()),
674+
signed_entity_type,
671675
is_certified: is_certified == IsCertified::Yes,
672676
is_expired: is_expired == IsExpired::Yes,
673677
..OpenMessage::dummy()
@@ -973,7 +977,11 @@ pub mod tests {
973977
#[tokio::test]
974978
async fn test_get_current_non_certified_open_message_should_create_new_open_message_if_none_exists(
975979
) {
976-
let open_message_created = create_open_message(IsCertified::No, IsExpired::No);
980+
let open_message_created = create_open_message(
981+
IsCertified::No,
982+
IsExpired::No,
983+
SignedEntityType::MithrilStakeDistribution(fake_data::epoch()),
984+
);
977985
let open_message_expected = open_message_created.clone();
978986

979987
let runner = {
@@ -997,7 +1005,11 @@ pub mod tests {
9971005
#[tokio::test]
9981006
async fn test_get_current_non_certified_open_message_should_return_existing_open_message_if_already_exists_and_not_expired(
9991007
) {
1000-
let not_certified_and_not_expired = create_open_message(IsCertified::No, IsExpired::No);
1008+
let not_certified_and_not_expired = create_open_message(
1009+
IsCertified::No,
1010+
IsExpired::No,
1011+
SignedEntityType::MithrilStakeDistribution(fake_data::epoch()),
1012+
);
10011013

10021014
let open_message_expected = not_certified_and_not_expired.clone();
10031015

@@ -1023,8 +1035,16 @@ pub mod tests {
10231035
#[tokio::test]
10241036
async fn test_get_current_non_certified_open_message_should_return_existing_open_message_if_already_exists_and_open_message_already_certified(
10251037
) {
1026-
let certified_and_not_expired = create_open_message(IsCertified::Yes, IsExpired::No);
1027-
let not_certified_and_not_expired = create_open_message(IsCertified::No, IsExpired::No);
1038+
let certified_and_not_expired = create_open_message(
1039+
IsCertified::Yes,
1040+
IsExpired::No,
1041+
SignedEntityType::MithrilStakeDistribution(fake_data::epoch()),
1042+
);
1043+
let not_certified_and_not_expired = create_open_message(
1044+
IsCertified::No,
1045+
IsExpired::No,
1046+
SignedEntityType::CardanoStakeDistribution(fake_data::epoch()),
1047+
);
10281048

10291049
let open_message_expected = not_certified_and_not_expired.clone();
10301050

@@ -1041,7 +1061,7 @@ pub mod tests {
10411061
mock_certifier_service,
10421062
vec![
10431063
SignedEntityTypeDiscriminants::MithrilStakeDistribution,
1044-
SignedEntityTypeDiscriminants::CardanoImmutableFilesFull,
1064+
SignedEntityTypeDiscriminants::CardanoStakeDistribution,
10451065
],
10461066
)
10471067
.await
@@ -1058,9 +1078,16 @@ pub mod tests {
10581078
#[tokio::test]
10591079
async fn test_get_current_non_certified_open_message_should_create_open_message_if_none_exists_and_open_message_already_certified(
10601080
) {
1061-
let certified_and_not_expired = create_open_message(IsCertified::Yes, IsExpired::No);
1062-
1063-
let open_message_created = create_open_message(IsCertified::No, IsExpired::No);
1081+
let certified_and_not_expired = create_open_message(
1082+
IsCertified::Yes,
1083+
IsExpired::No,
1084+
SignedEntityType::MithrilStakeDistribution(fake_data::epoch()),
1085+
);
1086+
let open_message_created = create_open_message(
1087+
IsCertified::No,
1088+
IsExpired::No,
1089+
SignedEntityType::CardanoStakeDistribution(fake_data::epoch()),
1090+
);
10641091
let open_message_expected = open_message_created.clone();
10651092

10661093
let runner = {
@@ -1079,7 +1106,7 @@ pub mod tests {
10791106
mock_certifier_service,
10801107
vec![
10811108
SignedEntityTypeDiscriminants::MithrilStakeDistribution,
1082-
SignedEntityTypeDiscriminants::CardanoImmutableFilesFull,
1109+
SignedEntityTypeDiscriminants::CardanoStakeDistribution,
10831110
],
10841111
)
10851112
.await
@@ -1096,8 +1123,16 @@ pub mod tests {
10961123
#[tokio::test]
10971124
async fn test_get_current_non_certified_open_message_should_return_none_if_all_open_message_already_certified(
10981125
) {
1099-
let certified_and_not_expired_1 = create_open_message(IsCertified::Yes, IsExpired::No);
1100-
let certified_and_not_expired_2 = create_open_message(IsCertified::Yes, IsExpired::No);
1126+
let certified_and_not_expired_1 = create_open_message(
1127+
IsCertified::Yes,
1128+
IsExpired::No,
1129+
SignedEntityType::MithrilStakeDistribution(fake_data::epoch()),
1130+
);
1131+
let certified_and_not_expired_2 = create_open_message(
1132+
IsCertified::Yes,
1133+
IsExpired::No,
1134+
SignedEntityType::CardanoStakeDistribution(fake_data::epoch()),
1135+
);
11011136

11021137
let runner = {
11031138
let mut mock_certifier_service = MockCertifierService::new();
@@ -1112,7 +1147,7 @@ pub mod tests {
11121147
mock_certifier_service,
11131148
vec![
11141149
SignedEntityTypeDiscriminants::MithrilStakeDistribution,
1115-
SignedEntityTypeDiscriminants::CardanoImmutableFilesFull,
1150+
SignedEntityTypeDiscriminants::CardanoStakeDistribution,
11161151
],
11171152
)
11181153
.await
@@ -1129,8 +1164,16 @@ pub mod tests {
11291164
#[tokio::test]
11301165
async fn test_get_current_non_certified_open_message_should_return_first_not_certified_and_not_expired_open_message(
11311166
) {
1132-
let not_certified_and_expired = create_open_message(IsCertified::No, IsExpired::Yes);
1133-
let not_certified_and_not_expired = create_open_message(IsCertified::No, IsExpired::No);
1167+
let not_certified_and_expired = create_open_message(
1168+
IsCertified::No,
1169+
IsExpired::Yes,
1170+
SignedEntityType::MithrilStakeDistribution(fake_data::epoch()),
1171+
);
1172+
let not_certified_and_not_expired = create_open_message(
1173+
IsCertified::No,
1174+
IsExpired::No,
1175+
SignedEntityType::CardanoStakeDistribution(fake_data::epoch()),
1176+
);
11341177

11351178
let open_message_expected = not_certified_and_not_expired.clone();
11361179

@@ -1147,7 +1190,7 @@ pub mod tests {
11471190
mock_certifier_service,
11481191
vec![
11491192
SignedEntityTypeDiscriminants::MithrilStakeDistribution,
1150-
SignedEntityTypeDiscriminants::CardanoImmutableFilesFull,
1193+
SignedEntityTypeDiscriminants::CardanoStakeDistribution,
11511194
],
11521195
)
11531196
.await
@@ -1165,15 +1208,19 @@ pub mod tests {
11651208
async fn test_get_current_non_certified_open_message_called_for_mithril_stake_distribution() {
11661209
let mut mock_certifier_service = MockCertifierService::new();
11671210

1168-
let mut seq = Sequence::new();
11691211
mock_certifier_service
11701212
.expect_get_open_message()
11711213
.with(eq(SignedEntityType::MithrilStakeDistribution(
11721214
TimePoint::dummy().epoch,
11731215
)))
11741216
.times(1)
1175-
.in_sequence(&mut seq)
1176-
.return_once(|_| Ok(Some(create_open_message(IsCertified::Yes, IsExpired::No))));
1217+
.return_once(|_| {
1218+
Ok(Some(create_open_message(
1219+
IsCertified::Yes,
1220+
IsExpired::No,
1221+
SignedEntityType::MithrilStakeDistribution(fake_data::epoch()),
1222+
)))
1223+
});
11771224

11781225
mock_certifier_service.expect_create_open_message().never();
11791226

mithril-aggregator/tests/certificate_chain.rs

Lines changed: 14 additions & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -24,9 +24,7 @@ async fn certificate_chain() {
2424
let configuration = ServeCommandConfiguration {
2525
protocol_parameters: protocol_parameters.clone(),
2626
data_stores_directory: get_test_dir("certificate_chain"),
27-
signed_entity_types: Some(
28-
SignedEntityTypeDiscriminants::CardanoImmutableFilesFull.to_string(),
29-
),
27+
signed_entity_types: Some(SignedEntityTypeDiscriminants::CardanoDatabase.to_string()),
3028
..ServeCommandConfiguration::new_sample(temp_dir!())
3129
};
3230
let mut tester = RuntimeTester::build(
@@ -92,50 +90,45 @@ async fn certificate_chain() {
9290
)
9391
);
9492

95-
comment!("The state machine should get back to signing to sign CardanoImmutableFilesFull");
93+
comment!("The state machine should get back to signing to sign CardanoDatabase");
9694
tester.increase_immutable_number().await.unwrap();
9795
cycle!(tester, "signing");
9896
tester
99-
.send_single_signatures(
100-
SignedEntityTypeDiscriminants::CardanoImmutableFilesFull,
101-
&signers,
102-
)
97+
.send_single_signatures(SignedEntityTypeDiscriminants::CardanoDatabase, &signers)
10398
.await
10499
.unwrap();
105-
comment!("The state machine should issue a certificate for the CardanoImmutableFilesFull");
100+
comment!("The state machine should issue a certificate for the CardanoDatabase");
106101
cycle!(tester, "ready");
107102
assert_last_certificate_eq!(
108103
tester,
109104
ExpectedCertificate::new(
110105
Epoch(1),
111106
StakeDistributionParty::from_signers(initial_fixture.signers_with_stake()).as_slice(),
112107
initial_fixture.compute_and_encode_avk(),
113-
SignedEntityType::CardanoImmutableFilesFull(CardanoDbBeacon::new(1, 3)),
108+
SignedEntityType::CardanoDatabase(CardanoDbBeacon::new(1, 3)),
114109
ExpectedCertificate::genesis_identifier(Epoch(1)),
115110
)
116111
);
117112

118113
comment!(
119-
"Increase immutable number to do a second CardanoImmutableFilesFull certificate for this epoch, {:?}",
114+
"Increase immutable number to do a second CardanoDatabase certificate for this epoch, {:?}",
120115
current_epoch
121116
);
122117
tester.increase_immutable_number().await.unwrap();
123118
cycle!(tester, "signing");
124119
tester
125-
.send_single_signatures(
126-
SignedEntityTypeDiscriminants::CardanoImmutableFilesFull,
127-
&signers,
128-
)
120+
.send_single_signatures(SignedEntityTypeDiscriminants::CardanoDatabase, &signers)
129121
.await
130122
.unwrap();
131123
cycle!(tester, "ready");
124+
tokio::time::sleep(std::time::Duration::from_secs(2)).await;
132125
assert_last_certificate_eq!(
133126
tester,
134127
ExpectedCertificate::new(
135128
Epoch(1),
136129
StakeDistributionParty::from_signers(initial_fixture.signers_with_stake()).as_slice(),
137130
initial_fixture.compute_and_encode_avk(),
138-
SignedEntityType::CardanoImmutableFilesFull(CardanoDbBeacon::new(1, 4)),
131+
SignedEntityType::CardanoDatabase(CardanoDbBeacon::new(1, 4)),
139132
ExpectedCertificate::genesis_identifier(Epoch(1)),
140133
)
141134
);
@@ -267,23 +260,23 @@ async fn certificate_chain() {
267260
);
268261

269262
comment!(
270-
"Increase immutable number to do a CardanoImmutableFilesFull certificate for this epoch, {:?}",
263+
"Increase immutable number to do a CardanoDatabase certificate for this epoch, {:?}",
271264
current_epoch
272265
);
273266
tester.increase_immutable_number().await.unwrap();
274267
cycle!(tester, "signing");
275268

276269
tester
277270
.send_single_signatures(
278-
SignedEntityTypeDiscriminants::CardanoImmutableFilesFull,
271+
SignedEntityTypeDiscriminants::CardanoDatabase,
279272
&next_signers,
280273
)
281274
.await
282275
.unwrap();
283276
cycle!(tester, "ready");
284277

285278
comment!(
286-
"A CardanoImmutableFilesFull, linked to the MithrilStakeDistribution of the current epoch, should have been created, {:?}",
279+
"A CardanoDatabase, linked to the MithrilStakeDistribution of the current epoch, should have been created, {:?}",
287280
current_epoch
288281
);
289282
assert_last_certificate_eq!(
@@ -292,7 +285,7 @@ async fn certificate_chain() {
292285
Epoch(4),
293286
StakeDistributionParty::from_signers(next_fixture.signers_with_stake()).as_slice(),
294287
next_fixture.compute_and_encode_avk(),
295-
SignedEntityType::CardanoImmutableFilesFull(CardanoDbBeacon::new(4, 7)),
288+
SignedEntityType::CardanoDatabase(CardanoDbBeacon::new(4, 7)),
296289
ExpectedCertificate::identifier(&SignedEntityType::MithrilStakeDistribution(Epoch(4))),
297290
)
298291
);
@@ -301,7 +294,7 @@ async fn certificate_chain() {
301294
tester.metrics_verifier,
302295
ExpectedMetrics::new()
303296
.certificate_total(7)
304-
.artifact_cardano_immutable_files_full_total(3)
297+
.artifact_cardano_database_total(3)
305298
.artifact_mithril_stake_distribution_total(4)
306299
);
307300
}

mithril-aggregator/tests/create_certificate.rs

Lines changed: 2 additions & 31 deletions
Original file line numberDiff line numberDiff line change
@@ -25,7 +25,6 @@ async fn create_certificate() {
2525
protocol_parameters: protocol_parameters.clone(),
2626
signed_entity_types: Some(
2727
[
28-
SignedEntityTypeDiscriminants::CardanoImmutableFilesFull.to_string(),
2928
SignedEntityTypeDiscriminants::CardanoTransactions.to_string(),
3029
SignedEntityTypeDiscriminants::CardanoDatabase.to_string(),
3130
]
@@ -104,35 +103,8 @@ async fn create_certificate() {
104103
)
105104
);
106105

107-
comment!("The state machine should get back to signing to sign CardanoImmutableFilesFull when a new immutable file exists");
108-
tester.increase_immutable_number().await.unwrap();
109-
cycle!(tester, "signing");
110-
let signers_for_immutables = &fixture.signers_fixture()[0..=6];
111-
tester
112-
.send_single_signatures(
113-
SignedEntityTypeDiscriminants::CardanoImmutableFilesFull,
114-
signers_for_immutables,
115-
)
116-
.await
117-
.unwrap();
118-
119-
comment!("The state machine should issue a certificate for the CardanoImmutableFilesFull");
120-
cycle!(tester, "ready");
121-
assert_last_certificate_eq!(
122-
tester,
123-
ExpectedCertificate::new(
124-
Epoch(1),
125-
&signers_for_immutables
126-
.iter()
127-
.map(|s| s.signer_with_stake.clone().into())
128-
.collect::<Vec<_>>(),
129-
fixture.compute_and_encode_avk(),
130-
SignedEntityType::CardanoImmutableFilesFull(CardanoDbBeacon::new(1, 3)),
131-
ExpectedCertificate::genesis_identifier(Epoch(1)),
132-
)
133-
);
134-
135106
comment!("The state machine should get back to signing to sign CardanoDatabase with the previously created immutable file");
107+
tester.increase_immutable_number().await.unwrap();
136108
cycle!(tester, "signing");
137109
let signers_for_cardano_database = &fixture.signers_fixture()[1..=6];
138110
tester
@@ -238,8 +210,7 @@ async fn create_certificate() {
238210
assert_metrics_eq!(
239211
tester.metrics_verifier,
240212
ExpectedMetrics::new()
241-
.certificate_total(5)
242-
.artifact_cardano_immutable_files_full_total(1)
213+
.certificate_total(4)
243214
.artifact_cardano_database_total(1)
244215
.artifact_mithril_stake_distribution_total(1)
245216
.artifact_cardano_transaction_total(2)

mithril-aggregator/tests/create_certificate_follower.rs

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -104,9 +104,7 @@ async fn create_certificate_follower() {
104104
security_parameter: BlockNumber(0),
105105
step: BlockNumber(30),
106106
},
107-
signed_entity_types: Some(
108-
SignedEntityTypeDiscriminants::CardanoImmutableFilesFull.to_string(),
109-
),
107+
signed_entity_types: Some(SignedEntityTypeDiscriminants::CardanoDatabase.to_string()),
110108
..ServeCommandConfiguration::new_sample(temp_dir!())
111109
};
112110
let mut leader_tester =

0 commit comments

Comments
 (0)