diff --git a/Cargo.lock b/Cargo.lock index 435ee3cce8f..6622473f1c6 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -2096,7 +2096,7 @@ dependencies = [ [[package]] name = "mithril-aggregator" -version = "0.3.55" +version = "0.3.56" dependencies = [ "async-trait", "chrono", @@ -2169,7 +2169,7 @@ dependencies = [ [[package]] name = "mithril-common" -version = "0.2.80" +version = "0.2.81" dependencies = [ "anyhow", "async-trait", diff --git a/mithril-aggregator/Cargo.toml b/mithril-aggregator/Cargo.toml index 48c67a72c60..860a71c3e8d 100644 --- a/mithril-aggregator/Cargo.toml +++ b/mithril-aggregator/Cargo.toml @@ -1,6 +1,6 @@ [package] name = "mithril-aggregator" -version = "0.3.55" +version = "0.3.56" description = "A Mithril Aggregator server" authors = { workspace = true } edition = { workspace = true } diff --git a/mithril-aggregator/src/database/provider/certificate.rs b/mithril-aggregator/src/database/provider/certificate.rs index b6b25b6b6c9..663e2283243 100644 --- a/mithril-aggregator/src/database/provider/certificate.rs +++ b/mithril-aggregator/src/database/provider/certificate.rs @@ -827,6 +827,54 @@ mod tests { Ok(()) } + fn insert_golden_certificate(connection: &Connection) { + connection + .execute(r#" + insert into certificate + values( + 'bfb4efbd48d58f7677ddb7d5fe5b5b9e998e8ca549cbf7583873bdccfc70f194', + null, + '08420665c56dcf6981b7d8b64b5a584e148edbf7638f466cb36b278ce962439c', + 'b7944ddc7d728812f8e68abc93b668a84876e9867b97648bc937b20debdff15a8415470ee709599d1a12a50ac5a57a3a4955cf19307d04955fcad6931c3b9505', + '7b226d745f636f6d6d69746d656e74223a7b22726f6f74223a5b37372c3230382c3138392c3138372c37362c3136322c36382c3233382c3134342c31372c3131342c3137352c36302c3136352c3230322c3134362c3139342c31332c37332c3233392c3233372c3232322c3136392c3230362c352c3130392c3132332c35322c3235342c39382c3133312c37395d2c226e725f6c6561766573223a332c22686173686572223a6e756c6c7d2c22746f74616c5f7374616b65223a32383439323639303636317d', + 241, + '{"network":"preview","epoch":241,"immutable_file_number":4823}', + '0.1.0', + '{"k":2422,"m":20973,"phi_f":0.2}', + '{"message_parts":{ + "next_aggregate_verification_key":"7b226d745f636f6d6d69746d656e74223a7b22726f6f74223a5b37372c3230382c3138392c3138372c37362c3136322c36382c3233382c3134342c31372c3131342c3137352c36302c3136352c3230322c3134362c3139342c31332c37332c3233392c3233372c3232322c3136392c3230362c352c3130392c3132332c35322c3235342c39382c3133312c37395d2c226e725f6c6561766573223a332c22686173686572223a6e756c6c7d2c22746f74616c5f7374616b65223a32383439323639303636317d" + }}', + '[{ + "party_id":"pool1vapqexnsx6hvc588yyysxpjecf3k43hcr5mvhmstutuvy085xpa", + "verification_key":"7b22766b223a5b3133382c33322c3133382c3135322c3134362c3235352c3130382c3139302c37302c34322c3132362c3137322c31392c3135312c3133392c3133392c3235352c33352c3134312c38322c3138372c33372c3133332c3235322c3139322c302c32362c32342c3134342c372c3235332c3136362c3135312c3139332c392c3230392c3131392c3230302c3134312c34312c38302c342c3231372c3132322c3132302c3235332c3230382c3131312c362c37382c3234362c3134362c3131382c352c3235312c31392c3234332c3138342c3233382c3139352c39392c3235312c3135312c342c39342c3133382c3234362c33362c33372c34382c3133362c3130302c3233352c3134312c3232382c392c39362c3131332c35392c3137352c3130322c3232392c39352c39332c3134332c3137312c3130302c32302c3133362c36372c33302c3133312c3135332c32362c35372c3132385d2c22706f70223a5b3137342c3233302c33382c3138312c3131332c38332c372c34332c3130312c38392c3133372c3133302c37302c3135382c3235342c31342c31362c36372c38332c362c3234322c39312c3136372c34352c3232392c3139382c3130312c37302c3232382c36312c3138302c3132302c3130332c3232302c3231312c3134362c3136322c37302c33382c3230352c3139312c3235322c3138342c3235322c39362c3134382c3130322c3133362c3136362c34322c3137382c3133352c3130302c33312c38392c3233342c3135392c3131382c33382c3133392c31362c3134342c3132382c3134382c3132382c3139312c31382c34382c38392c3136352c35342c3134362c36332c3136302c3138362c3139362c31392c3137312c3136302c31342c39322c35382c3232312c3138352c3132392c382c3133322c35352c3231382c3235302c39352c32312c3235302c3135312c36352c3231395d7d", + "verification_key_signature":"7b227369676d61223a7b227369676d61223a7b227369676d61223a7b227369676d61223a7b227369676d61223a7b227369676d61223a5b35342c35372c32332c3234302c3234342c3130352c3139322c3138312c3130362c3232312c3132302c3139382c3136392c3134372c3233362c34382c32342c35382c3233352c31332c36302c31352c3231382c33312c34352c3135322c3133302c3230382c36392c38312c34372c3135302c3234352c3234332c32352c39342c3134382c3136322c39322c3136392c3131352c37382c31352c38382c3139382c38342c3233322c3138342c3135372c3139352c35342c3136352c33352c382c3232342c3130312c3138392c38372c32392c3131342c3133322c33382c3132322c31305d2c226c68735f706b223a5b3139322c3135342c3230322c3233342c36352c3234332c3132392c3230302c3131382c3137352c3131342c3233352c3232322c3235342c3134322c3232332c3137372c3233342c31352c31382c34312c31362c38382c38352c37322c3130372c33322c3134382c33352c35312c3132352c34355d2c227268735f706b223a5b3137342c39352c3132342c31382c36322c3135312c3137302c3136382c3232332c36362c3132322c36312c3234322c3130372c3132352c3137372c3137302c3132332c35382c3231362c3137362c392c3234302c3131382c3131302c35362c3232372c3230302c3131322c3130352c32392c3230385d7d2c226c68735f706b223a5b36392c3138322c39392c382c34302c39332c3130382c3233312c382c312c3235322c3131302c3132322c37332c3133302c3230372c3231332c3137312c3130352c3232322c31352c3134322c3230362c3137392c33382c3132302c39322c362c32302c3133352c3130382c3138335d2c227268735f706b223a5b33342c36372c3134302c3132392c3231352c36392c3136302c3135362c3230302c31302c3232362c35382c3132322c36342c33382c3135362c3230362c3230362c302c3137382c3132302c3139332c362c3135332c3131322c3130392c3135372c3131322c3132322c3133372c3233372c38355d7d2c226c68735f706b223a5b37332c3131342c3136352c3137312c34322c3131372c3139322c3139342c3137342c32302c38312c392c3230392c31392c3134352c3233302c3233302c3130392c34382c3135302c31332c3232392c3139322c35342c3138362c3137372c32382c3133362c31352c3230342c3231342c3132305d2c227268735f706b223a5b3139302c32322c3131312c38362c38322c3138362c3231372c3134312c302c3136382c3130382c3230362c3130392c332c3138342c3230342c382c3138362c3136362c32312c39372c34342c3135352c332c3136352c3139392c3132372c39312c3233382c38362c3139302c35305d7d2c226c68735f706b223a5b3135392c37352c3131382c3132372c3139382c34342c3137392c34322c3231382c3131382c3235332c3139392c32342c37312c3133302c362c3136332c3131342c3133392c31332c3130392c31372c3132372c35312c39342c3133312c3132382c3230332c3131382c3231312c3137392c36365d2c227268735f706b223a5b3139312c3136342c33362c3131312c37362c3132372c3231382c3230352c3234322c3134322c3230312c3233322c3235322c3233322c35372c39362c3131372c3232362c37332c34322c3231372c3235342c3130382c3233342c3234372c3137362c3234372c3133302c32342c36332c31392c38355d7d2c226c68735f706b223a5b35342c33392c3235342c33322c3131392c39332c3138322c3132372c3136352c3134362c3230352c33392c36352c3139362c3134362c36392c36392c34332c3139382c3130322c3139342c35372c31332c3230302c3232332c39382c38322c3134312c3133362c35382c3235322c3130325d2c227268735f706b223a5b3137372c34322c33372c3133322c3133352c3130322c3135342c392c3233362c31392c3235302c3235312c39382c36352c3133302c3232352c3136382c3232362c3136352c34392c35302c35322c3134312c3136392c35312c3230342c3234362c3130302c3233372c3234362c39322c32345d7d2c226c68735f706b223a5b33302c38302c3232322c3233372c3139302c342c3130352c3230362c37302c31372c3234382c3134322c362c31332c3137352c3136332c38342c3231352c3132322c3235352c3232302c3131382c34382c33312c34352c33332c3233372c3234352c3235302c3234302c3132392c3131355d2c227268735f706b223a5b3132332c31302c31352c36332c3138312c3231382c31302c36362c3138382c3138312c3130302c3138302c3130302c3139352c3137382c38372c3233362c32382c3138322c35362c3232362c35382c3234302c3131322c392c3133322c39332c33302c33372c3136332c3134322c39315d7d", + "operational_certificate":"5b5b5b3131322c39352c34322c39372c382c3235322c31382c3231342c31392c3231382c3231372c3234322c3233302c3138372c3234302c3133392c31342c3135382c3137392c3234392c3231312c36332c3132332c342c32362c3132362c3132312c3234372c302c35372c31362c3136315d2c312c37312c5b3132392c3234382c3133342c3132342c3230372c3130332c3233312c37302c3130372c32382c3134322c3134312c38362c3234392c3230352c31312c33392c3232382c3130382c3132322c3233312c3138322c3132372c3130312c3234352c33332c3135322c3233342c35342c36372c3138312c39362c3137372c3234362c32382c322c3235322c3130382c35392c3231352c3232372c3230392c3131382c3130352c3135342c37312c36332c3134352c3132372c3137352c3133382c3131352c39362c3233352c3131382c31322c3234302c3232352c3130392c3130382c3231322c3232392c35372c31305d5d2c5b33302c3138312c32302c37382c33392c3232332c352c3133372c3134312c3138392c372c3132372c34352c3232372c3230362c3135372c39352c3131352c36312c3132382c3135392c3135362c34332c3132372c302c34302c3134332c3138332c3233302c32352c39312c3137305d5d", + "kes_period":22, + "stake":1009497432569 + }]', + '2023-06-23T08:37:49.066Z', + '2023-06-23T08:37:49.066Z' + ); + "#, + ) + .unwrap(); + } + + #[test] + fn test_golden_master() { + let connection = Connection::open(":memory:").unwrap(); + setup_certificate_db(&connection, vec![]).unwrap(); + insert_golden_certificate(&connection); + + let provider = CertificateRecordProvider::new(&connection); + let certificate_records: Vec = provider + .get_all() + .expect("Getting Golden certificate should not fail") + .collect(); + + assert_eq!(certificate_records.len(), 1); + } + #[test] fn test_convert_certificates() { let (certificates, _) = setup_certificate_chain(20, 3); diff --git a/mithril-aggregator/src/database/provider/signed_entity.rs b/mithril-aggregator/src/database/provider/signed_entity.rs index 2e54b6e5bcb..b0efa552519 100644 --- a/mithril-aggregator/src/database/provider/signed_entity.rs +++ b/mithril-aggregator/src/database/provider/signed_entity.rs @@ -502,6 +502,7 @@ impl SignedEntityStorer for SignedEntityStoreAdapter { #[cfg(test)] mod tests { use crate::database::provider::{apply_all_migrations_to_db, disable_foreign_key_support}; + use mithril_common::entities::MithrilStakeDistribution; use mithril_common::{entities::Beacon, test_utils::fake_data}; use super::*; @@ -597,6 +598,74 @@ mod tests { Ok(()) } + fn insert_golden_signed_entities(connection: &Connection) { + connection + .execute(r#" + -- Cardano immutable file full + insert into signed_entity values( + 'bfcd77e372a25e13353bb77697d0d08785ba98b703e22640a317c5054dc05fb1', + 2, + '258edf0f1238c60985d0229869a6d4c4c635c118915b4d524d2686515be99946', + '{"network":"preview","epoch":142,"immutable_file_number":2847}', + '2023-05-09T13:11:15Z', + '{ + "digest":"bfcd77e372a25e13353bb77697d0d08785ba98b703e22640a317c5054dc05fb1", + "beacon":{"network":"preview","epoch":142,"immutable_file_number":2847}, + "size":1689696245, + "locations":["https://storage.googleapis.com/mithril-testing-preview-cs/preview-e142-i2847.bfcd77e372a25e13353bb77697d0d08785ba98b703e22640a317c5054dc05fb1.tar.gz" + ]}' + ); + + -- Mithril stake distribution + insert into signed_entity + values( + '2da62e3ffee5e284ffd1e29ee52ee5547c5ff5ef34bee0a49dc54ea5e375f77e', + 0, + 'ad2d3705693dfaae8baac099b6976a5cc3e0f708245d0fa79d149a3fcbc79f00', + 203, + '2023-05-16T02:17:16.203859116Z', + '{ + "type":"MithrilStakeDistribution", + "epoch":203, + "signers_with_stake":[{ + "party_id":"pool1r0tln8nct3mpyvehgy6uu3cdlmjnmtr2fxjcqnfl6v0qg0we42e", + "verification_key":"7b22766b223a5b3138352c3132342c3231382c31362c3133312c3137382c3136302c37312c35382c3235312c31382c36382c37372c3135342c35382c3131352c3133392c3139392c38392c3230382c3139312c3235332c3138362c3232302c3133372c3135382c34312c3230332c382c3136352c3232362c3139342c3133382c3135322c35382c3131352c35342c3136322c3230332c32322c32332c3232382c3139342c34382c3137322c3139342c3130352c36382c302c3138302c3131332c3230312c3130392c3234372c39362c39342c3232372c3135372c36322c3139352c3134382c33352c3230352c3133372c3132312c3135322c3130302c3138342c3136372c3230362c3133322c34352c3133382c3131312c38392c3138322c3230352c3138372c3135382c32322c32332c3231382c36342c3137332c35392c3134312c3133332c3138302c3131392c36302c3134392c3134382c38332c3234312c3230312c33375d2c22706f70223a5b3137352c3135382c3130322c34352c3133322c38352c33312c3130342c36352c3230342c38352c312c34332c3137382c3138372c3233382c3135372c32372c39312c3230332c35342c37332c36322c35352c3131322c3131352c302c32312c3130302c3230382c37392c3135382c3233332c3132372c38332c3234352c3134362c3231382c3131382c3139332c38322c3139352c3137302c32312c36382c3231342c3138352c38372c3136382c3135372c3230322c3136382c3132392c3233332c38372c3230332c37372c36332c3232312c31362c3130392c33302c3235312c35312c38342c36392c3233372c39382c3133372c36302c39312c37362c38302c3232322c302c3130342c3231332c3132352c31332c3135312c3133312c3130312c3230312c33322c3138392c3137362c3139392c3131342c3234302c31352c33312c3136302c31332c3136352c32372c3134335d7d", + "verification_key_signature":"7b227369676d61223a7b227369676d61223a7b227369676d61223a7b227369676d61223a7b227369676d61223a7b227369676d61223a5b36322c33302c32362c3131302c3134382c3137342c36302c32392c3139302c34362c37342c3135392c3137312c3134362c31342c3231362c37352c32302c38352c3134342c32332c3134352c3132352c39382c36362c3132342c3139332c32352c3233352c3234372c3130342c382c352c3133342c302c3134302c3131352c33362c31342c33382c31322c34392c39372c33392c3232312c3234352c39322c362c35302c3134362c3135372c3136362c32382c38352c33312c33352c3232392c3233312c34332c3230322c34372c3235352c3138322c375d2c226c68735f706b223a5b3234322c3132322c34322c39332c39352c31322c36352c3131332c31342c35322c3135352c3133372c3130312c3137382c3232362c3133332c31372c39302c3138332c3132312c3136362c35322c342c39312c3135332c3232332c32352c3133372c37332c3137332c3235332c3233315d2c227268735f706b223a5b322c3231312c3230372c3234392c3234322c362c3131322c362c3235322c31322c3135362c3139332c38362c3133362c3138352c36342c3132342c35302c3230392c38382c3138322c3133352c32392c3138372c3133302c3138392c34312c3134302c34322c33342c3135392c3234365d7d2c226c68735f706b223a5b37352c3232312c3235302c3235322c3135382c3134362c35362c34312c39382c3137362c3139382c3231392c33352c3130392c3136332c36312c3139362c3139342c3137382c3130392c3132382c3131352c3130302c3135322c33392c3231392c35382c34392c3235302c33312c3138342c395d2c227268735f706b223a5b3135372c3232312c38372c3139342c3235322c3234382c3132372c33312c3136362c3235322c3233342c3232362c33362c3139352c3230312c33312c34372c3232302c3233372c3137342c3130372c3134342c33382c3234372c3135352c3135382c34372c3139302c3235322c3134302c3235342c3131375d7d2c226c68735f706b223a5b34322c37372c37392c36302c3137312c3234372c31392c3230332c3232302c36332c3231352c3135372c3132392c3230382c3135382c35352c3131302c3232312c3139372c3233322c38372c33312c31312c3235342c3133352c32372c3234352c3137352c3135342c3231382c3232312c3138345d2c227268735f706b223a5b36382c3230332c38362c31352c37352c33352c3232332c342c3130392c3234392c3231372c3132352c34372c3231372c3130342c36352c3131332c3234312c3235332c3138332c3138362c36362c37352c3135302c3233342c3138362c3137332c3233302c3130332c3139342c3135322c3132375d7d2c226c68735f706b223a5b3133312c38372c3135382c3233352c34312c3233372c33332c34362c3235342c38302c3235322c3132392c37332c3234382c3135332c33382c3138332c33342c3231362c3135362c3131302c36392c37322c39302c32382c36382c3131342c33352c33352c3134332c3234312c3231305d2c227268735f706b223a5b3232382c3135352c3133332c34312c3137392c39342c3233362c3133392c3231362c3136302c3130382c3137362c3134362c3232352c3134302c3231352c35392c3130372c32302c3133372c3139372c33392c3135332c3132362c3233372c3135382c3132332c392c3133322c3139342c3132312c3232355d7d2c226c68735f706b223a5b3232322c39362c35332c34312c32342c38382c3136342c39382c3133312c33342c3132362c3133392c32382c37342c34362c3137332c35302c3133362c39372c3137312c3130312c3136322c33312c3137352c32332c3130352c3231352c36332c37362c3132342c31322c3131365d2c227268735f706b223a5b3133382c31382c31302c352c3231382c3134372c35332c35322c33362c3234342c33362c3131302c31302c33382c3134382c3132332c3235302c3131352c36342c36372c3137332c3130352c3137392c3235342c3130352c332c3132372c32302c31322c3230352c37372c3230365d7d2c226c68735f706b223a5b3132342c382c37312c3135302c34352c3130362c3232322c3234372c3130302c3137342c34352c3135322c3136312c3130382c3135382c32372c3234342c35362c3131352c3233322c3136332c3234342c38372c3138332c3232372c3235302c3232372c3234382c3137352c3136332c3230392c37345d2c227268735f706b223a5b3134302c33372c3131392c36332c39302c3132302c3131332c3135372c3130352c34362c31342c33332c3230372c3131322c3131332c3235342c38342c37332c3131302c33392c392c3230372c3133312c342c3232352c39302c3135312c32302c31352c36342c39372c39385d7d", + "operational_certificate":"5b5b5b3138332c33342c3231362c34362c3232372c3235312c37342c3130312c31352c3233332c3234392c34322c312c37372c37322c3234382c3137392c32312c3137332c3131332c3131382c3139382c36322c3133352c34352c38382c3138372c3233332c34302c37322c31362c36365d2c312c3132332c5b31362c3136392c3134312c3138332c32322c3137342c3131312c33322c36342c35322c3234392c36382c3230322c33352c3130362c332c38362c3230352c37382c3230302c3138362c39342c3139372c3232382c37392c3137352c32392c31342c3132382c36332c35392c3139382c36322c3233302c34362c34312c38342c39382c3131392c3134352c32392c3132312c33352c3139372c3132382c3137322c302c3135342c392c31332c32362c3138332c3138362c3138362c33312c3234392c3133322c3232392c3235332c3134332c3130322c3235342c3231322c315d5d2c5b3234312c32372c31332c34342c3131342c37382c3138392c3234392c3135302c3135302c35332c3134342c3233362c3135312c38382c3134302c3132382c3136322c36302c3232382c38382c3131312c392c3134342c3233322c38332c39342c3231302c3135362c3136382c33352c3234325d5d", + "kes_period":12, + "stake":9497629046 + }], + "hash":"2da62e3ffee5e284ffd1e29ee52ee5547c5ff5ef34bee0a49dc54ea5e375f77e", + "protocol_parameters":{"k":2422,"m":20973,"phi_f":0.2}}' + ); + + "#, + ) + .unwrap(); + } + + #[test] + fn test_golden_master() { + let connection = Connection::open(":memory:").unwrap(); + setup_signed_entity_db(&connection, vec![]).unwrap(); + insert_golden_signed_entities(&connection); + + let provider = SignedEntityRecordProvider::new(&connection); + let cardano_immutable_files_fulls: Vec> = provider + .get_by_signed_entity_type(&SignedEntityTypeDiscriminants::CardanoImmutableFilesFull) + .expect("Getting Golden snapshot signed entities should not fail") + .map(|r| r.try_into().unwrap()) + .collect(); + let mithril_stake_distributions: Vec> = provider + .get_by_signed_entity_type(&SignedEntityTypeDiscriminants::MithrilStakeDistribution) + .expect("Getting Golden mithril stake distribution signed entities should not fail") + .map(|r| r.try_into().unwrap()) + .collect(); + + assert_eq!(cardano_immutable_files_fulls.len(), 1); + assert_eq!(mithril_stake_distributions.len(), 1); + } + #[test] fn test_convert_signed_entity() { let snapshots = fake_data::snapshots(1); diff --git a/mithril-common/Cargo.toml b/mithril-common/Cargo.toml index 2cafa335bef..1ef0934edfe 100644 --- a/mithril-common/Cargo.toml +++ b/mithril-common/Cargo.toml @@ -1,6 +1,6 @@ [package] name = "mithril-common" -version = "0.2.80" +version = "0.2.81" authors = { workspace = true } edition = { workspace = true } documentation = { workspace = true } diff --git a/mithril-common/src/crypto_helper/verification_key.rs b/mithril-common/src/crypto_helper/verification_key.rs index b4a4215caeb..cb07df825ac 100644 --- a/mithril-common/src/crypto_helper/verification_key.rs +++ b/mithril-common/src/crypto_helper/verification_key.rs @@ -6,12 +6,35 @@ use super::{key_decode_hex, key_encode_hex}; /// Wrapper of [MithrilStm:StmVerificationKeyPoP](type@mithril_stm::stm::StmVerificationKeyPoP) /// to add serialization utilities. -#[derive(Debug, Clone, PartialEq, Eq, Serialize, Deserialize)] +#[derive(Debug, Clone, PartialEq, Eq)] pub struct ProtocolSignerVerificationKey { - #[serde(flatten)] verification_key: StmVerificationKeyPoP, } +impl Serialize for ProtocolSignerVerificationKey { + fn serialize(&self, serializer: S) -> Result + where + S: serde::Serializer, + { + use serde::ser::Error; + let hex = self.to_json_hex().map_err(Error::custom)?; + + hex.serialize(serializer) + } +} + +impl<'de> Deserialize<'de> for ProtocolSignerVerificationKey { + fn deserialize(deserializer: D) -> Result + where + D: serde::Deserializer<'de>, + { + use serde::de::Error; + let string = String::deserialize(deserializer)?; + + Self::from_json_hex(&string).map_err(Error::custom) + } +} + impl From for ProtocolSignerVerificationKey { fn from(value: StmVerificationKeyPoP) -> Self { Self { @@ -54,16 +77,18 @@ impl TryInto for ProtocolSignerVerificationKey { impl ProtocolSignerVerificationKey { /// create an instance from a JSON hex representation pub fn from_json_hex(hex_string: &str) -> StdResult { - key_decode_hex(&hex_string.to_owned()) + let verification_key = key_decode_hex::(&hex_string.to_owned()) .map_err(|e| anyhow!(e)) .with_context(|| { "Could not deserialize a ProtocolSignerVerificationKey from JSON hex string." - }) + })?; + + Ok(Self { verification_key }) } /// create a JSON hash representation of the verificationkey pub fn to_json_hex(&self) -> StdResult { - key_encode_hex(self.clone()) + key_encode_hex(self.verification_key) .map_err(|e| anyhow!(e)) .with_context(|| { "Could not serialize a ProtocolSignerVerificationKey to JSON hex key string." @@ -75,3 +100,58 @@ impl ProtocolSignerVerificationKey { self.verification_key.to_bytes() } } + +#[cfg(test)] +mod test { + use super::*; + + const VERIFICATION_KEY: &str = "7b22766b223a5b3134352c32332c3135382c31322c3138332c3230392c33322c3134302c33372c3132342c3136362c3231352c3136302c3231352c3235302c3133342c3135342c3235302c3234312c3230362c3139342c3232322c382c35392c33332c392c35382c322c3235312c31302c33322c3135352c3232372c3134332c3232362c35372c3135312c37342c3139392c3131372c37352c3136382c3134302c34362c3233392c3134352c37322c31362c32312c3138312c3139332c3134362c38362c3231332c3230342c3139332c3232332c32352c3135372c33342c33332c3232372c35312c3132362c3132362c3135362c36342c3232302c3139392c3231332c31362c34352c3131302c3234332c33352c3134382c37312c3231382c3132342c3132332c31362c3132312c3135322c31382c32362c3231322c3231342c3230312c3139302c3137342c3131352c39372c3234392c3235342c3131362c3234335d2c22706f70223a5b3138332c3134352c3133392c3234322c3132302c3136302c35362c3131382c3234322c3230342c39312c38392c32312c3138342c382c34372c3231332c3130352c36332c3135302c32312c3231372c352c382c3231392c3138382c3131342c3230352c3136362c31362c3234302c3234302c3231342c31362c3230342c3231382c3139332c3138312c32342c35362c34352c39392c3234342c38312c32352c35322c3232342c36372c3136382c3136392c3130392c3132322c38372c34392c3137302c3138312c3135312c31352c3235322c3139352c3231312c3233342c3139352c34392c39312c31392c35312c3234312c33332c35382c3134302c3235322c3234322c362c342c34302c32312c3136372c3234392c3235312c33362c38372c36302c39362c36392c3135322c3231302c39382c3136352c352c362c34312c39362c3233352c37352c3138335d7d"; + + #[derive(Debug, Clone, Serialize, Deserialize, PartialEq, Eq)] + struct Container { + key: ProtocolSignerVerificationKey, + } + + #[test] + fn serializing_directly_does_not_change_the_string() { + let key: ProtocolSignerVerificationKey = VERIFICATION_KEY.try_into().unwrap(); + let serialized = serde_json::to_string(&key).expect("Serialization should not fail"); + + // Note: in json strings are enclosed in quotes + assert_eq!(format!("\"{VERIFICATION_KEY}\""), serialized); + } + + #[test] + fn serialize_deserialize_are_the_same_object() { + let container = Container { + key: VERIFICATION_KEY.try_into().unwrap(), + }; + let serialized = serde_json::to_string(&container).expect("Serialization should not fail"); + let deserialized: Container = serde_json::from_str(&serialized).unwrap(); + + assert_eq!(container, deserialized); + } + + #[test] + fn can_serialize_a_struct_containing_a_verification_key() { + let container = Container { + key: VERIFICATION_KEY.try_into().unwrap(), + }; + let expected = format!(r#"{{"key":"{VERIFICATION_KEY}"}}"#); + + let serialized = serde_json::to_string(&container).expect("Serialization should not fail"); + assert_eq!(expected, serialized); + } + + #[test] + fn can_deserialize_a_struct_containing_a_verification_key() { + let expected = Container { + key: VERIFICATION_KEY.try_into().unwrap(), + }; + let serialized = format!(r#"{{"key":"{VERIFICATION_KEY}"}}"#); + + let deserialized: Container = + serde_json::from_str(&serialized).expect("Deserialization should not fail"); + assert_eq!(expected, deserialized); + } +} diff --git a/mithril-common/src/messages/certificate_metadata.rs b/mithril-common/src/messages/certificate_metadata.rs index 23b8636b433..527bfbc19f0 100644 --- a/mithril-common/src/messages/certificate_metadata.rs +++ b/mithril-common/src/messages/certificate_metadata.rs @@ -48,24 +48,22 @@ impl CertificateMetadataMessage { initiated_at, sealed_at: initiated_at + Duration::seconds(100), signers: vec![ - SignerWithStakeMessagePart -{ - party_id: "1".to_string(), - verification_key: "7b22766b223a5b3134332c3136312c3235352c34382c37382c35372c3230342c3232302c32352c3232312c3136342c3235322c3234382c31342c35362c3132362c3138362c3133352c3232382c3138382c3134352c3138312c35322c3230302c39372c39392c3231332c34362c302c3139392c3139332c38392c3138372c38382c32392c3133352c3137332c3234342c38362c33362c38332c35342c36372c3136342c362c3133372c39342c37322c362c3130352c3132382c3132382c39332c34382c3137362c31312c342c3234362c3133382c34382c3138302c3133332c39302c3134322c3139322c32342c3139332c3131312c3134322c33312c37362c3131312c3131302c3233342c3135332c39302c3230382c3139322c33312c3132342c39352c3130322c34392c3135382c39392c35322c3232302c3136352c39342c3235312c36382c36392c3132312c31362c3232342c3139345d2c22706f70223a5b3136382c35302c3233332c3139332c31352c3133362c36352c37322c3132332c3134382c3132392c3137362c33382c3139382c3230392c34372c32382c3230342c3137362c3134342c35372c3235312c34322c32382c36362c37362c38392c39372c3135382c36332c35342c3139382c3139342c3137362c3133352c3232312c31342c3138352c3139372c3232352c3230322c39382c3234332c37342c3233332c3232352c3134332c3135312c3134372c3137372c3137302c3131372c36362c3136352c36362c36322c33332c3231362c3233322c37352c36382c3131342c3139352c32322c3130302c36352c34342c3139382c342c3136362c3130322c3233332c3235332c3234302c35392c3137352c36302c3131372c3134322c3131342c3134302c3132322c31372c38372c3131302c3138372c312c31372c31302c3139352c3135342c31332c3234392c38362c35342c3232365d7d".to_string(), - verification_key_signature: None, - operational_certificate: None, - kes_period: None, - stake: 10 -}, - SignerWithStakeMessagePart -{ - party_id: "2".to_string(), - verification_key: "7b22766b223a5b3134352c35362c3137352c33322c3132322c3138372c3231342c3232362c3235312c3134382c38382c392c312c3130332c3135392c3134362c38302c3136362c3130372c3234332c3235312c3233362c34312c32382c3131312c3132382c3230372c3136342c3133322c3134372c3232382c38332c3234362c3232382c3137302c36382c38392c37382c36302c32382c3132332c3133302c38382c3233342c33382c39372c34322c36352c312c3130302c35332c31382c37382c3133312c382c36312c3132322c3133312c3233382c38342c3233332c3232332c3135342c3131382c3131382c37332c32382c32372c3130312c37382c38302c3233332c3132332c3230362c3232302c3137342c3133342c3230352c37312c3131302c3131322c3138302c39372c39382c302c3131332c36392c3134352c3233312c3136382c34332c3137332c3137322c35362c3130342c3230385d2c22706f70223a5b3133372c3231342c37352c37352c3134342c3136312c3133372c37392c39342c3134302c3138312c34372c33312c38312c3231332c33312c3137312c3231362c32342c3137342c37382c3234382c3133302c37352c3235352c31312c3134352c3132342c36312c38302c3139302c32372c3231362c3130352c3130362c3234382c39312c3134332c3230342c3130322c3230332c3136322c37362c3130372c31352c35322c36312c38322c3134362c3133302c3132342c37342c382c33342c3136342c3138372c3230332c38322c36342c3130382c3139312c3138352c3138382c37372c3132322c352c3234362c3235352c3130322c3131392c3234372c3139392c3131372c36372c3234312c3134332c32392c3136382c36372c39342c3135312c37382c3132392c3133312c33302c3130312c3137332c31302c36392c36382c3137352c39382c33372c3233392c3139342c32395d7d".to_string(), - verification_key_signature: None, - operational_certificate: None, - kes_period: None, - stake: 20 -}, + SignerWithStakeMessagePart { + party_id: "1".to_string(), + verification_key: "7b22766b223a5b3134332c3136312c3235352c34382c37382c35372c3230342c3232302c32352c3232312c3136342c3235322c3234382c31342c35362c3132362c3138362c3133352c3232382c3138382c3134352c3138312c35322c3230302c39372c39392c3231332c34362c302c3139392c3139332c38392c3138372c38382c32392c3133352c3137332c3234342c38362c33362c38332c35342c36372c3136342c362c3133372c39342c37322c362c3130352c3132382c3132382c39332c34382c3137362c31312c342c3234362c3133382c34382c3138302c3133332c39302c3134322c3139322c32342c3139332c3131312c3134322c33312c37362c3131312c3131302c3233342c3135332c39302c3230382c3139322c33312c3132342c39352c3130322c34392c3135382c39392c35322c3232302c3136352c39342c3235312c36382c36392c3132312c31362c3232342c3139345d2c22706f70223a5b3136382c35302c3233332c3139332c31352c3133362c36352c37322c3132332c3134382c3132392c3137362c33382c3139382c3230392c34372c32382c3230342c3137362c3134342c35372c3235312c34322c32382c36362c37362c38392c39372c3135382c36332c35342c3139382c3139342c3137362c3133352c3232312c31342c3138352c3139372c3232352c3230322c39382c3234332c37342c3233332c3232352c3134332c3135312c3134372c3137372c3137302c3131372c36362c3136352c36362c36322c33332c3231362c3233322c37352c36382c3131342c3139352c32322c3130302c36352c34342c3139382c342c3136362c3130322c3233332c3235332c3234302c35392c3137352c36302c3131372c3134322c3131342c3134302c3132322c31372c38372c3131302c3138372c312c31372c31302c3139352c3135342c31332c3234392c38362c35342c3232365d7d".to_string(), + verification_key_signature: None, + operational_certificate: None, + kes_period: None, + stake: 10, + }, + SignerWithStakeMessagePart { + party_id: "2".to_string(), + verification_key: "7b22766b223a5b3134352c35362c3137352c33322c3132322c3138372c3231342c3232362c3235312c3134382c38382c392c312c3130332c3135392c3134362c38302c3136362c3130372c3234332c3235312c3233362c34312c32382c3131312c3132382c3230372c3136342c3133322c3134372c3232382c38332c3234362c3232382c3137302c36382c38392c37382c36302c32382c3132332c3133302c38382c3233342c33382c39372c34322c36352c312c3130302c35332c31382c37382c3133312c382c36312c3132322c3133312c3233382c38342c3233332c3232332c3135342c3131382c3131382c37332c32382c32372c3130312c37382c38302c3233332c3132332c3230362c3232302c3137342c3133342c3230352c37312c3131302c3131322c3138302c39372c39382c302c3131332c36392c3134352c3233312c3136382c34332c3137332c3137322c35362c3130342c3230385d2c22706f70223a5b3133372c3231342c37352c37352c3134342c3136312c3133372c37392c39342c3134302c3138312c34372c33312c38312c3231332c33312c3137312c3231362c32342c3137342c37382c3234382c3133302c37352c3235352c31312c3134352c3132342c36312c38302c3139302c32372c3231362c3130352c3130362c3234382c39312c3134332c3230342c3130322c3230332c3136322c37362c3130372c31352c35322c36312c38322c3134362c3133302c3132342c37342c382c33342c3136342c3138372c3230332c38322c36342c3130382c3139312c3138352c3138382c37372c3132322c352c3234362c3235352c3130322c3131392c3234372c3139392c3131372c36372c3234312c3134332c32392c3136382c36372c39342c3135312c37382c3132392c3133312c33302c3130312c3137332c31302c36392c36382c3137352c39382c33372c3233392c3139342c32395d7d".to_string(), + verification_key_signature: None, + operational_certificate: None, + kes_period: None, + stake: 20, + }, ], } } @@ -86,24 +84,22 @@ mod tests { .unwrap() .with_timezone(&Utc), signers: vec![ - SignerWithStakeMessagePart -{ - party_id: "1".to_string(), - verification_key: "7b22766b223a5b3134332c3136312c3235352c34382c37382c35372c3230342c3232302c32352c3232312c3136342c3235322c3234382c31342c35362c3132362c3138362c3133352c3232382c3138382c3134352c3138312c35322c3230302c39372c39392c3231332c34362c302c3139392c3139332c38392c3138372c38382c32392c3133352c3137332c3234342c38362c33362c38332c35342c36372c3136342c362c3133372c39342c37322c362c3130352c3132382c3132382c39332c34382c3137362c31312c342c3234362c3133382c34382c3138302c3133332c39302c3134322c3139322c32342c3139332c3131312c3134322c33312c37362c3131312c3131302c3233342c3135332c39302c3230382c3139322c33312c3132342c39352c3130322c34392c3135382c39392c35322c3232302c3136352c39342c3235312c36382c36392c3132312c31362c3232342c3139345d2c22706f70223a5b3136382c35302c3233332c3139332c31352c3133362c36352c37322c3132332c3134382c3132392c3137362c33382c3139382c3230392c34372c32382c3230342c3137362c3134342c35372c3235312c34322c32382c36362c37362c38392c39372c3135382c36332c35342c3139382c3139342c3137362c3133352c3232312c31342c3138352c3139372c3232352c3230322c39382c3234332c37342c3233332c3232352c3134332c3135312c3134372c3137372c3137302c3131372c36362c3136352c36362c36322c33332c3231362c3233322c37352c36382c3131342c3139352c32322c3130302c36352c34342c3139382c342c3136362c3130322c3233332c3235332c3234302c35392c3137352c36302c3131372c3134322c3131342c3134302c3132322c31372c38372c3131302c3138372c312c31372c31302c3139352c3135342c31332c3234392c38362c35342c3232365d7d".to_string(), - verification_key_signature: None, - operational_certificate: None, - kes_period: None, - stake: 10 -}, - SignerWithStakeMessagePart -{ - party_id: "2".to_string(), - verification_key: "7b22766b223a5b3134352c35362c3137352c33322c3132322c3138372c3231342c3232362c3235312c3134382c38382c392c312c3130332c3135392c3134362c38302c3136362c3130372c3234332c3235312c3233362c34312c32382c3131312c3132382c3230372c3136342c3133322c3134372c3232382c38332c3234362c3232382c3137302c36382c38392c37382c36302c32382c3132332c3133302c38382c3233342c33382c39372c34322c36352c312c3130302c35332c31382c37382c3133312c382c36312c3132322c3133312c3233382c38342c3233332c3232332c3135342c3131382c3131382c37332c32382c32372c3130312c37382c38302c3233332c3132332c3230362c3232302c3137342c3133342c3230352c37312c3131302c3131322c3138302c39372c39382c302c3131332c36392c3134352c3233312c3136382c34332c3137332c3137322c35362c3130342c3230385d2c22706f70223a5b3133372c3231342c37352c37352c3134342c3136312c3133372c37392c39342c3134302c3138312c34372c33312c38312c3231332c33312c3137312c3231362c32342c3137342c37382c3234382c3133302c37352c3235352c31312c3134352c3132342c36312c38302c3139302c32372c3231362c3130352c3130362c3234382c39312c3134332c3230342c3130322c3230332c3136322c37362c3130372c31352c35322c36312c38322c3134362c3133302c3132342c37342c382c33342c3136342c3138372c3230332c38322c36342c3130382c3139312c3138352c3138382c37372c3132322c352c3234362c3235352c3130322c3131392c3234372c3139392c3131372c36372c3234312c3134332c32392c3136382c36372c39342c3135312c37382c3132392c3133312c33302c3130312c3137332c31302c36392c36382c3137352c39382c33372c3233392c3139342c32395d7d".to_string(), - verification_key_signature: None, - operational_certificate: None, - kes_period: None, - stake: 20 -}, + SignerWithStakeMessagePart { + party_id: "1".to_string(), + verification_key: "7b22766b223a5b3134332c3136312c3235352c34382c37382c35372c3230342c3232302c32352c3232312c3136342c3235322c3234382c31342c35362c3132362c3138362c3133352c3232382c3138382c3134352c3138312c35322c3230302c39372c39392c3231332c34362c302c3139392c3139332c38392c3138372c38382c32392c3133352c3137332c3234342c38362c33362c38332c35342c36372c3136342c362c3133372c39342c37322c362c3130352c3132382c3132382c39332c34382c3137362c31312c342c3234362c3133382c34382c3138302c3133332c39302c3134322c3139322c32342c3139332c3131312c3134322c33312c37362c3131312c3131302c3233342c3135332c39302c3230382c3139322c33312c3132342c39352c3130322c34392c3135382c39392c35322c3232302c3136352c39342c3235312c36382c36392c3132312c31362c3232342c3139345d2c22706f70223a5b3136382c35302c3233332c3139332c31352c3133362c36352c37322c3132332c3134382c3132392c3137362c33382c3139382c3230392c34372c32382c3230342c3137362c3134342c35372c3235312c34322c32382c36362c37362c38392c39372c3135382c36332c35342c3139382c3139342c3137362c3133352c3232312c31342c3138352c3139372c3232352c3230322c39382c3234332c37342c3233332c3232352c3134332c3135312c3134372c3137372c3137302c3131372c36362c3136352c36362c36322c33332c3231362c3233322c37352c36382c3131342c3139352c32322c3130302c36352c34342c3139382c342c3136362c3130322c3233332c3235332c3234302c35392c3137352c36302c3131372c3134322c3131342c3134302c3132322c31372c38372c3131302c3138372c312c31372c31302c3139352c3135342c31332c3234392c38362c35342c3232365d7d".to_string(), + verification_key_signature: None, + operational_certificate: None, + kes_period: None, + stake: 10, + }, + SignerWithStakeMessagePart { + party_id: "2".to_string(), + verification_key: "7b22766b223a5b3134352c35362c3137352c33322c3132322c3138372c3231342c3232362c3235312c3134382c38382c392c312c3130332c3135392c3134362c38302c3136362c3130372c3234332c3235312c3233362c34312c32382c3131312c3132382c3230372c3136342c3133322c3134372c3232382c38332c3234362c3232382c3137302c36382c38392c37382c36302c32382c3132332c3133302c38382c3233342c33382c39372c34322c36352c312c3130302c35332c31382c37382c3133312c382c36312c3132322c3133312c3233382c38342c3233332c3232332c3135342c3131382c3131382c37332c32382c32372c3130312c37382c38302c3233332c3132332c3230362c3232302c3137342c3133342c3230352c37312c3131302c3131322c3138302c39372c39382c302c3131332c36392c3134352c3233312c3136382c34332c3137332c3137322c35362c3130342c3230385d2c22706f70223a5b3133372c3231342c37352c37352c3134342c3136312c3133372c37392c39342c3134302c3138312c34372c33312c38312c3231332c33312c3137312c3231362c32342c3137342c37382c3234382c3133302c37352c3235352c31312c3134352c3132342c36312c38302c3139302c32372c3231362c3130352c3130362c3234382c39312c3134332c3230342c3130322c3230332c3136322c37362c3130372c31352c35322c36312c38322c3134362c3133302c3132342c37342c382c33342c3136342c3138372c3230332c38322c36342c3130382c3139312c3138352c3138382c37372c3132322c352c3234362c3235352c3130322c3131392c3234372c3139392c3131372c36372c3234312c3134332c32392c3136382c36372c39342c3135312c37382c3132392c3133312c33302c3130312c3137332c31302c36392c36382c3137352c39382c33372c3233392c3139342c32395d7d".to_string(), + verification_key_signature: None, + operational_certificate: None, + kes_period: None, + stake: 20, + }, ], } } diff --git a/mithril-common/src/messages/mithril_stake_distribution.rs b/mithril-common/src/messages/mithril_stake_distribution.rs index 4b41586b80b..ecc170e46fb 100644 --- a/mithril-common/src/messages/mithril_stake_distribution.rs +++ b/mithril-common/src/messages/mithril_stake_distribution.rs @@ -48,20 +48,21 @@ impl MithrilStakeDistributionMessage { #[cfg(test)] mod tests { - use super::*; fn golden_message() -> MithrilStakeDistributionMessage { MithrilStakeDistributionMessage { epoch: Epoch(1), - signers_with_stake: vec![SignerWithStakeMessagePart { - party_id: "0".to_string(), - verification_key: "7b22766b223a5b3134332c3136312c3235352c34382c37382c35372c3230342c3232302c32352c3232312c3136342c3235322c3234382c31342c35362c3132362c3138362c3133352c3232382c3138382c3134352c3138312c35322c3230302c39372c39392c3231332c34362c302c3139392c3139332c38392c3138372c38382c32392c3133352c3137332c3234342c38362c33362c38332c35342c36372c3136342c362c3133372c39342c37322c362c3130352c3132382c3132382c39332c34382c3137362c31312c342c3234362c3133382c34382c3138302c3133332c39302c3134322c3139322c32342c3139332c3131312c3134322c33312c37362c3131312c3131302c3233342c3135332c39302c3230382c3139322c33312c3132342c39352c3130322c34392c3135382c39392c35322c3232302c3136352c39342c3235312c36382c36392c3132312c31362c3232342c3139345d2c22706f70223a5b3136382c35302c3233332c3139332c31352c3133362c36352c37322c3132332c3134382c3132392c3137362c33382c3139382c3230392c34372c32382c3230342c3137362c3134342c35372c3235312c34322c32382c36362c37362c38392c39372c3135382c36332c35342c3139382c3139342c3137362c3133352c3232312c31342c3138352c3139372c3232352c3230322c39382c3234332c37342c3233332c3232352c3134332c3135312c3134372c3137372c3137302c3131372c36362c3136352c36362c36322c33332c3231362c3233322c37352c36382c3131342c3139352c32322c3130302c36352c34342c3139382c342c3136362c3130322c3233332c3235332c3234302c35392c3137352c36302c3131372c3134322c3131342c3134302c3132322c31372c38372c3131302c3138372c312c31372c31302c3139352c3135342c31332c3234392c38362c35342c3232365d7d".to_string(), - verification_key_signature: None, - operational_certificate: None, - kes_period: None, - stake: 826 - }], + signers_with_stake: vec![ + SignerWithStakeMessagePart { + party_id: "0".to_string(), + verification_key: "7b22766b223a5b3134332c3136312c3235352c34382c37382c35372c3230342c3232302c32352c3232312c3136342c3235322c3234382c31342c35362c3132362c3138362c3133352c3232382c3138382c3134352c3138312c35322c3230302c39372c39392c3231332c34362c302c3139392c3139332c38392c3138372c38382c32392c3133352c3137332c3234342c38362c33362c38332c35342c36372c3136342c362c3133372c39342c37322c362c3130352c3132382c3132382c39332c34382c3137362c31312c342c3234362c3133382c34382c3138302c3133332c39302c3134322c3139322c32342c3139332c3131312c3134322c33312c37362c3131312c3131302c3233342c3135332c39302c3230382c3139322c33312c3132342c39352c3130322c34392c3135382c39392c35322c3232302c3136352c39342c3235312c36382c36392c3132312c31362c3232342c3139345d2c22706f70223a5b3136382c35302c3233332c3139332c31352c3133362c36352c37322c3132332c3134382c3132392c3137362c33382c3139382c3230392c34372c32382c3230342c3137362c3134342c35372c3235312c34322c32382c36362c37362c38392c39372c3135382c36332c35342c3139382c3139342c3137362c3133352c3232312c31342c3138352c3139372c3232352c3230322c39382c3234332c37342c3233332c3232352c3134332c3135312c3134372c3137372c3137302c3131372c36362c3136352c36362c36322c33332c3231362c3233322c37352c36382c3131342c3139352c32322c3130302c36352c34342c3139382c342c3136362c3130322c3233332c3235332c3234302c35392c3137352c36302c3131372c3134322c3131342c3134302c3132322c31372c38372c3131302c3138372c312c31372c31302c3139352c3135342c31332c3234392c38362c35342c3232365d7d".to_string(), + verification_key_signature: None, + operational_certificate: None, + kes_period: None, + stake: 826 + }, + ], hash: "hash-123".to_string(), certificate_hash: "cert-hash-123".to_string(), created_at: DateTime::from_str("2023-06-13T17:05:41Z").unwrap(),