Skip to content

Commit

Permalink
Add single_attestation event topic test coverage
Browse files Browse the repository at this point in the history
  • Loading branch information
eserilev committed Jan 16, 2025
1 parent f7a0b37 commit 42c01c6
Show file tree
Hide file tree
Showing 2 changed files with 57 additions and 0 deletions.
56 changes: 56 additions & 0 deletions beacon_node/http_api/tests/tests.rs
Original file line number Diff line number Diff line change
Expand Up @@ -6042,6 +6042,48 @@ impl ApiTester {
self
}

pub async fn test_get_events_electra(self) -> Self {
let topics = vec![EventTopic::SingleAttestation];
let mut events_future = self
.client
.get_events::<E>(topics.as_slice())
.await
.unwrap();

let expected_attestation_len = self.single_attestations.len();

let fork_name = self
.chain
.spec
.fork_name_at_slot::<E>(self.chain.slot().unwrap());

self.client
.post_beacon_pool_attestations_v2(&self.single_attestations, fork_name)
.await
.unwrap();

let attestation_events = poll_events(
&mut events_future,
expected_attestation_len,
Duration::from_millis(10000),
)
.await;

assert_eq!(
attestation_events.as_slice(),
self.single_attestations
.clone()
.into_iter()
.map(|single_attestation| EventKind::SingleAttestation(Box::new(
single_attestation
)))
.collect::<Vec<_>>()
.as_slice()
);

self
}

pub async fn test_get_events_altair(self) -> Self {
let topics = vec![EventTopic::ContributionAndProof];
let mut events_future = self
Expand Down Expand Up @@ -6189,6 +6231,20 @@ async fn get_events_altair() {
.await;
}

#[tokio::test(flavor = "multi_thread", worker_threads = 2)]
async fn get_events_electra() {
let mut config = ApiTesterConfig::default();
config.spec.altair_fork_epoch = Some(Epoch::new(0));
config.spec.bellatrix_fork_epoch = Some(Epoch::new(0));
config.spec.capella_fork_epoch = Some(Epoch::new(0));
config.spec.deneb_fork_epoch = Some(Epoch::new(0));
config.spec.electra_fork_epoch = Some(Epoch::new(0));
ApiTester::new_from_config(config)
.await
.test_get_events_electra()
.await;
}

#[tokio::test(flavor = "multi_thread", worker_threads = 2)]
async fn get_events_from_genesis() {
ApiTester::new_from_genesis()
Expand Down
1 change: 1 addition & 0 deletions common/eth2/src/types.rs
Original file line number Diff line number Diff line change
Expand Up @@ -1288,6 +1288,7 @@ impl FromStr for EventTopic {
"block" => Ok(EventTopic::Block),
"blob_sidecar" => Ok(EventTopic::BlobSidecar),
"attestation" => Ok(EventTopic::Attestation),
"single_attestation" => Ok(EventTopic::SingleAttestation),
"voluntary_exit" => Ok(EventTopic::VoluntaryExit),
"finalized_checkpoint" => Ok(EventTopic::FinalizedCheckpoint),
"chain_reorg" => Ok(EventTopic::ChainReorg),
Expand Down

0 comments on commit 42c01c6

Please sign in to comment.