Skip to content

Commit

Permalink
Fix compile errors in HTTP tests
Browse files Browse the repository at this point in the history
  • Loading branch information
paulhauner committed Jun 28, 2022
1 parent 8ade87e commit b00c0db
Show file tree
Hide file tree
Showing 2 changed files with 34 additions and 36 deletions.
6 changes: 3 additions & 3 deletions beacon_node/http_api/tests/interactive_tests.rs
Original file line number Diff line number Diff line change
Expand Up @@ -94,15 +94,15 @@ pub async fn fork_choice_before_proposal() {

// Due to proposer boost, the head should be C during slot C.
assert_eq!(
harness.chain.head_info().unwrap().block_root,
harness.chain.canonical_head.read().head_block_root(),
block_root_c.into()
);

// Ensure that building a block via the HTTP API re-runs fork choice and builds block D upon B.
// Manually prod the per-slot task, because the slot timer doesn't run in the background in
// these tests.
harness.advance_slot();
harness.chain.per_slot_task();
harness.chain.per_slot_task().await;

let proposer_index = state_b
.get_beacon_proposer_index(slot_d, &harness.chain.spec)
Expand All @@ -119,7 +119,7 @@ pub async fn fork_choice_before_proposal() {

// Head is now B.
assert_eq!(
harness.chain.head_info().unwrap().block_root,
harness.chain.canonical_head.read().head_block_root(),
block_root_b.into()
);
// D's parent is B.
Expand Down
64 changes: 31 additions & 33 deletions beacon_node/http_api/tests/tests.rs
Original file line number Diff line number Diff line change
Expand Up @@ -162,16 +162,12 @@ impl ApiTester {
let chain = harness.chain.clone();

assert_eq!(
chain.head_info().unwrap().finalized_checkpoint.epoch,
chain.canonical_head.read().finalized_checkpoint().epoch,
2,
"precondition: finality"
);
assert_eq!(
chain
.head_info()
.unwrap()
.current_justified_checkpoint
.epoch,
chain.canonical_head.read().justified_checkpoint().epoch,
3,
"precondition: justification"
);
Expand Down Expand Up @@ -321,7 +317,9 @@ impl ApiTester {
StateId::Slot(Slot::from(SKIPPED_SLOTS[3])),
StateId::Root(Hash256::zero()),
];
ids.push(StateId::Root(self.chain.head_info().unwrap().state_root));
ids.push(StateId::Root(
self.chain.canonical_head.read().head_state_root(),
));
ids
}

Expand All @@ -339,7 +337,9 @@ impl ApiTester {
BlockId::Slot(Slot::from(SKIPPED_SLOTS[3])),
BlockId::Root(Hash256::zero()),
];
ids.push(BlockId::Root(self.chain.head_info().unwrap().block_root));
ids.push(BlockId::Root(
self.chain.canonical_head.read().head_block_root(),
));
ids
}

Expand All @@ -353,9 +353,9 @@ impl ApiTester {
StateId::Finalized => {
let finalized_slot = self
.chain
.head_info()
.unwrap()
.finalized_checkpoint
.canonical_head
.read()
.finalized_checkpoint()
.epoch
.start_slot(E::slots_per_epoch());

Expand All @@ -370,9 +370,9 @@ impl ApiTester {
StateId::Justified => {
let justified_slot = self
.chain
.head_info()
.unwrap()
.current_justified_checkpoint
.canonical_head
.read()
.justified_checkpoint()
.epoch
.start_slot(E::slots_per_epoch());

Expand Down Expand Up @@ -418,14 +418,14 @@ impl ApiTester {
.map(|res| res.data.root);

let expected = match state_id {
StateId::Head => Some(self.chain.head_info().unwrap().state_root),
StateId::Head => Some(self.chain.canonical_head.read().head_state_root()),
StateId::Genesis => Some(self.chain.genesis_state_root),
StateId::Finalized => {
let finalized_slot = self
.chain
.head_info()
.unwrap()
.finalized_checkpoint
.canonical_head
.read()
.finalized_checkpoint()
.epoch
.start_slot(E::slots_per_epoch());

Expand All @@ -434,9 +434,9 @@ impl ApiTester {
StateId::Justified => {
let justified_slot = self
.chain
.head_info()
.unwrap()
.current_justified_checkpoint
.canonical_head
.read()
.justified_checkpoint()
.epoch
.start_slot(E::slots_per_epoch());

Expand Down Expand Up @@ -746,16 +746,14 @@ impl ApiTester {

fn get_block_root(&self, block_id: BlockId) -> Option<Hash256> {
match block_id {
BlockId::Head => Some(self.chain.head_info().unwrap().block_root),
BlockId::Head => Some(self.chain.canonical_head.read().head_block_root()),
BlockId::Genesis => Some(self.chain.genesis_block_root),
BlockId::Finalized => Some(self.chain.head_info().unwrap().finalized_checkpoint.root),
BlockId::Justified => Some(
self.chain
.head_info()
.unwrap()
.current_justified_checkpoint
.root,
),
BlockId::Finalized => {
Some(self.chain.canonical_head.read().finalized_checkpoint().root)
}
BlockId::Justified => {
Some(self.chain.canonical_head.read().justified_checkpoint().root)
}
BlockId::Slot(slot) => self
.chain
.block_root_at_slot(slot, WhenSlotSkipped::None)
Expand Down Expand Up @@ -1314,7 +1312,7 @@ impl ApiTester {

pub async fn test_get_node_syncing(self) -> Self {
let result = self.client.get_node_syncing().await.unwrap().data;
let head_slot = self.chain.head_info().unwrap().slot;
let head_slot = self.chain.canonical_head.read().head_slot();
let sync_distance = self.chain.slot().unwrap() - head_slot;

let expected = SyncingData {
Expand Down Expand Up @@ -1870,7 +1868,7 @@ impl ApiTester {
}

pub async fn test_block_production(self) -> Self {
let fork = self.chain.head_info().unwrap().fork;
let fork = self.chain.canonical_head.read().head_fork();
let genesis_validators_root = self.chain.genesis_validators_root;

for _ in 0..E::slots_per_epoch() * 3 {
Expand Down Expand Up @@ -1949,7 +1947,7 @@ impl ApiTester {
}

pub async fn test_block_production_verify_randao_invalid(self) -> Self {
let fork = self.chain.head_info().unwrap().fork;
let fork = self.chain.canonical_head.read().head_fork();
let genesis_validators_root = self.chain.genesis_validators_root;

for _ in 0..E::slots_per_epoch() {
Expand Down

0 comments on commit b00c0db

Please sign in to comment.