Skip to content

Commit

Permalink
test(sidecar): fetch two-epoch proposer duties
Browse files Browse the repository at this point in the history
  • Loading branch information
thedevbirb committed Oct 28, 2024
1 parent 2c0e977 commit bd2ed7e
Showing 1 changed file with 40 additions and 1 deletion.
41 changes: 40 additions & 1 deletion bolt-sidecar/src/state/consensus.rs
Original file line number Diff line number Diff line change
Expand Up @@ -204,7 +204,7 @@ impl ConsensusState {

#[cfg(test)]
mod tests {
use beacon_api_client::ProposerDuty;
use beacon_api_client::{BlockId, ProposerDuty};
use reqwest::Url;
use tracing::warn;

Expand Down Expand Up @@ -232,6 +232,7 @@ mod tests {
validator_indexes,
commitment_deadline_duration: Duration::from_secs(1),
latest_slot: 0,
unsafe_lookahead_enabled: false,
};

// Test finding a valid slot
Expand Down Expand Up @@ -268,6 +269,7 @@ mod tests {
validator_indexes,
commitment_deadline: CommitmentDeadline::new(0, commitment_deadline_duration),
commitment_deadline_duration,
unsafe_lookahead_enabled: false,
};

// Update the slot to 32
Expand All @@ -290,4 +292,41 @@ mod tests {

Ok(())
}

#[tokio::test]
async fn test_fetch_proposer_duties() -> eyre::Result<()> {
let _ = tracing_subscriber::fmt::try_init();

let commitment_deadline_duration = Duration::from_secs(1);
let validator_indexes = ValidatorIndexes::from(vec![100, 101, 102]);

let Some(url) = try_get_beacon_api_url().await else {
warn!("skipping test: beacon API URL is not reachable");
return Ok(());
};

let beacon_client = BeaconClient::new(Url::parse(url).unwrap());

// Create the initial ConsensusState
let mut state = ConsensusState {
beacon_api_client: beacon_client,
epoch: Epoch::default(),
latest_slot: Default::default(),
latest_slot_timestamp: Instant::now(),
validator_indexes,
commitment_deadline: CommitmentDeadline::new(0, commitment_deadline_duration),
commitment_deadline_duration,
// We test for both epochs
unsafe_lookahead_enabled: true,
};

let epoch =
state.beacon_api_client.get_beacon_header(BlockId::Head).await?.header.message.slot
/ SLOTS_PER_EPOCH;

state.fetch_proposer_duties(epoch).await?;
assert_eq!(state.epoch.proposer_duties.len(), SLOTS_PER_EPOCH as usize * 2);

Ok(())
}
}

0 comments on commit bd2ed7e

Please sign in to comment.