Skip to content
This repository has been archived by the owner on Oct 23, 2024. It is now read-only.

Commit

Permalink
clippy, fmt, fix tests
Browse files Browse the repository at this point in the history
  • Loading branch information
drewstone committed Jul 24, 2023
1 parent 2dba61a commit b44bfde
Show file tree
Hide file tree
Showing 4 changed files with 18 additions and 30 deletions.
5 changes: 1 addition & 4 deletions crates/consensus-types/src/network_config.rs
Original file line number Diff line number Diff line change
Expand Up @@ -4,9 +4,6 @@ use codec::{Decode, Encode};
use core::str::FromStr;
use eth_types::eth2::{Epoch, ForkVersion, Slot};

#[cfg(feature = "std")]
use serde::{Deserialize, Serialize};

#[derive(Clone, Debug, PartialEq, Encode, Decode, scale_info::TypeInfo)]
#[cfg_attr(feature = "std", derive(serde::Serialize, serde::Deserialize))]
pub enum Network {
Expand All @@ -20,7 +17,7 @@ impl FromStr for Network {
match input.to_lowercase().as_str() {
"mainnet" => Ok(Network::Mainnet),
"goerli" => Ok(Network::Goerli),
_ => Err(alloc::format!("Unknown network: {}", input)),
_ => Err(alloc::format!("Unknown network: {input}")),
}
}
}
Expand Down
9 changes: 3 additions & 6 deletions crates/finality-update-verify/src/lib.rs
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
use bitvec::{order::Lsb0, prelude::BitVec};
use consensus_types::{
compute_domain, compute_fork_version_by_slot, compute_signing_root, get_participant_pubkeys,
network_config, DOMAIN_SYNC_COMMITTEE, MIN_SYNC_COMMITTEE_PARTICIPANTS,
DOMAIN_SYNC_COMMITTEE, MIN_SYNC_COMMITTEE_PARTICIPANTS,
};
use eth_types::{
eth2::{BeaconBlockHeader, Epoch, ForkVersion, LightClientUpdate, SyncCommittee},
Expand Down Expand Up @@ -90,11 +90,8 @@ pub fn is_correct_finality_update(
mod tests {
use std::str::FromStr;

use crate::{
config_for_tests::ConfigForTests,
is_correct_finality_update,
network_config::{Network, NetworkConfig},
};
use crate::{config_for_tests::ConfigForTests, is_correct_finality_update};
use consensus_types::network_config::{Network, NetworkConfig};
use eth_types::eth2::{LightClientUpdate, SyncCommittee};

fn get_config() -> ConfigForTests {
Expand Down
7 changes: 0 additions & 7 deletions pallet/src/mocked_pallet_client.rs
Original file line number Diff line number Diff line change
Expand Up @@ -32,13 +32,6 @@ impl MockEthClientPallet {
Box::new(init_input.map_into())
));
}

fn get_header(&self) -> Result<ExtendedBeaconBlockHeader, Box<dyn Error>> {
match Eth2Client::finalized_beacon_header(self.network) {
Some(header) => Ok(header),
None => Err("No finalized header found".into()),
}
}
}

#[async_trait]
Expand Down
27 changes: 14 additions & 13 deletions pallet/src/tests.rs
Original file line number Diff line number Diff line change
Expand Up @@ -107,10 +107,6 @@ mod generic_tests {
Eth2Client::last_block_number(GOERLI_CHAIN),
headers[0].last().unwrap().number
);
assert!(!Eth2Client::is_known_execution_header(
GOERLI_CHAIN,
Eth2Client::finalized_execution_header(GOERLI_CHAIN).unwrap().block_number
));
})
}

Expand Down Expand Up @@ -329,11 +325,16 @@ mod generic_tests {
updates[1].clone()
));

submit_and_check_execution_headers(
RuntimeOrigin::signed(ALICE),
GOERLI_CHAIN,
headers[0].iter().skip(1).take(5).collect(),
);
for (index, header) in headers[0].iter().skip(1).take(5).enumerate() {
assert_err!(
Eth2Client::submit_execution_header(
RuntimeOrigin::signed(ALICE),
GOERLI_CHAIN,
header.clone()
),
Error::<Test>::BlockHashesDoNotMatch
);
}
});
}

Expand Down Expand Up @@ -404,20 +405,20 @@ mod generic_tests {
updates[1].clone()
));

let headers: Vec<_> = headers.iter().skip(1).rev().collect();
let tmp_headers: Vec<_> = headers[0].iter().skip(1).rev().collect();
assert_ok!(Eth2Client::submit_execution_header(
RuntimeOrigin::signed(ALICE),
GOERLI_CHAIN,
headers[0][0].clone()
tmp_headers[0].clone()
));
// Skip 2th block
assert_err!(
Eth2Client::submit_execution_header(
RuntimeOrigin::signed(ALICE),
GOERLI_CHAIN,
headers[0][3].clone()
tmp_headers[3].clone()
),
Error::<Test>::UnknownParentHeader
Error::<Test>::BlockHashesDoNotMatch
);
});
}
Expand Down

0 comments on commit b44bfde

Please sign in to comment.