Skip to content

Commit

Permalink
remove some sync committee tests
Browse files Browse the repository at this point in the history
  • Loading branch information
Wizdave97 committed Dec 31, 2023
1 parent 87e01ff commit cb41a15
Showing 1 changed file with 1 addition and 161 deletions.
162 changes: 1 addition & 161 deletions parachain/modules/consensus/sync-committee/prover/src/test.rs
Original file line number Diff line number Diff line change
@@ -1,10 +1,7 @@
use super::*;
use base2::Base2;
use reqwest_eventsource::EventSource;
use ssz_rs::{
calculate_multi_merkle_root, get_generalized_index, is_valid_merkle_branch, GeneralizedIndex,
Merkleized, SszVariableOrIndex,
};
use ssz_rs::{calculate_multi_merkle_root, is_valid_merkle_branch, GeneralizedIndex, Merkleized};
use std::time::Duration;
use sync_committee_primitives::{
constants::{
Expand Down Expand Up @@ -55,42 +52,6 @@ async fn fetch_processed_sync_committee_works() {
assert!(validator.is_ok());
}

#[allow(non_snake_case)]
#[tokio::test]
#[ignore]
async fn generate_indexes() {
let sync_committee_prover = setup_prover();
let beacon_state = sync_committee_prover.fetch_beacon_state("head").await.unwrap();
let execution_payload_index = get_generalized_index(
&beacon_state,
&[SszVariableOrIndex::Name("latest_execution_payload_header")],
);
let next_sync =
get_generalized_index(&beacon_state, &[SszVariableOrIndex::Name("next_sync_committee")]);
let finalized =
get_generalized_index(&beacon_state, &[SszVariableOrIndex::Name("finalized_checkpoint")]);
let execution_payload_root = get_generalized_index(
&beacon_state.latest_execution_payload_header,
&[SszVariableOrIndex::Name("state_root")],
);
let block_number = get_generalized_index(
&beacon_state.latest_execution_payload_header,
&[SszVariableOrIndex::Name("block_number")],
);
let timestamp = get_generalized_index(
&beacon_state.latest_execution_payload_header,
&[SszVariableOrIndex::Name("timestamp")],
);
dbg!(execution_payload_index);
dbg!(next_sync);
dbg!(finalized);
dbg!(execution_payload_root);
dbg!(block_number);
dbg!(timestamp);

dbg!(next_sync.floor_log2());
}

#[allow(non_snake_case)]
#[tokio::test]
#[ignore]
Expand Down Expand Up @@ -234,127 +195,6 @@ async fn test_sync_committee_update_proof() {
assert!(is_merkle_branch_valid);
}

#[allow(non_snake_case)]
#[tokio::test]
#[ignore]
async fn test_client_sync() {
let sync_committee_prover = setup_prover();
let start_period = 810;
let end_period = 815;
let starting_slot = ((start_period * EPOCHS_PER_SYNC_COMMITTEE_PERIOD) * SLOTS_PER_EPOCH) +
(EPOCHS_PER_SYNC_COMMITTEE_PERIOD * SLOTS_PER_EPOCH) -
1;
let block_header =
sync_committee_prover.fetch_header(&starting_slot.to_string()).await.unwrap();

let state = sync_committee_prover
.fetch_beacon_state(&block_header.slot.to_string())
.await
.unwrap();

let mut client_state = VerifierState {
finalized_header: block_header.clone(),
latest_finalized_epoch: compute_epoch_at_slot(block_header.slot),
current_sync_committee: state.current_sync_committee,
next_sync_committee: state.next_sync_committee,
state_period: 810,
};

let mut next_period = start_period + 1;
loop {
if next_period > end_period {
break;
}
let update = sync_committee_prover.latest_update_for_period(next_period).await.unwrap();
dbg!(&update);
client_state = verify_sync_committee_attestation(client_state, update).unwrap();
next_period += 1;
}

println!("Sync completed");
}

#[allow(non_snake_case)]
#[tokio::test]
#[ignore]
async fn test_sync_committee_hand_offs() {
let sync_committee_prover = setup_prover();
let state_period = 805;
let signature_period = 806;
let starting_slot = ((state_period * EPOCHS_PER_SYNC_COMMITTEE_PERIOD) * SLOTS_PER_EPOCH) + 1;
let block_header =
sync_committee_prover.fetch_header(&starting_slot.to_string()).await.unwrap();

let state = sync_committee_prover
.fetch_beacon_state(&block_header.slot.to_string())
.await
.unwrap();

let mut client_state = VerifierState {
finalized_header: block_header.clone(),
latest_finalized_epoch: compute_epoch_at_slot(block_header.slot),
current_sync_committee: state.current_sync_committee,
next_sync_committee: state.next_sync_committee,
state_period: 805,
};

// Verify an update from state_period + 1
let latest_block_id = {
let slot = ((signature_period * EPOCHS_PER_SYNC_COMMITTEE_PERIOD) * SLOTS_PER_EPOCH) +
((EPOCHS_PER_SYNC_COMMITTEE_PERIOD * SLOTS_PER_EPOCH) / 2);
slot.to_string()
};

let finalized_checkpoint = sync_committee_prover
.fetch_finalized_checkpoint(Some("head"))
.await
.unwrap()
.finalized;

let update = sync_committee_prover
.fetch_light_client_update(
client_state.clone(),
finalized_checkpoint.clone(),
Some(&latest_block_id),
"prover",
)
.await
.unwrap()
.unwrap();
assert!(update.sync_committee_update.is_some());
client_state = verify_sync_committee_attestation(client_state, update).unwrap();
assert_eq!(client_state.state_period, state_period + 1);
// Verify block in the current state_period
let latest_block_id = {
let slot = ((signature_period * EPOCHS_PER_SYNC_COMMITTEE_PERIOD) * SLOTS_PER_EPOCH) +
(EPOCHS_PER_SYNC_COMMITTEE_PERIOD * SLOTS_PER_EPOCH) -
1;
slot.to_string()
};

let update = sync_committee_prover
.fetch_light_client_update(
client_state.clone(),
finalized_checkpoint,
Some(&latest_block_id),
"prover",
)
.await
.unwrap()
.unwrap();
assert!(update.sync_committee_update.is_none());
client_state = verify_sync_committee_attestation(client_state, update).unwrap();

let next_period = signature_period + 1;
let next_period_slot = ((next_period * EPOCHS_PER_SYNC_COMMITTEE_PERIOD) * SLOTS_PER_EPOCH) + 1;
let beacon_state = sync_committee_prover
.fetch_beacon_state(&next_period_slot.to_string())
.await
.unwrap();

assert_eq!(client_state.next_sync_committee, beacon_state.current_sync_committee);
}

#[allow(non_snake_case)]
#[tokio::test]
#[ignore]
Expand Down

0 comments on commit cb41a15

Please sign in to comment.