Skip to content

Commit

Permalink
Generate more interesting ids
Browse files Browse the repository at this point in the history
  • Loading branch information
paulhauner committed Sep 5, 2020
1 parent 6324b56 commit d9f5773
Showing 1 changed file with 54 additions and 60 deletions.
114 changes: 54 additions & 60 deletions beacon_node/http_api/tests/tests.rs
Original file line number Diff line number Diff line change
Expand Up @@ -100,6 +100,42 @@ impl ApiTester {
}
}

fn interesting_state_ids(&self) -> Vec<StateId> {
let mut ids = vec![
StateId::Head,
StateId::Genesis,
StateId::Finalized,
StateId::Justified,
StateId::Slot(Slot::new(0)),
StateId::Slot(Slot::new(32)),
StateId::Slot(Slot::from(SKIPPED_SLOTS[0])),
StateId::Slot(Slot::from(SKIPPED_SLOTS[1])),
StateId::Slot(Slot::from(SKIPPED_SLOTS[2])),
StateId::Slot(Slot::from(SKIPPED_SLOTS[3])),
StateId::Root(Hash256::zero()),
];
ids.push(StateId::Root(self.chain.head_info().unwrap().state_root));
ids
}

fn interesting_block_ids(&self) -> Vec<BlockId> {
let mut ids = vec![
BlockId::Head,
BlockId::Genesis,
BlockId::Finalized,
BlockId::Justified,
BlockId::Slot(Slot::new(0)),
BlockId::Slot(Slot::new(32)),
BlockId::Slot(Slot::from(SKIPPED_SLOTS[0])),
BlockId::Slot(Slot::from(SKIPPED_SLOTS[1])),
BlockId::Slot(Slot::from(SKIPPED_SLOTS[2])),
BlockId::Slot(Slot::from(SKIPPED_SLOTS[3])),
BlockId::Root(Hash256::zero()),
];
ids.push(BlockId::Root(self.chain.head_info().unwrap().block_root));
ids
}

fn get_state(&self, state_id: StateId) -> Option<BeaconState<E>> {
match state_id {
StateId::Head => Some(self.chain.head().unwrap().beacon_state),
Expand Down Expand Up @@ -150,8 +186,8 @@ impl ApiTester {
}
}

pub async fn test_beacon_states_root(self, state_ids: &[StateId]) -> Self {
for &state_id in state_ids {
pub async fn test_beacon_states_root(self) -> Self {
for state_id in self.interesting_state_ids() {
let result = self
.client
.beacon_states_root(state_id)
Expand Down Expand Up @@ -194,8 +230,8 @@ impl ApiTester {
self
}

pub async fn test_beacon_states_fork(self, state_ids: &[StateId]) -> Self {
for &state_id in state_ids {
pub async fn test_beacon_states_fork(self) -> Self {
for state_id in self.interesting_state_ids() {
let result = self
.client
.beacon_states_fork(state_id)
Expand All @@ -211,8 +247,8 @@ impl ApiTester {
self
}

pub async fn test_beacon_states_finality_checkpoints(self, state_ids: &[StateId]) -> Self {
for &state_id in state_ids {
pub async fn test_beacon_states_finality_checkpoints(self) -> Self {
for state_id in self.interesting_state_ids() {
let result = self
.client
.beacon_states_finality_checkpoints(state_id)
Expand All @@ -234,8 +270,8 @@ impl ApiTester {
self
}

pub async fn test_beacon_states_validators(self, state_ids: &[StateId]) -> Self {
for &state_id in state_ids {
pub async fn test_beacon_states_validators(self) -> Self {
for state_id in self.interesting_state_ids() {
let result = self
.client
.beacon_states_validators(state_id)
Expand Down Expand Up @@ -275,8 +311,8 @@ impl ApiTester {
self
}

pub async fn test_beacon_states_validator_id(self, state_ids: &[StateId]) -> Self {
for &state_id in state_ids {
pub async fn test_beacon_states_validator_id(self) -> Self {
for state_id in self.interesting_state_ids() {
let state_opt = self.get_state(state_id);
let validators = match state_opt.as_ref() {
Some(state) => state.validators.clone().into(),
Expand Down Expand Up @@ -353,8 +389,8 @@ impl ApiTester {
}
}

pub async fn test_beacon_blocks_root(self, block_ids: &[BlockId]) -> Self {
for &block_id in block_ids {
pub async fn test_beacon_blocks_root(self) -> Self {
for block_id in self.interesting_block_ids() {
let result = self
.client
.beacon_blocks_root(block_id)
Expand All @@ -371,76 +407,34 @@ impl ApiTester {
}
}

fn interesting_state_ids() -> Vec<StateId> {
vec![
StateId::Head,
StateId::Genesis,
StateId::Finalized,
StateId::Justified,
StateId::Slot(Slot::new(0)),
StateId::Slot(Slot::new(32)),
StateId::Slot(Slot::from(SKIPPED_SLOTS[0])),
StateId::Slot(Slot::from(SKIPPED_SLOTS[1])),
StateId::Slot(Slot::from(SKIPPED_SLOTS[2])),
StateId::Slot(Slot::from(SKIPPED_SLOTS[3])),
StateId::Root(Hash256::zero()),
]
}

fn interesting_block_ids() -> Vec<BlockId> {
vec![
BlockId::Head,
BlockId::Genesis,
BlockId::Finalized,
BlockId::Justified,
BlockId::Slot(Slot::new(0)),
BlockId::Slot(Slot::new(32)),
BlockId::Slot(Slot::from(SKIPPED_SLOTS[0])),
BlockId::Slot(Slot::from(SKIPPED_SLOTS[1])),
BlockId::Slot(Slot::from(SKIPPED_SLOTS[2])),
BlockId::Slot(Slot::from(SKIPPED_SLOTS[3])),
BlockId::Root(Hash256::zero()),
]
}

#[tokio::test(core_threads = 2)]
async fn beacon_states_root() {
ApiTester::new()
.test_beacon_states_root(&interesting_state_ids())
.await;
ApiTester::new().test_beacon_states_root().await;
}

#[tokio::test(core_threads = 2)]
async fn beacon_states_fork() {
ApiTester::new()
.test_beacon_states_fork(&interesting_state_ids())
.await;
ApiTester::new().test_beacon_states_fork().await;
}

#[tokio::test(core_threads = 2)]
async fn beacon_states_finality_checkpoints() {
ApiTester::new()
.test_beacon_states_finality_checkpoints(&interesting_state_ids())
.test_beacon_states_finality_checkpoints()
.await;
}

#[tokio::test(core_threads = 2)]
async fn beacon_states_validators() {
ApiTester::new()
.test_beacon_states_validators(&interesting_state_ids())
.await;
ApiTester::new().test_beacon_states_validators().await;
}

#[tokio::test(core_threads = 2)]
async fn beacon_states_validator_id() {
ApiTester::new()
.test_beacon_states_validator_id(&interesting_state_ids())
.await;
ApiTester::new().test_beacon_states_validator_id().await;
}

#[tokio::test(core_threads = 2)]
async fn beacon_blocks_root() {
ApiTester::new()
.test_beacon_blocks_root(&interesting_block_ids())
.await;
ApiTester::new().test_beacon_blocks_root().await;
}

0 comments on commit d9f5773

Please sign in to comment.