mirror of
https://github.com/sigp/lighthouse.git
synced 2026-03-22 14:24:44 +00:00
Improve ef_tests, pass all ssz_static tests
This commit is contained in:
@@ -1,5 +1,7 @@
|
||||
use super::*;
|
||||
use crate::case_result::compare_result;
|
||||
use cached_tree_hash::{CachedTreeHash, TreeHashCache};
|
||||
use rayon::prelude::*;
|
||||
use serde_derive::Deserialize;
|
||||
use ssz::Decode;
|
||||
use std::fmt::Debug;
|
||||
@@ -48,7 +50,7 @@ impl SszStatic {
|
||||
impl EfTest for Cases<SszStatic> {
|
||||
fn test_results<E: EthSpec>(&self) -> Vec<CaseResult> {
|
||||
self.test_cases
|
||||
.iter()
|
||||
.par_iter()
|
||||
.enumerate()
|
||||
.map(|(i, tc)| {
|
||||
let result = match tc.type_name.as_ref() {
|
||||
@@ -88,7 +90,7 @@ impl EfTest for Cases<SszStatic> {
|
||||
|
||||
fn ssz_static_test<T>(tc: &SszStatic) -> Result<(), Error>
|
||||
where
|
||||
T: Decode + Debug + PartialEq<T> + serde::de::DeserializeOwned + TreeHash,
|
||||
T: Decode + Debug + PartialEq<T> + serde::de::DeserializeOwned + TreeHash + CachedTreeHash,
|
||||
{
|
||||
// Verify we can decode SSZ in the same way we can decode YAML.
|
||||
let ssz = hex::decode(&tc.serialized[2..])
|
||||
@@ -97,12 +99,18 @@ where
|
||||
let decode_result = T::from_ssz_bytes(&ssz);
|
||||
compare_result(&decode_result, &Some(expected))?;
|
||||
|
||||
// Verify the tree hash root is identical to the decoded struct.
|
||||
let root_bytes =
|
||||
// Verify the TreeHash root of the decoded struct matches the test.
|
||||
let decoded = decode_result.unwrap();
|
||||
let expected_root =
|
||||
&hex::decode(&tc.root[2..]).map_err(|e| Error::FailedToParseTest(format!("{:?}", e)))?;
|
||||
let expected_root = Hash256::from_slice(&root_bytes);
|
||||
let root = Hash256::from_slice(&decode_result.unwrap().tree_hash_root());
|
||||
compare_result::<Hash256, Error>(&Ok(root), &Some(expected_root))?;
|
||||
let expected_root = Hash256::from_slice(&expected_root);
|
||||
let tree_hash_root = Hash256::from_slice(&decoded.tree_hash_root());
|
||||
compare_result::<Hash256, Error>(&Ok(tree_hash_root), &Some(expected_root))?;
|
||||
|
||||
// Verify a _new_ CachedTreeHash root of the decoded struct matches the test.
|
||||
let cache = TreeHashCache::new(&decoded).unwrap();
|
||||
let cached_tree_hash_root = Hash256::from_slice(cache.tree_hash_root().unwrap());
|
||||
compare_result::<Hash256, Error>(&Ok(cached_tree_hash_root), &Some(expected_root))?;
|
||||
|
||||
Ok(())
|
||||
}
|
||||
|
||||
@@ -1,12 +1,12 @@
|
||||
use crate::case_result::CaseResult;
|
||||
use crate::cases::*;
|
||||
use crate::doc_header::DocHeader;
|
||||
use crate::eth_specs::MinimalEthSpec;
|
||||
use crate::eth_specs::{MainnetEthSpec, MinimalEthSpec};
|
||||
use crate::yaml_decode::{extract_yaml_by_key, YamlDecode};
|
||||
use crate::EfTest;
|
||||
use serde_derive::Deserialize;
|
||||
use std::{fs::File, io::prelude::*, path::PathBuf};
|
||||
use types::{EthSpec, FoundationEthSpec};
|
||||
use types::EthSpec;
|
||||
|
||||
#[derive(Debug, Deserialize)]
|
||||
pub struct Doc {
|
||||
@@ -32,8 +32,9 @@ impl Doc {
|
||||
header.handler.as_ref(),
|
||||
header.config.as_ref(),
|
||||
) {
|
||||
("ssz", "uint", _) => run_test::<SszGeneric, FoundationEthSpec>(&self.yaml),
|
||||
("ssz", "uint", _) => run_test::<SszGeneric, MainnetEthSpec>(&self.yaml),
|
||||
("ssz", "static", "minimal") => run_test::<SszStatic, MinimalEthSpec>(&self.yaml),
|
||||
("ssz", "static", "mainnet") => run_test::<SszStatic, MainnetEthSpec>(&self.yaml),
|
||||
(runner, handler, config) => panic!(
|
||||
"No implementation for runner: \"{}\", handler: \"{}\", config: \"{}\"",
|
||||
runner, handler, config
|
||||
@@ -48,6 +49,8 @@ impl Doc {
|
||||
if results.iter().any(|r| r.result.is_err()) {
|
||||
print_failures(&doc, &results);
|
||||
panic!("Tests failed (see above)");
|
||||
} else {
|
||||
println!("Passed {} tests in {:?}", results.len(), doc.path);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -1,5 +1,8 @@
|
||||
use types::{EthSpec, typenum::{U64, U8}, ChainSpec, FewValidatorsEthSpec};
|
||||
use serde_derive::{Serialize, Deserialize};
|
||||
use serde_derive::{Deserialize, Serialize};
|
||||
use types::{
|
||||
typenum::{U64, U8},
|
||||
ChainSpec, EthSpec, FewValidatorsEthSpec, FoundationEthSpec,
|
||||
};
|
||||
|
||||
/// "Minimal" testing specification, as defined here:
|
||||
///
|
||||
@@ -21,3 +24,5 @@ impl EthSpec for MinimalEthSpec {
|
||||
FewValidatorsEthSpec::spec()
|
||||
}
|
||||
}
|
||||
|
||||
pub type MainnetEthSpec = FoundationEthSpec;
|
||||
|
||||
Reference in New Issue
Block a user