Skip to content

Commit a642884

Browse files
committed
Use one bind for aggregator db layer test data insert
1 parent a224706 commit a642884

File tree

7 files changed

+150
-190
lines changed

7 files changed

+150
-190
lines changed

mithril-aggregator/src/database/provider/certificate.rs

Lines changed: 42 additions & 60 deletions
Original file line numberDiff line numberDiff line change
@@ -777,68 +777,50 @@ mod tests {
777777
for certificate in certificates {
778778
let certificate_record: CertificateRecord = certificate.into();
779779
let mut statement = connection.prepare(&query)?;
780-
781-
statement
782-
.bind((1, certificate_record.certificate_id.as_str()))
783-
.unwrap();
784-
if let Some(parent_certificate_id) = certificate_record.parent_certificate_id {
785-
statement.bind((2, parent_certificate_id.as_str())).unwrap();
786-
} else {
787-
statement.bind((2, &Value::Null)).unwrap();
788-
}
789-
statement
790-
.bind((3, certificate_record.message.as_str()))
791-
.unwrap();
792-
statement
793-
.bind((4, certificate_record.signature.as_str()))
794-
.unwrap();
795-
statement
796-
.bind((5, certificate_record.aggregate_verification_key.as_str()))
797-
.unwrap();
798780
statement
799-
.bind((6, certificate_record.epoch.0 as i64))
800-
.unwrap();
801-
statement
802-
.bind((
803-
7,
804-
serde_json::to_string(&certificate_record.beacon)
805-
.unwrap()
806-
.as_str(),
807-
))
808-
.unwrap();
809-
statement
810-
.bind((8, certificate_record.protocol_version.as_str()))
811-
.unwrap();
812-
statement
813-
.bind((
814-
9,
815-
serde_json::to_string(&certificate_record.protocol_parameters)
816-
.unwrap()
817-
.as_str(),
818-
))
819-
.unwrap();
820-
statement
821-
.bind((
822-
10,
823-
serde_json::to_string(&certificate_record.protocol_message)
824-
.unwrap()
825-
.as_str(),
826-
))
827-
.unwrap();
828-
statement
829-
.bind((
830-
11,
831-
serde_json::to_string(&certificate_record.signers)
832-
.unwrap()
833-
.as_str(),
834-
))
835-
.unwrap();
836-
statement
837-
.bind((12, certificate_record.initiated_at.to_rfc3339().as_str()))
838-
.unwrap();
839-
statement
840-
.bind((13, certificate_record.sealed_at.to_rfc3339().as_str()))
781+
.bind::<&[(_, Value)]>(&[
782+
(1, certificate_record.certificate_id.into()),
783+
(
784+
2,
785+
match certificate_record.parent_certificate_id {
786+
None => Value::Null,
787+
Some(parent_certificate_id) => parent_certificate_id.into(),
788+
},
789+
),
790+
(3, certificate_record.message.into()),
791+
(4, certificate_record.signature.into()),
792+
(5, certificate_record.aggregate_verification_key.into()),
793+
(6, i64::try_from(certificate_record.epoch.0).unwrap().into()),
794+
(
795+
7,
796+
serde_json::to_string(&certificate_record.beacon)
797+
.unwrap()
798+
.into(),
799+
),
800+
(8, certificate_record.protocol_version.into()),
801+
(
802+
9,
803+
serde_json::to_string(&certificate_record.protocol_parameters)
804+
.unwrap()
805+
.into(),
806+
),
807+
(
808+
10,
809+
serde_json::to_string(&certificate_record.protocol_message)
810+
.unwrap()
811+
.into(),
812+
),
813+
(
814+
11,
815+
serde_json::to_string(&certificate_record.signers)
816+
.unwrap()
817+
.into(),
818+
),
819+
(12, certificate_record.initiated_at.to_rfc3339().into()),
820+
(13, certificate_record.sealed_at.to_rfc3339().into()),
821+
])
841822
.unwrap();
823+
842824
statement.next().unwrap();
843825
}
844826

mithril-aggregator/src/database/provider/epoch_setting.rs

Lines changed: 8 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -425,14 +425,16 @@ mod tests {
425425
];
426426
for (epoch, protocol_parameters) in epoch_settings {
427427
let mut statement = connection.prepare(&query)?;
428-
429-
statement.bind((1, *epoch)).unwrap();
430428
statement
431-
.bind((
432-
2,
433-
serde_json::to_string(protocol_parameters).unwrap().as_str(),
434-
))
429+
.bind::<&[(_, Value)]>(&[
430+
(1, Value::Integer(*epoch)),
431+
(
432+
2,
433+
serde_json::to_string(protocol_parameters).unwrap().into(),
434+
),
435+
])
435436
.unwrap();
437+
436438
statement.next().unwrap();
437439
}
438440

mithril-aggregator/src/database/provider/signed_entity.rs

Lines changed: 20 additions & 24 deletions
Original file line numberDiff line numberDiff line change
@@ -562,31 +562,27 @@ mod tests {
562562

563563
for signed_entity_record in signed_entity_records {
564564
let mut statement = connection.prepare(&query)?;
565-
566-
statement
567-
.bind((1, signed_entity_record.signed_entity_id.as_str()))
568-
.unwrap();
569-
statement
570-
.bind((2, signed_entity_record.signed_entity_type.index() as i64))
571-
.unwrap();
572565
statement
573-
.bind((3, signed_entity_record.certificate_id.as_str()))
574-
.unwrap();
575-
statement
576-
.bind((
577-
4,
578-
signed_entity_record
579-
.signed_entity_type
580-
.get_json_beacon()
581-
.unwrap()
582-
.as_str(),
583-
))
584-
.unwrap();
585-
statement
586-
.bind((5, signed_entity_record.artifact.as_str()))
587-
.unwrap();
588-
statement
589-
.bind((6, signed_entity_record.created_at.to_rfc3339().as_str()))
566+
.bind::<&[(_, Value)]>(&[
567+
(1, signed_entity_record.signed_entity_id.into()),
568+
(
569+
2,
570+
i64::try_from(signed_entity_record.signed_entity_type.index())
571+
.unwrap()
572+
.into(),
573+
),
574+
(3, signed_entity_record.certificate_id.into()),
575+
(
576+
4,
577+
signed_entity_record
578+
.signed_entity_type
579+
.get_json_beacon()
580+
.unwrap()
581+
.into(),
582+
),
583+
(5, signed_entity_record.artifact.into()),
584+
(6, signed_entity_record.created_at.to_rfc3339().into()),
585+
])
590586
.unwrap();
591587

592588
statement.next().unwrap();

mithril-aggregator/src/database/provider/signer.rs

Lines changed: 12 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -328,24 +328,19 @@ mod tests {
328328

329329
for signer_record in signer_records {
330330
let mut statement = connection.prepare(&query)?;
331-
332-
statement
333-
.bind((1, signer_record.signer_id.as_str()))
334-
.unwrap();
335-
statement
336-
.bind((
337-
2,
338-
&signer_record
339-
.pool_ticker
340-
.map(Value::String)
341-
.unwrap_or(Value::Null),
342-
))
343-
.unwrap();
344-
statement
345-
.bind((3, signer_record.created_at.to_rfc3339().as_str()))
346-
.unwrap();
347331
statement
348-
.bind((4, signer_record.updated_at.to_rfc3339().as_str()))
332+
.bind::<&[(_, Value)]>(&[
333+
(1, signer_record.signer_id.into()),
334+
(
335+
2,
336+
signer_record
337+
.pool_ticker
338+
.map(Value::String)
339+
.unwrap_or(Value::Null),
340+
),
341+
(3, signer_record.created_at.to_rfc3339().into()),
342+
(4, signer_record.updated_at.to_rfc3339().into()),
343+
])
349344
.unwrap();
350345
statement.next().unwrap();
351346
}

mithril-aggregator/src/database/provider/signer_registration.rs

Lines changed: 40 additions & 50 deletions
Original file line numberDiff line numberDiff line change
@@ -558,58 +558,48 @@ mod tests {
558558
let signer_registration_record =
559559
SignerRegistrationRecord::from_signer_with_stake(signer_with_stake, epoch);
560560
let mut statement = connection.prepare(&query)?;
561-
562-
statement
563-
.bind((1, signer_registration_record.signer_id.as_str()))
564-
.unwrap();
565-
statement
566-
.bind((2, signer_registration_record.epoch_setting_id.0 as i64))
567-
.unwrap();
568-
statement
569-
.bind((3, signer_registration_record.verification_key.as_str()))
570-
.unwrap();
571561
statement
572-
.bind((
573-
4,
574-
&signer_registration_record
575-
.verification_key_signature
576-
.map(Value::String)
577-
.unwrap_or(Value::Null),
578-
))
579-
.unwrap();
580-
statement
581-
.bind((
582-
5,
583-
&signer_registration_record
584-
.operational_certificate
585-
.map(Value::String)
586-
.unwrap_or(Value::Null),
587-
))
588-
.unwrap();
589-
statement
590-
.bind((
591-
6,
592-
&signer_registration_record
593-
.kes_period
594-
.map(|k| Value::Integer(k as i64))
595-
.unwrap_or(Value::Null),
596-
))
597-
.unwrap();
598-
statement
599-
.bind((
600-
7,
601-
&signer_registration_record
602-
.stake
603-
.map(|s| Value::Integer(s as i64))
604-
.unwrap_or(Value::Null),
605-
))
606-
.unwrap();
607-
statement
608-
.bind((
609-
8,
610-
signer_registration_record.created_at.to_rfc3339().as_str(),
611-
))
562+
.bind::<&[(_, Value)]>(&[
563+
(1, signer_registration_record.signer_id.into()),
564+
(
565+
2,
566+
i64::try_from(signer_registration_record.epoch_setting_id.0)
567+
.unwrap()
568+
.into(),
569+
),
570+
(3, signer_registration_record.verification_key.into()),
571+
(
572+
4,
573+
signer_registration_record
574+
.verification_key_signature
575+
.map(Value::String)
576+
.unwrap_or(Value::Null),
577+
),
578+
(
579+
5,
580+
signer_registration_record
581+
.operational_certificate
582+
.map(Value::String)
583+
.unwrap_or(Value::Null),
584+
),
585+
(
586+
6,
587+
signer_registration_record
588+
.kes_period
589+
.map(|k| Value::Integer(k as i64))
590+
.unwrap_or(Value::Null),
591+
),
592+
(
593+
7,
594+
signer_registration_record
595+
.stake
596+
.map(|s| Value::Integer(s as i64))
597+
.unwrap_or(Value::Null),
598+
),
599+
(8, signer_registration_record.created_at.to_rfc3339().into()),
600+
])
612601
.unwrap();
602+
613603
statement.next().unwrap();
614604
}
615605
}

mithril-aggregator/src/database/provider/stake_pool.rs

Lines changed: 6 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -322,12 +322,13 @@ mod tests {
322322
];
323323
for (pool_id, epoch, stake) in stake_distribution {
324324
let mut statement = connection.prepare(&query)?;
325-
326-
statement.bind((1, *pool_id)).unwrap();
327-
statement.bind((2, *epoch)).unwrap();
328-
statement.bind((3, *stake)).unwrap();
329325
statement
330-
.bind((4, Utc::now().to_rfc3339().as_str()))
326+
.bind::<&[(_, Value)]>(&[
327+
(1, pool_id.to_string().into()),
328+
(2, Value::Integer(*epoch)),
329+
(3, Value::Integer(*stake)),
330+
(4, Utc::now().to_rfc3339().into()),
331+
])
331332
.unwrap();
332333
statement.next().unwrap();
333334
}

0 commit comments

Comments
 (0)