Make EF Tests Fork-Agnostic (#5713)

This commit is contained in:
ethDreamer
2024-05-03 13:57:01 -05:00
committed by GitHub
parent 3a41e137d1
commit 9b98f4e297

View File

@@ -23,11 +23,10 @@ use state_processing::state_advance::complete_state_advance;
use std::future::Future; use std::future::Future;
use std::sync::Arc; use std::sync::Arc;
use std::time::Duration; use std::time::Duration;
use types::AttesterSlashingBase;
use types::{ use types::{
Attestation, AttesterSlashingRef, BeaconBlock, BeaconState, BlobSidecar, BlobsList, Checkpoint, Attestation, AttesterSlashing, AttesterSlashingRef, BeaconBlock, BeaconState, BlobSidecar,
ExecutionBlockHash, Hash256, IndexedAttestation, KzgProof, ProposerPreparationData, BlobsList, Checkpoint, ExecutionBlockHash, Hash256, IndexedAttestation, KzgProof,
SignedBeaconBlock, Slot, Uint256, ProposerPreparationData, SignedBeaconBlock, Slot, Uint256,
}; };
#[derive(Default, Debug, PartialEq, Clone, Deserialize, Decode)] #[derive(Default, Debug, PartialEq, Clone, Deserialize, Decode)]
@@ -134,7 +133,7 @@ pub struct ForkChoiceTest<E: EthSpec> {
#[allow(clippy::type_complexity)] #[allow(clippy::type_complexity)]
// TODO(electra): these tests will need to be updated to use new types // TODO(electra): these tests will need to be updated to use new types
pub steps: Vec< pub steps: Vec<
Step<SignedBeaconBlock<E>, BlobsList<E>, Attestation<E>, AttesterSlashingBase<E>, PowBlock>, Step<SignedBeaconBlock<E>, BlobsList<E>, Attestation<E>, AttesterSlashing<E>, PowBlock>,
>, >,
} }
@@ -185,10 +184,24 @@ impl<E: EthSpec> LoadCase for ForkChoiceTest<E> {
ssz_decode_file(&path.join(format!("{}.ssz_snappy", attestation))) ssz_decode_file(&path.join(format!("{}.ssz_snappy", attestation)))
.map(|attestation| Step::Attestation { attestation }) .map(|attestation| Step::Attestation { attestation })
} }
Step::AttesterSlashing { attester_slashing } => { Step::AttesterSlashing { attester_slashing } => match fork_name {
ssz_decode_file(&path.join(format!("{}.ssz_snappy", attester_slashing))) ForkName::Base
.map(|attester_slashing| Step::AttesterSlashing { attester_slashing }) | ForkName::Altair
} | ForkName::Bellatrix
| ForkName::Capella
| ForkName::Deneb => {
ssz_decode_file(&path.join(format!("{}.ssz_snappy", attester_slashing)))
.map(|attester_slashing| Step::AttesterSlashing {
attester_slashing: AttesterSlashing::Base(attester_slashing),
})
}
ForkName::Electra => {
ssz_decode_file(&path.join(format!("{}.ssz_snappy", attester_slashing)))
.map(|attester_slashing| Step::AttesterSlashing {
attester_slashing: AttesterSlashing::Electra(attester_slashing),
})
}
},
Step::PowBlock { pow_block } => { Step::PowBlock { pow_block } => {
ssz_decode_file(&path.join(format!("{}.ssz_snappy", pow_block))) ssz_decode_file(&path.join(format!("{}.ssz_snappy", pow_block)))
.map(|pow_block| Step::PowBlock { pow_block }) .map(|pow_block| Step::PowBlock { pow_block })
@@ -251,7 +264,7 @@ impl<E: EthSpec> Case for ForkChoiceTest<E> {
} => tester.process_block(block.clone(), blobs.clone(), proofs.clone(), *valid)?, } => tester.process_block(block.clone(), blobs.clone(), proofs.clone(), *valid)?,
Step::Attestation { attestation } => tester.process_attestation(attestation)?, Step::Attestation { attestation } => tester.process_attestation(attestation)?,
Step::AttesterSlashing { attester_slashing } => { Step::AttesterSlashing { attester_slashing } => {
tester.process_attester_slashing(AttesterSlashingRef::Base(attester_slashing)) tester.process_attester_slashing(attester_slashing.to_ref())
} }
Step::PowBlock { pow_block } => tester.process_pow_block(pow_block), Step::PowBlock { pow_block } => tester.process_pow_block(pow_block),
Step::OnPayloadInfo { Step::OnPayloadInfo {