lighthouse-pulse/tests/ef_tests/src/cases/bls_aggregate_pubkeys.rs

40 lines
1.2 KiB
Rust
Raw Normal View History

2019-05-21 00:32:14 +00:00
use super::*;
use crate::case_result::compare_result;
use bls::{AggregatePublicKey, PublicKey};
use serde_derive::Deserialize;
#[derive(Debug, Clone, Deserialize)]
pub struct BlsAggregatePubkeys {
pub input: Vec<String>,
pub output: String,
}
impl YamlDecode for BlsAggregatePubkeys {
fn yaml_decode(yaml: &str) -> Result<Self, Error> {
Ok(serde_yaml::from_str(yaml).unwrap())
2019-05-21 00:32:14 +00:00
}
}
impl Case for BlsAggregatePubkeys {
2019-05-22 08:13:22 +00:00
fn result(&self, _case_index: usize) -> Result<(), Error> {
let mut aggregate_pubkey = AggregatePublicKey::new();
2019-05-21 00:32:14 +00:00
for key_str in &self.input {
let key = hex::decode(&key_str[2..])
.map_err(|e| Error::FailedToParseTest(format!("{:?}", e)))?;
let key = PublicKey::from_bytes(&key)
.map_err(|e| Error::FailedToParseTest(format!("{:?}", e)))?;
2019-05-21 00:32:14 +00:00
aggregate_pubkey.add(&key);
}
2019-05-21 00:32:14 +00:00
let output_bytes = Some(
hex::decode(&self.output[2..])
.map_err(|e| Error::FailedToParseTest(format!("{:?}", e)))?,
);
let aggregate_pubkey = Ok(aggregate_pubkey.as_raw().as_bytes());
2019-05-21 00:32:14 +00:00
compare_result::<Vec<u8>, Vec<u8>>(&aggregate_pubkey, &output_bytes)
2019-05-21 00:32:14 +00:00
}
}