Skip to content

Commit

Permalink
fmt
Browse files Browse the repository at this point in the history
  • Loading branch information
willemolding committed Aug 25, 2023
1 parent a9a7dee commit 79851d6
Show file tree
Hide file tree
Showing 3 changed files with 24 additions and 20 deletions.
24 changes: 15 additions & 9 deletions finality-client/tests/direct_state_reader.rs
Original file line number Diff line number Diff line change
@@ -1,11 +1,11 @@
use crypto::bls::PublicKey;
use ethereum_consensus::bellatrix::{get_active_validator_indices, self};
use ethereum_consensus::bellatrix::{self, get_active_validator_indices};

Check warning on line 2 in finality-client/tests/direct_state_reader.rs

View workflow job for this annotation

GitHub Actions / test

unused import: `self`
use ssz_rs::prelude::*;
use ssz_rs::SimpleSerialize;
use validator_shuffling::get_randao_index;
use zipline_finality_client::state_patch::StatePatch;
use zipline_finality_client::state_reader::{PatchedStateReader, StateReadError, StateReader};
use zipline_spec::Spec;
use ssz_rs::SimpleSerialize;

// holds a eth-consensus BeaconState object which it can read from directly
// useful for testing only
Expand Down Expand Up @@ -114,13 +114,19 @@ impl StateReader for DirectStateReader<ethereum_consensus::capella::mainnet::Bea
}

fn get_active_validator_indices(&self, epoch: u64) -> Result<Vec<usize>, StateReadError> {
Ok(self.state.validators.iter().enumerate().filter_map(|(index, validator)| {
if validator.activation_epoch <= epoch && epoch < validator.exit_epoch {
Some(index)
} else {
None
}
}).collect())
Ok(self
.state
.validators
.iter()
.enumerate()
.filter_map(|(index, validator)| {
if validator.activation_epoch <= epoch && epoch < validator.exit_epoch {
Some(index)
} else {
None
}
})
.collect())
}

fn get_randao<S: Spec>(&self, epoch: u64) -> Result<[u8; 32], StateReadError> {
Expand Down
14 changes: 4 additions & 10 deletions finality-client/tests/verify.rs
Original file line number Diff line number Diff line change
Expand Up @@ -8,14 +8,13 @@ use ethereum_consensus::bellatrix::mainnet as spec;
use ethereum_consensus::capella;
use preimage_oracle::hashmap_oracle::HashMapOracle;
use ssz_rs::prelude::*;
use std::io::Read;
use std::io::Write;
use std::sync::Once;
use zipline_finality_client::ssz_state_reader::{PatchedSszStateReader, SszStateReader};
use zipline_finality_client::{input::ZiplineInput, verify};
use zipline_spec::{MainnetSpec, SpecTestSpec};
use zipline_test_case::ZiplineTestCase;
use std::io::Read;


use crate::direct_state_reader::DirectStateReader;
use crate::direct_state_reader::PatchedDirectStateReader;
Expand Down Expand Up @@ -213,7 +212,7 @@ fn unicorn_mainnet() {
let mut preimages_file = std::fs::File::open(format!("{gen_path}/preimages.bin")).unwrap();
let mut pre = [0; 64];
let mut im = [0; 32];

let mut preims = alloc::collections::btree_map::BTreeMap::new();

while preimages_file.read_exact(&mut im).is_ok() {
Expand Down Expand Up @@ -265,7 +264,7 @@ fn native_mainnet() {

// the mainnet states are capella states rather than bellatrix like the minimal tests
let beaconstatefile = std::fs::read(format!("{gen_path}/state196726")).unwrap();
let state: ethereum_consensus:: capella::mainnet::BeaconState =
let state: ethereum_consensus::capella::mainnet::BeaconState =
deserialize(&beaconstatefile).unwrap();
let reader = DirectStateReader::new(state);

Expand Down Expand Up @@ -334,12 +333,7 @@ fn run_test_unicorn(mut test: ZiplineTestCase) {

let oracle_provider = make_test_oracle_provider(&input, &mut test.state);

let mut mu = new_cannon_unicorn(
UnsyncRam::new(),
oracle_provider,
None,
TraceConfig::Turbo,
);
let mut mu = new_cannon_unicorn(UnsyncRam::new(), oracle_provider, None, TraceConfig::Turbo);

let input_hash = hash(&serialize(&input).unwrap());
write_program(&mut mu, &program);
Expand Down
6 changes: 5 additions & 1 deletion finality-client/tests/zipline_test_case/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -234,7 +234,11 @@ impl ZiplineTestCase {
}
}

pub fn from_input(input: ZiplineInput<{ spec::MAX_VALIDATORS_PER_COMMITTEE }, 1000, 10>, state: BeaconState, expected: bool) -> Self {
pub fn from_input(

Check warning on line 237 in finality-client/tests/zipline_test_case/mod.rs

View workflow job for this annotation

GitHub Actions / test

associated function `from_input` is never used
input: ZiplineInput<{ spec::MAX_VALIDATORS_PER_COMMITTEE }, 1000, 10>,
state: BeaconState,
expected: bool,
) -> Self {
assert_eq!(state.clone().hash_tree_root().unwrap(), input.state_root);
Self {
state,
Expand Down

0 comments on commit 79851d6

Please sign in to comment.