Fix EF test runners for v0.12

This commit is contained in:
Michael Sproul
2020-05-27 15:26:49 +10:00
parent 8040b001f1
commit c4340af056
3 changed files with 31 additions and 26 deletions

View File

@@ -25,12 +25,17 @@ impl Case for BlsAggregateSigs {
aggregate_signature.add(&sig); aggregate_signature.add(&sig);
} }
let output_bytes = Some( // Check for YAML null value, indicating invalid input. This is a bit of a hack,
// as our mutating `aggregate_signature.add` API doesn't play nicely with aggregating 0
// inputs.
let output_bytes = if self.output == "~" {
AggregateSignature::new().as_bytes().to_vec()
} else {
hex::decode(&self.output[2..]) hex::decode(&self.output[2..])
.map_err(|e| Error::FailedToParseTest(format!("{:?}", e)))?, .map_err(|e| Error::FailedToParseTest(format!("{:?}", e)))?
); };
let aggregate_signature = Ok(aggregate_signature.as_bytes().to_vec()); let aggregate_signature = Ok(aggregate_signature.as_bytes().to_vec());
compare_result::<Vec<u8>, Vec<u8>>(&aggregate_signature, &output_bytes) compare_result::<Vec<u8>, Vec<u8>>(&aggregate_signature, &Some(output_bytes))
} }
} }

View File

@@ -4,15 +4,10 @@ use crate::cases::common::BlsCase;
use bls::{AggregateSignature, PublicKey}; use bls::{AggregateSignature, PublicKey};
use serde_derive::Deserialize; use serde_derive::Deserialize;
#[derive(Debug, Clone, Deserialize)]
pub struct BlsAggregatePair {
pub pubkey: PublicKey,
pub message: String,
}
#[derive(Debug, Clone, Deserialize)] #[derive(Debug, Clone, Deserialize)]
pub struct BlsAggregateVerifyInput { pub struct BlsAggregateVerifyInput {
pub pairs: Vec<BlsAggregatePair>, pub pubkeys: Vec<PublicKey>,
pub messages: Vec<String>,
pub signature: String, pub signature: String,
} }
@@ -28,11 +23,10 @@ impl Case for BlsAggregateVerify {
fn result(&self, _case_index: usize) -> Result<(), Error> { fn result(&self, _case_index: usize) -> Result<(), Error> {
let messages = self let messages = self
.input .input
.pairs .messages
.iter() .iter()
.map(|pair| { .map(|message| {
hex::decode(&pair.message[2..]) hex::decode(&message[2..]).map_err(|e| Error::FailedToParseTest(format!("{:?}", e)))
.map_err(|e| Error::FailedToParseTest(format!("{:?}", e)))
}) })
.collect::<Result<Vec<Vec<_>>, _>>()?; .collect::<Result<Vec<Vec<_>>, _>>()?;
@@ -41,12 +35,7 @@ impl Case for BlsAggregateVerify {
.map(|x| x.as_slice()) .map(|x| x.as_slice())
.collect::<Vec<&[u8]>>(); .collect::<Vec<&[u8]>>();
let pubkey_refs = self let pubkey_refs = self.input.pubkeys.iter().collect::<Vec<_>>();
.input
.pairs
.iter()
.map(|p| &p.pubkey)
.collect::<Vec<_>>();
let signature_ok = hex::decode(&self.input.signature[2..]) let signature_ok = hex::decode(&self.input.signature[2..])
.ok() .ok()

View File

@@ -27,7 +27,7 @@ struct Metadata {
pub struct Operations<E: EthSpec, O: Operation<E>> { pub struct Operations<E: EthSpec, O: Operation<E>> {
metadata: Metadata, metadata: Metadata,
pub pre: BeaconState<E>, pub pre: BeaconState<E>,
pub operation: O, pub operation: Option<O>,
pub post: Option<BeaconState<E>>, pub post: Option<BeaconState<E>>,
} }
@@ -135,8 +135,16 @@ impl<E: EthSpec, O: Operation<E>> LoadCase for Operations<E, O> {
} else { } else {
Metadata::default() Metadata::default()
}; };
let pre = ssz_decode_file(&path.join("pre.ssz"))?; let pre = ssz_decode_file(&path.join("pre.ssz"))?;
let operation = ssz_decode_file(&path.join(O::filename()))?;
// Check BLS setting here before SSZ deserialization, as most types require signatures
// to be valid.
let operation = if metadata.bls_setting.unwrap_or_default().check().is_ok() {
Some(ssz_decode_file(&path.join(O::filename()))?)
} else {
None
};
let post_filename = path.join("post.ssz"); let post_filename = path.join("post.ssz");
let post = if post_filename.is_file() { let post = if post_filename.is_file() {
Some(ssz_decode_file(&post_filename)?) Some(ssz_decode_file(&post_filename)?)
@@ -162,8 +170,6 @@ impl<E: EthSpec, O: Operation<E>> Case for Operations<E, O> {
} }
fn result(&self, _case_index: usize) -> Result<(), Error> { fn result(&self, _case_index: usize) -> Result<(), Error> {
self.metadata.bls_setting.unwrap_or_default().check()?;
let spec = &E::default_spec(); let spec = &E::default_spec();
let mut state = self.pre.clone(); let mut state = self.pre.clone();
let mut expected = self.post.clone(); let mut expected = self.post.clone();
@@ -173,7 +179,12 @@ impl<E: EthSpec, O: Operation<E>> Case for Operations<E, O> {
.build_all_committee_caches(spec) .build_all_committee_caches(spec)
.expect("committee caches OK"); .expect("committee caches OK");
let mut result = self.operation.apply_to(&mut state, spec).map(|()| state); let mut result = self
.operation
.as_ref()
.ok_or(Error::SkippedBls)?
.apply_to(&mut state, spec)
.map(|()| state);
compare_beacon_state_results_without_caches(&mut result, &mut expected) compare_beacon_state_results_without_caches(&mut result, &mut expected)
} }