mirror of
https://github.com/pezkuwichain/pezkuwi-subxt.git
synced 2026-07-18 15:15:42 +00:00
cargo +nightly fmt (#3540)
* cargo +nightly fmt * add cargo-fmt check to ci * update ci * fmt * fmt * skip macro * ignore bridges
This commit is contained in:
@@ -22,16 +22,16 @@ use std::{collections::HashMap, sync::Arc};
|
||||
use async_trait::async_trait;
|
||||
use lazy_static::lazy_static;
|
||||
|
||||
use polkadot_node_network_protocol::{PeerId, authority_discovery::AuthorityDiscovery};
|
||||
use polkadot_node_network_protocol::{authority_discovery::AuthorityDiscovery, PeerId};
|
||||
use sc_keystore::LocalKeystore;
|
||||
use sp_application_crypto::AppKey;
|
||||
use sp_keyring::{Sr25519Keyring};
|
||||
use sp_keyring::Sr25519Keyring;
|
||||
use sp_keystore::{SyncCryptoStore, SyncCryptoStorePtr};
|
||||
|
||||
use polkadot_node_primitives::{DisputeMessage, SignedDisputeStatement};
|
||||
use polkadot_primitives::v1::{
|
||||
CandidateDescriptor, CandidateHash, CandidateReceipt, Hash,
|
||||
SessionIndex, SessionInfo, ValidatorId, ValidatorIndex, AuthorityDiscoveryId,
|
||||
AuthorityDiscoveryId, CandidateDescriptor, CandidateHash, CandidateReceipt, Hash, SessionIndex,
|
||||
SessionInfo, ValidatorId, ValidatorIndex,
|
||||
};
|
||||
|
||||
pub const MOCK_SESSION_INDEX: SessionIndex = 1;
|
||||
@@ -45,22 +45,19 @@ pub const MOCK_VALIDATORS: [Sr25519Keyring; 6] = [
|
||||
Sr25519Keyring::Eve,
|
||||
];
|
||||
|
||||
pub const MOCK_AUTHORITIES_NEXT_SESSION: [Sr25519Keyring;2] = [
|
||||
Sr25519Keyring::One,
|
||||
Sr25519Keyring::Two,
|
||||
];
|
||||
pub const MOCK_AUTHORITIES_NEXT_SESSION: [Sr25519Keyring; 2] =
|
||||
[Sr25519Keyring::One, Sr25519Keyring::Two];
|
||||
|
||||
pub const FERDIE_INDEX: ValidatorIndex = ValidatorIndex(0);
|
||||
pub const ALICE_INDEX: ValidatorIndex = ValidatorIndex(1);
|
||||
|
||||
|
||||
lazy_static! {
|
||||
|
||||
/// Mocked `AuthorityDiscovery` service.
|
||||
pub static ref MOCK_AUTHORITY_DISCOVERY: MockAuthorityDiscovery = MockAuthorityDiscovery::new();
|
||||
// Creating an innocent looking `SessionInfo` is really expensive in a debug build. Around
|
||||
// 700ms on my machine, We therefore cache those keys here:
|
||||
pub static ref MOCK_VALIDATORS_DISCOVERY_KEYS: HashMap<Sr25519Keyring, AuthorityDiscoveryId> =
|
||||
pub static ref MOCK_VALIDATORS_DISCOVERY_KEYS: HashMap<Sr25519Keyring, AuthorityDiscoveryId> =
|
||||
MOCK_VALIDATORS
|
||||
.iter()
|
||||
.chain(MOCK_AUTHORITIES_NEXT_SESSION.iter())
|
||||
@@ -92,13 +89,9 @@ pub static ref MOCK_NEXT_SESSION_INFO: SessionInfo =
|
||||
};
|
||||
}
|
||||
|
||||
|
||||
pub fn make_candidate_receipt(relay_parent: Hash) -> CandidateReceipt {
|
||||
CandidateReceipt {
|
||||
descriptor: CandidateDescriptor {
|
||||
relay_parent,
|
||||
..Default::default()
|
||||
},
|
||||
descriptor: CandidateDescriptor { relay_parent, ..Default::default() },
|
||||
commitments_hash: Hash::random(),
|
||||
}
|
||||
}
|
||||
@@ -106,15 +99,11 @@ pub fn make_candidate_receipt(relay_parent: Hash) -> CandidateReceipt {
|
||||
pub async fn make_explicit_signed(
|
||||
validator: Sr25519Keyring,
|
||||
candidate_hash: CandidateHash,
|
||||
valid: bool
|
||||
valid: bool,
|
||||
) -> SignedDisputeStatement {
|
||||
let keystore: SyncCryptoStorePtr = Arc::new(LocalKeystore::in_memory());
|
||||
SyncCryptoStore::sr25519_generate_new(
|
||||
&*keystore,
|
||||
ValidatorId::ID,
|
||||
Some(&validator.to_seed()),
|
||||
)
|
||||
.expect("Insert key into keystore");
|
||||
SyncCryptoStore::sr25519_generate_new(&*keystore, ValidatorId::ID, Some(&validator.to_seed()))
|
||||
.expect("Insert key into keystore");
|
||||
|
||||
SignedDisputeStatement::sign_explicit(
|
||||
&keystore,
|
||||
@@ -128,17 +117,18 @@ pub async fn make_explicit_signed(
|
||||
.expect("Signing should work.")
|
||||
}
|
||||
|
||||
|
||||
pub async fn make_dispute_message(
|
||||
candidate: CandidateReceipt,
|
||||
valid_validator: ValidatorIndex,
|
||||
invalid_validator: ValidatorIndex,
|
||||
) -> DisputeMessage {
|
||||
let candidate_hash = candidate.hash();
|
||||
let valid_vote =
|
||||
make_explicit_signed(MOCK_VALIDATORS[valid_validator.0 as usize], candidate_hash, true).await;
|
||||
let valid_vote =
|
||||
make_explicit_signed(MOCK_VALIDATORS[valid_validator.0 as usize], candidate_hash, true)
|
||||
.await;
|
||||
let invalid_vote =
|
||||
make_explicit_signed(MOCK_VALIDATORS[invalid_validator.0 as usize], candidate_hash, false).await;
|
||||
make_explicit_signed(MOCK_VALIDATORS[invalid_validator.0 as usize], candidate_hash, false)
|
||||
.await;
|
||||
DisputeMessage::from_signed_statements(
|
||||
valid_vote,
|
||||
valid_validator,
|
||||
@@ -153,7 +143,7 @@ pub async fn make_dispute_message(
|
||||
/// Dummy `AuthorityDiscovery` service.
|
||||
#[derive(Debug, Clone)]
|
||||
pub struct MockAuthorityDiscovery {
|
||||
peer_ids: HashMap<Sr25519Keyring, PeerId>
|
||||
peer_ids: HashMap<Sr25519Keyring, PeerId>,
|
||||
}
|
||||
|
||||
impl MockAuthorityDiscovery {
|
||||
@@ -178,13 +168,17 @@ impl MockAuthorityDiscovery {
|
||||
|
||||
#[async_trait]
|
||||
impl AuthorityDiscovery for MockAuthorityDiscovery {
|
||||
async fn get_addresses_by_authority_id(&mut self, _authority: polkadot_primitives::v1::AuthorityDiscoveryId)
|
||||
-> Option<Vec<sc_network::Multiaddr>> {
|
||||
panic!("Not implemented");
|
||||
async fn get_addresses_by_authority_id(
|
||||
&mut self,
|
||||
_authority: polkadot_primitives::v1::AuthorityDiscoveryId,
|
||||
) -> Option<Vec<sc_network::Multiaddr>> {
|
||||
panic!("Not implemented");
|
||||
}
|
||||
|
||||
async fn get_authority_id_by_peer_id(&mut self, peer_id: polkadot_node_network_protocol::PeerId)
|
||||
-> Option<polkadot_primitives::v1::AuthorityDiscoveryId> {
|
||||
async fn get_authority_id_by_peer_id(
|
||||
&mut self,
|
||||
peer_id: polkadot_node_network_protocol::PeerId,
|
||||
) -> Option<polkadot_primitives::v1::AuthorityDiscoveryId> {
|
||||
for (a, p) in self.peer_ids.iter() {
|
||||
if p == &peer_id {
|
||||
return Some(MOCK_VALIDATORS_DISCOVERY_KEYS.get(&a).unwrap().clone())
|
||||
|
||||
Reference in New Issue
Block a user