Add progress on ssz_static tests

This commit is contained in:
Paul Hauner 2019-05-14 16:56:00 +10:00
parent 6096abf071
commit 1835ca8fd6
No known key found for this signature in database
GPG Key ID: D362883A9218FCC6
2 changed files with 31 additions and 2 deletions

View File

@ -1,6 +1,11 @@
use super::*;
use serde::de::{Deserialize, Deserializer};
use types::Fork;
use types::{
Attestation, AttestationData, AttestationDataAndCustodyBit, AttesterSlashing, BeaconBlock,
BeaconBlockBody, BeaconBlockHeader, BeaconState, Crosslink, Deposit, DepositData, Eth1Data,
Fork, HistoricalBatch, PendingAttestation, ProposerSlashing, Transfer, Validator,
VoluntaryExit,
};
#[derive(Debug, Clone, Deserialize)]
pub struct SszStatic {
@ -44,6 +49,29 @@ impl Test for TestDocCases<SszStatic> {
.map(|(i, tc)| {
let result = match tc.type_name.as_ref() {
"Fork" => ssz_static_test::<Fork>(tc),
"Crosslink" => ssz_static_test::<Crosslink>(tc),
"Eth1Data" => ssz_static_test::<Eth1Data>(tc),
"AttestationData" => ssz_static_test::<AttestationData>(tc),
/*
"AttestationDataAndCustodyBit" => {
ssz_static_test::<AttestationDataAndCustodyBit>(tc)
}
*/
// "IndexedAttestation" => ssz_static_test::<IndexedAttestation>(tc),
"DepositData" => ssz_static_test::<DepositData>(tc),
"BeaconBlockHeader" => ssz_static_test::<BeaconBlockHeader>(tc),
"Validator" => ssz_static_test::<Validator>(tc),
"PendingAttestation" => ssz_static_test::<PendingAttestation>(tc),
// "HistoricalBatch" => ssz_static_test::<HistoricalBatch>(tc),
"ProposerSlashing" => ssz_static_test::<ProposerSlashing>(tc),
"AttesterSlashing" => ssz_static_test::<AttesterSlashing>(tc),
"Attestation" => ssz_static_test::<Attestation>(tc),
"Deposit" => ssz_static_test::<Deposit>(tc),
"VoluntaryExit" => ssz_static_test::<VoluntaryExit>(tc),
"Transfer" => ssz_static_test::<Transfer>(tc),
"BeaconBlockBody" => ssz_static_test::<BeaconBlockBody>(tc),
"BeaconBlock" => ssz_static_test::<BeaconBlock>(tc),
// "BeaconState" => ssz_static_test::<DepositData>(tc),
_ => Err(Error::FailedToParseTest(format!(
"Unknown type: {}",
tc.type_name
@ -58,7 +86,7 @@ impl Test for TestDocCases<SszStatic> {
fn ssz_static_test<T>(tc: &SszStatic) -> Result<(), Error>
where
T: Decode + TestDecode + Debug + PartialEq<T> + serde::de::DeserializeOwned,
T: Decode + Debug + PartialEq<T> + serde::de::DeserializeOwned,
{
let ssz = hex::decode(&tc.serialized[2..])
.map_err(|e| Error::FailedToParseTest(format!("{:?}", e)))?;

View File

@ -47,6 +47,7 @@ mod ssz_static {
}
#[test]
#[ignore]
fn minimal_nil() {
TestDoc::assert_tests_pass(ssz_generic_file("core/ssz_minimal_nil.yaml"));
}