Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #949 from input-output-hk/jpraynaud/892-add-certif…
…icate-list-route Add Certificate list route to aggregator REST API
- Loading branch information
Showing
11 changed files
with
542 additions
and
19 deletions.
There are no files selected for viewing
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
63 changes: 63 additions & 0 deletions
63
mithril-aggregator/src/message_adapters/to_certificate_list_message.rs
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,63 @@ | ||
use mithril_common::entities::Certificate; | ||
use mithril_common::messages::{ | ||
CertificateListItemMessage, CertificateListItemMessageMetadata, CertificateListMessage, | ||
}; | ||
|
||
/// Adapter to convert a list of [Certificate] to [CertificateListMessage] instances | ||
pub struct ToCertificateListMessageAdapter; | ||
|
||
impl ToCertificateListMessageAdapter { | ||
/// Method to trigger the conversion | ||
pub fn adapt(certificates: Vec<Certificate>) -> CertificateListMessage { | ||
certificates | ||
.into_iter() | ||
.map(|certificate| CertificateListItemMessage { | ||
hash: certificate.hash, | ||
previous_hash: certificate.previous_hash, | ||
beacon: certificate.beacon, | ||
metadata: CertificateListItemMessageMetadata { | ||
protocol_version: certificate.metadata.protocol_version, | ||
protocol_parameters: certificate.metadata.protocol_parameters, | ||
initiated_at: certificate.metadata.initiated_at, | ||
sealed_at: certificate.metadata.sealed_at, | ||
total_signers: certificate.metadata.signers.len(), | ||
}, | ||
protocol_message: certificate.protocol_message, | ||
signed_message: certificate.signed_message, | ||
aggregate_verification_key: certificate.aggregate_verification_key, | ||
}) | ||
.collect() | ||
} | ||
} | ||
|
||
#[cfg(test)] | ||
mod tests { | ||
use mithril_common::test_utils::fake_data; | ||
|
||
use super::*; | ||
|
||
#[test] | ||
fn adapt_ok() { | ||
let certificate = fake_data::certificate("hash123".to_string()); | ||
|
||
let certificate_list_message = | ||
ToCertificateListMessageAdapter::adapt(vec![certificate.clone()]); | ||
let certificate_list_message_expected = vec![CertificateListItemMessage { | ||
hash: certificate.hash, | ||
previous_hash: certificate.previous_hash, | ||
beacon: certificate.beacon, | ||
metadata: CertificateListItemMessageMetadata { | ||
protocol_version: certificate.metadata.protocol_version, | ||
protocol_parameters: certificate.metadata.protocol_parameters, | ||
initiated_at: certificate.metadata.initiated_at, | ||
sealed_at: certificate.metadata.sealed_at, | ||
total_signers: certificate.metadata.signers.len(), | ||
}, | ||
protocol_message: certificate.protocol_message, | ||
signed_message: certificate.signed_message, | ||
aggregate_verification_key: certificate.aggregate_verification_key, | ||
}]; | ||
|
||
assert_eq!(certificate_list_message_expected, certificate_list_message); | ||
} | ||
} |
Oops, something went wrong.