Skip to content

Commit

Permalink
Update PeerDAS spec tests to 1.5.0-beta.0 and fix failing unit tests.
Browse files Browse the repository at this point in the history
  • Loading branch information
jimmygchen committed Jan 15, 2025
1 parent 056a375 commit 283f940
Show file tree
Hide file tree
Showing 6 changed files with 110 additions and 43 deletions.
26 changes: 11 additions & 15 deletions consensus/types/src/data_column_custody_group.rs
Original file line number Diff line number Diff line change
Expand Up @@ -109,15 +109,12 @@ mod test {

#[test]
fn test_compute_columns_for_custody_group() {
let number_of_custody_groups = 64;
let spec = ChainSpec {
number_of_columns: 128,
number_of_custody_groups,
..ChainSpec::mainnet()
};
let columns_per_custody_group = spec.number_of_columns / number_of_custody_groups;

for custody_group in 0..number_of_custody_groups {
let mut spec = ChainSpec::mainnet();
spec.number_of_custody_groups = 64;
spec.number_of_columns = 128;
let columns_per_custody_group = spec.number_of_columns / spec.number_of_custody_groups;

for custody_group in 0..spec.number_of_custody_groups {
let columns = compute_columns_for_custody_group(custody_group, &spec)
.unwrap()
.collect::<Vec<_>>();
Expand All @@ -127,12 +124,11 @@ mod test {

#[test]
fn test_compute_subnets_from_custody_group() {
let spec = ChainSpec {
number_of_columns: 256,
number_of_custody_groups: 64,
data_column_sidecar_subnet_count: 128,
..ChainSpec::mainnet()
};
let mut spec = ChainSpec::mainnet();
spec.number_of_custody_groups = 64;
spec.number_of_columns = 256;
spec.data_column_sidecar_subnet_count = 128;

let subnets_per_custody_group =
spec.data_column_sidecar_subnet_count / spec.number_of_custody_groups;

Expand Down
6 changes: 4 additions & 2 deletions testing/ef_tests/src/cases.rs
Original file line number Diff line number Diff line change
Expand Up @@ -13,12 +13,13 @@ mod bls_fast_aggregate_verify;
mod bls_sign_msg;
mod bls_verify_msg;
mod common;
mod compute_columns_for_custody_groups;
mod epoch_processing;
mod fork;
mod fork_choice;
mod genesis_initialization;
mod genesis_validity;
mod get_custody_columns;
mod get_custody_groups;
mod kzg_blob_to_kzg_commitment;
mod kzg_compute_blob_kzg_proof;
mod kzg_compute_cells_and_kzg_proofs;
Expand Down Expand Up @@ -49,11 +50,12 @@ pub use bls_fast_aggregate_verify::*;
pub use bls_sign_msg::*;
pub use bls_verify_msg::*;
pub use common::SszStaticType;
pub use compute_columns_for_custody_groups::*;
pub use epoch_processing::*;
pub use fork::ForkTest;
pub use genesis_initialization::*;
pub use genesis_validity::*;
pub use get_custody_columns::*;
pub use get_custody_groups::*;
pub use kzg_blob_to_kzg_commitment::*;
pub use kzg_compute_blob_kzg_proof::*;
pub use kzg_compute_cells_and_kzg_proofs::*;
Expand Down
47 changes: 47 additions & 0 deletions testing/ef_tests/src/cases/compute_columns_for_custody_groups.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,47 @@
use super::*;
use serde::Deserialize;
use std::marker::PhantomData;
use types::data_column_custody_group::{compute_columns_for_custody_group, CustodyIndex};

#[derive(Debug, Clone, Deserialize)]
#[serde(bound = "E: EthSpec", deny_unknown_fields)]
pub struct ComputeColumnsForCustodyGroups<E: EthSpec> {
/// The custody group index.
pub custody_group: CustodyIndex,
/// The list of resulting custody columns.
pub result: Vec<u64>,
#[serde(skip)]
_phantom: PhantomData<E>,
}

impl<E: EthSpec> LoadCase for ComputeColumnsForCustodyGroups<E> {
fn load_from_dir(path: &Path, _fork_name: ForkName) -> Result<Self, Error> {
decode::yaml_decode_file(path.join("meta.yaml").as_path())
}
}

impl<E: EthSpec> Case for ComputeColumnsForCustodyGroups<E> {
fn is_enabled_for_fork(_fork_name: ForkName) -> bool {
false
}

fn is_enabled_for_feature(feature_name: FeatureName) -> bool {
feature_name == FeatureName::Fulu
}

fn result(&self, _case_index: usize, _fork_name: ForkName) -> Result<(), Error> {
let spec = E::default_spec();
let computed_columns = compute_columns_for_custody_group(self.custody_group, &spec)
.expect("should compute custody columns from group")
.collect::<Vec<_>>();

let expected = &self.result;
if computed_columns == *expected {
Ok(())
} else {
Err(Error::NotEqual(format!(
"Got {computed_columns:?}\nExpected {expected:?}"
)))
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -2,28 +2,28 @@ use super::*;
use alloy_primitives::U256;
use serde::Deserialize;
use std::marker::PhantomData;
use types::data_column_custody_group::{compute_columns_for_custody_group, get_custody_groups};
use types::data_column_custody_group::get_custody_groups;

#[derive(Debug, Clone, Deserialize)]
#[serde(bound = "E: EthSpec", deny_unknown_fields)]
pub struct GetCustodyColumns<E: EthSpec> {
pub struct GetCustodyGroups<E: EthSpec> {
/// The NodeID input.
pub node_id: String,
/// The count of custody groups.
pub custody_group_count: u64,
/// The list of resulting custody columns.
/// The list of resulting custody groups.
pub result: Vec<u64>,
#[serde(skip)]
_phantom: PhantomData<E>,
}

impl<E: EthSpec> LoadCase for GetCustodyColumns<E> {
impl<E: EthSpec> LoadCase for GetCustodyGroups<E> {
fn load_from_dir(path: &Path, _fork_name: ForkName) -> Result<Self, Error> {
decode::yaml_decode_file(path.join("meta.yaml").as_path())
}
}

impl<E: EthSpec> Case for GetCustodyColumns<E> {
impl<E: EthSpec> Case for GetCustodyGroups<E> {
fn is_enabled_for_fork(_fork_name: ForkName) -> bool {
false
}
Expand All @@ -37,25 +37,17 @@ impl<E: EthSpec> Case for GetCustodyColumns<E> {
let node_id = U256::from_str_radix(&self.node_id, 10)
.map_err(|e| Error::FailedToParseTest(format!("{e:?}")))?;
let raw_node_id = node_id.to_be_bytes::<32>();
let computed_groups = get_custody_groups(raw_node_id, self.custody_group_count, &spec)
let mut computed = get_custody_groups(raw_node_id, self.custody_group_count, &spec)
.map(|set| set.into_iter().collect::<Vec<_>>())
.expect("should compute custody groups");

let mut computed_columns = vec![];
for custody_group in computed_groups {
let columns = compute_columns_for_custody_group(custody_group, &spec)
.expect("should compute custody columns from group");
computed_columns.extend(columns);
}
// TODO: This test will be broken down into two separate tests in the next release and this
// sort will not be needed.
computed_columns.sort();
computed.sort();

let expected = &self.result;
if computed_columns == *expected {
if computed == *expected {
Ok(())
} else {
Err(Error::NotEqual(format!(
"Got {computed_columns:?}\nExpected {expected:?}"
"Got {computed:?}\nExpected {expected:?}"
)))
}
}
Expand Down
28 changes: 24 additions & 4 deletions testing/ef_tests/src/handler.rs
Original file line number Diff line number Diff line change
Expand Up @@ -874,10 +874,10 @@ impl<E: EthSpec> Handler for KZGVerifyKZGProofHandler<E> {

#[derive(Derivative)]
#[derivative(Default(bound = ""))]
pub struct GetCustodyColumnsHandler<E>(PhantomData<E>);
pub struct GetCustodyGroupsHandler<E>(PhantomData<E>);

impl<E: EthSpec + TypeName> Handler for GetCustodyColumnsHandler<E> {
type Case = cases::GetCustodyColumns<E>;
impl<E: EthSpec + TypeName> Handler for GetCustodyGroupsHandler<E> {
type Case = cases::GetCustodyGroups<E>;

fn config_name() -> &'static str {
E::name()
Expand All @@ -888,7 +888,27 @@ impl<E: EthSpec + TypeName> Handler for GetCustodyColumnsHandler<E> {
}

fn handler_name(&self) -> String {
"get_custody_columns".into()
"get_custody_groups".into()
}
}

#[derive(Derivative)]
#[derivative(Default(bound = ""))]
pub struct ComputeColumnsForCustodyGroupHandler<E>(PhantomData<E>);

impl<E: EthSpec + TypeName> Handler for ComputeColumnsForCustodyGroupHandler<E> {
type Case = cases::ComputeColumnsForCustodyGroups<E>;

fn config_name() -> &'static str {
E::name()
}

fn runner_name() -> &'static str {
"networking"
}

fn handler_name(&self) -> String {
"compute_columns_for_custody_group".into()
}
}

Expand Down
18 changes: 14 additions & 4 deletions testing/ef_tests/tests/tests.rs
Original file line number Diff line number Diff line change
Expand Up @@ -237,7 +237,9 @@ macro_rules! ssz_static_test_no_run {

#[cfg(feature = "fake_crypto")]
mod ssz_static {
use ef_tests::{Handler, SszStaticHandler, SszStaticTHCHandler, SszStaticWithSpecHandler};
use ef_tests::{
FeatureName, Handler, SszStaticHandler, SszStaticTHCHandler, SszStaticWithSpecHandler,
};
use types::historical_summary::HistoricalSummary;
use types::{
AttesterSlashingBase, AttesterSlashingElectra, ConsolidationRequest, DepositRequest,
Expand Down Expand Up @@ -946,7 +948,15 @@ fn rewards() {
}

#[test]
fn get_custody_columns() {
GetCustodyColumnsHandler::<MainnetEthSpec>::default().run_for_feature(FeatureName::Fulu);
GetCustodyColumnsHandler::<MinimalEthSpec>::default().run_for_feature(FeatureName::Fulu);
fn get_custody_groups() {
GetCustodyGroupsHandler::<MainnetEthSpec>::default().run_for_feature(FeatureName::Fulu);
GetCustodyGroupsHandler::<MinimalEthSpec>::default().run_for_feature(FeatureName::Fulu);
}

#[test]
fn compute_columns_for_custody_group() {
ComputeColumnsForCustodyGroupHandler::<MainnetEthSpec>::default()
.run_for_feature(FeatureName::Fulu);
ComputeColumnsForCustodyGroupHandler::<MinimalEthSpec>::default()
.run_for_feature(FeatureName::Fulu);
}

0 comments on commit 283f940

Please sign in to comment.