mirror of
https://github.com/pezkuwichain/pezkuwi-subxt.git
synced 2026-06-14 02:51:08 +00:00
Run cargo fmt on the whole code base (#9394)
* Run cargo fmt on the whole code base * Second run * Add CI check * Fix compilation * More unnecessary braces * Handle weights * Use --all * Use correct attributes... * Fix UI tests * AHHHHHHHHH * 🤦 * Docs * Fix compilation * 🤷 * Please stop * 🤦 x 2 * More * make rustfmt.toml consistent with polkadot Co-authored-by: André Silva <andrerfosilva@gmail.com>
This commit is contained in:
@@ -31,50 +31,53 @@
|
||||
//! NOTE: Aura itself is designed to be generic over the crypto used.
|
||||
#![forbid(missing_docs, unsafe_code)]
|
||||
use std::{
|
||||
sync::Arc, marker::PhantomData, hash::Hash, fmt::Debug, pin::Pin,
|
||||
convert::{TryFrom, TryInto},
|
||||
fmt::Debug,
|
||||
hash::Hash,
|
||||
marker::PhantomData,
|
||||
pin::Pin,
|
||||
sync::Arc,
|
||||
};
|
||||
|
||||
use futures::prelude::*;
|
||||
use log::{debug, trace};
|
||||
|
||||
use codec::{Encode, Decode, Codec};
|
||||
use codec::{Codec, Decode, Encode};
|
||||
|
||||
use sp_consensus::{
|
||||
BlockImport, Environment, Proposer, CanAuthorWith, ForkChoiceStrategy, BlockImportParams,
|
||||
BlockOrigin, Error as ConsensusError, SelectChain, StateAction,
|
||||
};
|
||||
use sc_client_api::{backend::AuxStore, BlockOf, UsageProvider};
|
||||
use sp_blockchain::{Result as CResult, ProvideCache, HeaderBackend};
|
||||
use sp_core::crypto::Public;
|
||||
use sp_application_crypto::{AppKey, AppPublic};
|
||||
use sp_runtime::{generic::BlockId, traits::NumberFor};
|
||||
use sp_runtime::traits::{Block as BlockT, Header, DigestItemFor, Zero, Member};
|
||||
use sp_api::ProvideRuntimeApi;
|
||||
use sp_core::crypto::Pair;
|
||||
use sp_keystore::{SyncCryptoStorePtr, SyncCryptoStore};
|
||||
use sp_inherents::CreateInherentDataProviders;
|
||||
use sc_telemetry::TelemetryHandle;
|
||||
use sc_consensus_slots::{
|
||||
SlotInfo, BackoffAuthoringBlocksStrategy, InherentDataProviderExt, StorageChanges,
|
||||
BackoffAuthoringBlocksStrategy, InherentDataProviderExt, SlotInfo, StorageChanges,
|
||||
};
|
||||
use sc_telemetry::TelemetryHandle;
|
||||
use sp_api::ProvideRuntimeApi;
|
||||
use sp_application_crypto::{AppKey, AppPublic};
|
||||
use sp_blockchain::{HeaderBackend, ProvideCache, Result as CResult};
|
||||
use sp_consensus::{
|
||||
BlockImport, BlockImportParams, BlockOrigin, CanAuthorWith, Environment,
|
||||
Error as ConsensusError, ForkChoiceStrategy, Proposer, SelectChain, StateAction,
|
||||
};
|
||||
use sp_consensus_slots::Slot;
|
||||
use sp_core::crypto::{Pair, Public};
|
||||
use sp_inherents::CreateInherentDataProviders;
|
||||
use sp_keystore::{SyncCryptoStore, SyncCryptoStorePtr};
|
||||
use sp_runtime::{
|
||||
generic::BlockId,
|
||||
traits::{Block as BlockT, DigestItemFor, Header, Member, NumberFor, Zero},
|
||||
};
|
||||
|
||||
mod import_queue;
|
||||
|
||||
pub use sp_consensus_aura::{
|
||||
ConsensusLog, AuraApi, AURA_ENGINE_ID, digests::CompatibleDigestItem,
|
||||
inherents::{
|
||||
InherentType as AuraInherent,
|
||||
INHERENT_IDENTIFIER, InherentDataProvider,
|
||||
},
|
||||
};
|
||||
pub use sp_consensus::SyncOracle;
|
||||
pub use import_queue::{
|
||||
ImportQueueParams, import_queue, CheckForEquivocation,
|
||||
build_verifier, BuildVerifierParams, AuraVerifier,
|
||||
build_verifier, import_queue, AuraVerifier, BuildVerifierParams, CheckForEquivocation,
|
||||
ImportQueueParams,
|
||||
};
|
||||
pub use sc_consensus_slots::SlotProportion;
|
||||
pub use sp_consensus::SyncOracle;
|
||||
pub use sp_consensus_aura::{
|
||||
digests::CompatibleDigestItem,
|
||||
inherents::{InherentDataProvider, InherentType as AuraInherent, INHERENT_IDENTIFIER},
|
||||
AuraApi, ConsensusLog, AURA_ENGINE_ID,
|
||||
};
|
||||
|
||||
type AuthorityId<P> = <P as Pair>::Public;
|
||||
|
||||
@@ -82,7 +85,8 @@ type AuthorityId<P> = <P as Pair>::Public;
|
||||
pub type SlotDuration = sc_consensus_slots::SlotDuration<sp_consensus_aura::SlotDuration>;
|
||||
|
||||
/// Get type of `SlotDuration` for Aura.
|
||||
pub fn slot_duration<A, B, C>(client: &C) -> CResult<SlotDuration> where
|
||||
pub fn slot_duration<A, B, C>(client: &C) -> CResult<SlotDuration>
|
||||
where
|
||||
A: Codec,
|
||||
B: BlockT,
|
||||
C: AuxStore + ProvideRuntimeApi<B> + UsageProvider<B>,
|
||||
@@ -93,7 +97,9 @@ pub fn slot_duration<A, B, C>(client: &C) -> CResult<SlotDuration> where
|
||||
|
||||
/// Get slot author for given block along with authorities.
|
||||
fn slot_author<P: Pair>(slot: Slot, authorities: &[AuthorityId<P>]) -> Option<&AuthorityId<P>> {
|
||||
if authorities.is_empty() { return None }
|
||||
if authorities.is_empty() {
|
||||
return None
|
||||
}
|
||||
|
||||
let idx = *slot % (authorities.len() as u64);
|
||||
assert!(
|
||||
@@ -101,9 +107,10 @@ fn slot_author<P: Pair>(slot: Slot, authorities: &[AuthorityId<P>]) -> Option<&A
|
||||
"It is impossible to have a vector with length beyond the address space; qed",
|
||||
);
|
||||
|
||||
let current_author = authorities.get(idx as usize)
|
||||
.expect("authorities not empty; index constrained to list length;\
|
||||
this is a valid index; qed");
|
||||
let current_author = authorities.get(idx as usize).expect(
|
||||
"authorities not empty; index constrained to list length;\
|
||||
this is a valid index; qed",
|
||||
);
|
||||
|
||||
Some(current_author)
|
||||
}
|
||||
@@ -325,9 +332,8 @@ where
|
||||
type BlockImport = I;
|
||||
type SyncOracle = SO;
|
||||
type JustificationSyncLink = L;
|
||||
type CreateProposer = Pin<Box<
|
||||
dyn Future<Output = Result<E::Proposer, sp_consensus::Error>> + Send + 'static
|
||||
>>;
|
||||
type CreateProposer =
|
||||
Pin<Box<dyn Future<Output = Result<E::Proposer, sp_consensus::Error>> + Send + 'static>>;
|
||||
type Proposer = E::Proposer;
|
||||
type Claim = P::Public;
|
||||
type EpochData = Vec<AuthorityId<P>>;
|
||||
@@ -376,22 +382,25 @@ where
|
||||
slot: Slot,
|
||||
_claim: &Self::Claim,
|
||||
) -> Vec<sp_runtime::DigestItem<B::Hash>> {
|
||||
vec![
|
||||
<DigestItemFor<B> as CompatibleDigestItem<P::Signature>>::aura_pre_digest(slot),
|
||||
]
|
||||
vec![<DigestItemFor<B> as CompatibleDigestItem<P::Signature>>::aura_pre_digest(slot)]
|
||||
}
|
||||
|
||||
fn block_import_params(&self) -> Box<dyn Fn(
|
||||
B::Header,
|
||||
&B::Hash,
|
||||
Vec<B::Extrinsic>,
|
||||
StorageChanges<sp_api::TransactionFor<C, B>, B>,
|
||||
Self::Claim,
|
||||
Self::EpochData,
|
||||
) -> Result<
|
||||
sp_consensus::BlockImportParams<B, sp_api::TransactionFor<C, B>>,
|
||||
sp_consensus::Error> + Send + 'static>
|
||||
{
|
||||
fn block_import_params(
|
||||
&self,
|
||||
) -> Box<
|
||||
dyn Fn(
|
||||
B::Header,
|
||||
&B::Hash,
|
||||
Vec<B::Extrinsic>,
|
||||
StorageChanges<sp_api::TransactionFor<C, B>, B>,
|
||||
Self::Claim,
|
||||
Self::EpochData,
|
||||
) -> Result<
|
||||
sp_consensus::BlockImportParams<B, sp_api::TransactionFor<C, B>>,
|
||||
sp_consensus::Error,
|
||||
> + Send
|
||||
+ 'static,
|
||||
> {
|
||||
let keystore = self.keystore.clone();
|
||||
Box::new(move |header, header_hash, body, storage_changes, public, _epoch| {
|
||||
// sign the pre-sealed hash of the block and then
|
||||
@@ -402,28 +411,28 @@ where
|
||||
&*keystore,
|
||||
<AuthorityId<P> as AppKey>::ID,
|
||||
&public_type_pair,
|
||||
header_hash.as_ref()
|
||||
).map_err(|e| sp_consensus::Error::CannotSign(
|
||||
public.clone(), e.to_string(),
|
||||
))?
|
||||
.ok_or_else(|| sp_consensus::Error::CannotSign(
|
||||
public.clone(), "Could not find key in keystore.".into(),
|
||||
))?;
|
||||
let signature = signature.clone().try_into()
|
||||
.map_err(|_| sp_consensus::Error::InvalidSignature(
|
||||
signature, public
|
||||
))?;
|
||||
header_hash.as_ref(),
|
||||
)
|
||||
.map_err(|e| sp_consensus::Error::CannotSign(public.clone(), e.to_string()))?
|
||||
.ok_or_else(|| {
|
||||
sp_consensus::Error::CannotSign(
|
||||
public.clone(),
|
||||
"Could not find key in keystore.".into(),
|
||||
)
|
||||
})?;
|
||||
let signature = signature
|
||||
.clone()
|
||||
.try_into()
|
||||
.map_err(|_| sp_consensus::Error::InvalidSignature(signature, public))?;
|
||||
|
||||
let signature_digest_item = <
|
||||
DigestItemFor<B> as CompatibleDigestItem<P::Signature>
|
||||
>::aura_seal(signature);
|
||||
let signature_digest_item =
|
||||
<DigestItemFor<B> as CompatibleDigestItem<P::Signature>>::aura_seal(signature);
|
||||
|
||||
let mut import_block = BlockImportParams::new(BlockOrigin::Own, header);
|
||||
import_block.post_digests.push(signature_digest_item);
|
||||
import_block.body = Some(body);
|
||||
import_block.state_action = StateAction::ApplyChanges(
|
||||
sp_consensus::StorageChanges::Changes(storage_changes)
|
||||
);
|
||||
import_block.state_action =
|
||||
StateAction::ApplyChanges(sp_consensus::StorageChanges::Changes(storage_changes));
|
||||
import_block.fork_choice = Some(ForkChoiceStrategy::LongestChain);
|
||||
|
||||
Ok(import_block)
|
||||
@@ -443,7 +452,7 @@ where
|
||||
self.client.info().finalized_number,
|
||||
slot,
|
||||
self.logging_target(),
|
||||
);
|
||||
)
|
||||
}
|
||||
}
|
||||
false
|
||||
@@ -458,9 +467,11 @@ where
|
||||
}
|
||||
|
||||
fn proposer(&mut self, block: &B::Header) -> Self::CreateProposer {
|
||||
Box::pin(self.env.init(block).map_err(|e| {
|
||||
sp_consensus::Error::ClientImport(format!("{:?}", e)).into()
|
||||
}))
|
||||
Box::pin(
|
||||
self.env
|
||||
.init(block)
|
||||
.map_err(|e| sp_consensus::Error::ClientImport(format!("{:?}", e)).into()),
|
||||
)
|
||||
}
|
||||
|
||||
fn telemetry(&self) -> Option<TelemetryHandle> {
|
||||
@@ -515,7 +526,7 @@ impl<B: BlockT> std::convert::From<Error<B>> for String {
|
||||
|
||||
fn find_pre_digest<B: BlockT, Signature: Codec>(header: &B::Header) -> Result<Slot, Error<B>> {
|
||||
if header.number().is_zero() {
|
||||
return Ok(0.into());
|
||||
return Ok(0.into())
|
||||
}
|
||||
|
||||
let mut pre_digest: Option<Slot> = None;
|
||||
@@ -530,13 +541,15 @@ fn find_pre_digest<B: BlockT, Signature: Codec>(header: &B::Header) -> Result<Sl
|
||||
pre_digest.ok_or_else(|| aura_err(Error::NoDigestFound))
|
||||
}
|
||||
|
||||
fn authorities<A, B, C>(client: &C, at: &BlockId<B>) -> Result<Vec<A>, ConsensusError> where
|
||||
fn authorities<A, B, C>(client: &C, at: &BlockId<B>) -> Result<Vec<A>, ConsensusError>
|
||||
where
|
||||
A: Codec + Debug,
|
||||
B: BlockT,
|
||||
C: ProvideRuntimeApi<B> + BlockOf + ProvideCache<B>,
|
||||
C::Api: AuraApi<B, A>,
|
||||
{
|
||||
client.runtime_api()
|
||||
client
|
||||
.runtime_api()
|
||||
.authorities(at)
|
||||
.ok()
|
||||
.ok_or_else(|| sp_consensus::Error::InvalidAuthoritiesSet.into())
|
||||
@@ -545,26 +558,31 @@ fn authorities<A, B, C>(client: &C, at: &BlockId<B>) -> Result<Vec<A>, Consensus
|
||||
#[cfg(test)]
|
||||
mod tests {
|
||||
use super::*;
|
||||
use sp_consensus::{
|
||||
NoNetwork as DummyOracle, Proposal, AlwaysCanAuthor, DisableProofRecording,
|
||||
import_queue::BoxJustificationImport, SlotData,
|
||||
};
|
||||
use sc_network_test::{Block as TestBlock, *};
|
||||
use sp_runtime::traits::{Block as BlockT, DigestFor};
|
||||
use sc_network::config::ProtocolConfig;
|
||||
use parking_lot::Mutex;
|
||||
use sp_keyring::sr25519::Keyring;
|
||||
use sc_client_api::BlockchainEvents;
|
||||
use sp_consensus_aura::sr25519::AuthorityPair;
|
||||
use sc_consensus_slots::{SimpleSlotWorker, BackoffAuthoringOnFinalizedHeadLagging};
|
||||
use std::{task::Poll, time::{Instant, Duration}};
|
||||
use sc_block_builder::BlockBuilderProvider;
|
||||
use sp_runtime::traits::Header as _;
|
||||
use substrate_test_runtime_client::{TestClient, runtime::{Header, H256}};
|
||||
use sc_client_api::BlockchainEvents;
|
||||
use sc_consensus_slots::{BackoffAuthoringOnFinalizedHeadLagging, SimpleSlotWorker};
|
||||
use sc_keystore::LocalKeystore;
|
||||
use sc_network::config::ProtocolConfig;
|
||||
use sc_network_test::{Block as TestBlock, *};
|
||||
use sp_application_crypto::key_types::AURA;
|
||||
use sp_consensus::{
|
||||
import_queue::BoxJustificationImport, AlwaysCanAuthor, DisableProofRecording,
|
||||
NoNetwork as DummyOracle, Proposal, SlotData,
|
||||
};
|
||||
use sp_consensus_aura::sr25519::AuthorityPair;
|
||||
use sp_inherents::InherentData;
|
||||
use sp_keyring::sr25519::Keyring;
|
||||
use sp_runtime::traits::{Block as BlockT, DigestFor, Header as _};
|
||||
use sp_timestamp::InherentDataProvider as TimestampInherentDataProvider;
|
||||
use std::{
|
||||
task::Poll,
|
||||
time::{Duration, Instant},
|
||||
};
|
||||
use substrate_test_runtime_client::{
|
||||
runtime::{Header, H256},
|
||||
TestClient,
|
||||
};
|
||||
|
||||
type Error = sp_blockchain::Error;
|
||||
|
||||
@@ -576,19 +594,15 @@ mod tests {
|
||||
type CreateProposer = futures::future::Ready<Result<DummyProposer, Error>>;
|
||||
type Error = Error;
|
||||
|
||||
fn init(&mut self, parent_header: &<TestBlock as BlockT>::Header)
|
||||
-> Self::CreateProposer
|
||||
{
|
||||
fn init(&mut self, parent_header: &<TestBlock as BlockT>::Header) -> Self::CreateProposer {
|
||||
futures::future::ready(Ok(DummyProposer(parent_header.number + 1, self.0.clone())))
|
||||
}
|
||||
}
|
||||
|
||||
impl Proposer<TestBlock> for DummyProposer {
|
||||
type Error = Error;
|
||||
type Transaction = sc_client_api::TransactionFor<
|
||||
substrate_test_runtime_client::Backend,
|
||||
TestBlock
|
||||
>;
|
||||
type Transaction =
|
||||
sc_client_api::TransactionFor<substrate_test_runtime_client::Backend, TestBlock>;
|
||||
type Proposal = future::Ready<Result<Proposal<TestBlock, Self::Transaction, ()>, Error>>;
|
||||
type ProofRecording = DisableProofRecording;
|
||||
type Proof = ();
|
||||
@@ -616,11 +630,13 @@ mod tests {
|
||||
PeersFullClient,
|
||||
AuthorityPair,
|
||||
AlwaysCanAuthor,
|
||||
Box<dyn CreateInherentDataProviders<
|
||||
TestBlock,
|
||||
(),
|
||||
InherentDataProviders = (TimestampInherentDataProvider, InherentDataProvider)
|
||||
>>
|
||||
Box<
|
||||
dyn CreateInherentDataProviders<
|
||||
TestBlock,
|
||||
(),
|
||||
InherentDataProviders = (TimestampInherentDataProvider, InherentDataProvider),
|
||||
>,
|
||||
>,
|
||||
>;
|
||||
type AuraPeer = Peer<(), PeersClient>;
|
||||
|
||||
@@ -635,14 +651,15 @@ mod tests {
|
||||
|
||||
/// Create new test network with peers and given config.
|
||||
fn from_config(_config: &ProtocolConfig) -> Self {
|
||||
AuraTestNet {
|
||||
peers: Vec::new(),
|
||||
}
|
||||
AuraTestNet { peers: Vec::new() }
|
||||
}
|
||||
|
||||
fn make_verifier(&self, client: PeersClient, _cfg: &ProtocolConfig, _peer_data: &())
|
||||
-> Self::Verifier
|
||||
{
|
||||
fn make_verifier(
|
||||
&self,
|
||||
client: PeersClient,
|
||||
_cfg: &ProtocolConfig,
|
||||
_peer_data: &(),
|
||||
) -> Self::Verifier {
|
||||
match client {
|
||||
PeersClient::Full(client, _) => {
|
||||
let slot_duration = slot_duration(&*client).expect("slot duration available");
|
||||
@@ -668,7 +685,10 @@ mod tests {
|
||||
}
|
||||
}
|
||||
|
||||
fn make_block_import(&self, client: PeersClient) -> (
|
||||
fn make_block_import(
|
||||
&self,
|
||||
client: PeersClient,
|
||||
) -> (
|
||||
BlockImportAdapter<Self::BlockImport>,
|
||||
Option<BoxJustificationImport<Block>>,
|
||||
Self::PeerData,
|
||||
@@ -693,11 +713,7 @@ mod tests {
|
||||
sp_tracing::try_init_simple();
|
||||
let net = AuraTestNet::new(3);
|
||||
|
||||
let peers = &[
|
||||
(0, Keyring::Alice),
|
||||
(1, Keyring::Bob),
|
||||
(2, Keyring::Charlie),
|
||||
];
|
||||
let peers = &[(0, Keyring::Alice), (1, Keyring::Bob), (2, Keyring::Charlie)];
|
||||
|
||||
let net = Arc::new(Mutex::new(net));
|
||||
let mut import_notifications = Vec::new();
|
||||
@@ -710,9 +726,9 @@ mod tests {
|
||||
let client = peer.client().as_full().expect("full clients are created").clone();
|
||||
let select_chain = peer.select_chain().expect("full client has a select chain");
|
||||
let keystore_path = tempfile::tempdir().expect("Creates keystore path");
|
||||
let keystore = Arc::new(LocalKeystore::open(keystore_path.path(), None)
|
||||
.expect("Creates keystore."));
|
||||
|
||||
let keystore = Arc::new(
|
||||
LocalKeystore::open(keystore_path.path(), None).expect("Creates keystore."),
|
||||
);
|
||||
|
||||
SyncCryptoStore::sr25519_generate_new(&*keystore, AURA, Some(&key.to_seed()))
|
||||
.expect("Creates authority key");
|
||||
@@ -720,38 +736,46 @@ mod tests {
|
||||
|
||||
let environ = DummyFactory(client.clone());
|
||||
import_notifications.push(
|
||||
client.import_notification_stream()
|
||||
.take_while(|n| future::ready(!(n.origin != BlockOrigin::Own && n.header.number() < &5)))
|
||||
.for_each(move |_| future::ready(()))
|
||||
client
|
||||
.import_notification_stream()
|
||||
.take_while(|n| {
|
||||
future::ready(!(n.origin != BlockOrigin::Own && n.header.number() < &5))
|
||||
})
|
||||
.for_each(move |_| future::ready(())),
|
||||
);
|
||||
|
||||
let slot_duration = slot_duration(&*client).expect("slot duration available");
|
||||
|
||||
aura_futures.push(start_aura::<AuthorityPair, _, _, _, _, _, _, _, _, _, _, _>(StartAuraParams {
|
||||
slot_duration,
|
||||
block_import: client.clone(),
|
||||
select_chain,
|
||||
client,
|
||||
proposer_factory: environ,
|
||||
sync_oracle: DummyOracle,
|
||||
justification_sync_link: (),
|
||||
create_inherent_data_providers: |_, _| async {
|
||||
let timestamp = TimestampInherentDataProvider::from_system_time();
|
||||
let slot = InherentDataProvider::from_timestamp_and_duration(
|
||||
*timestamp,
|
||||
Duration::from_secs(6),
|
||||
);
|
||||
aura_futures.push(
|
||||
start_aura::<AuthorityPair, _, _, _, _, _, _, _, _, _, _, _>(StartAuraParams {
|
||||
slot_duration,
|
||||
block_import: client.clone(),
|
||||
select_chain,
|
||||
client,
|
||||
proposer_factory: environ,
|
||||
sync_oracle: DummyOracle,
|
||||
justification_sync_link: (),
|
||||
create_inherent_data_providers: |_, _| async {
|
||||
let timestamp = TimestampInherentDataProvider::from_system_time();
|
||||
let slot = InherentDataProvider::from_timestamp_and_duration(
|
||||
*timestamp,
|
||||
Duration::from_secs(6),
|
||||
);
|
||||
|
||||
Ok((timestamp, slot))
|
||||
},
|
||||
force_authoring: false,
|
||||
backoff_authoring_blocks: Some(BackoffAuthoringOnFinalizedHeadLagging::default()),
|
||||
keystore,
|
||||
can_author_with: sp_consensus::AlwaysCanAuthor,
|
||||
block_proposal_slot_portion: SlotProportion::new(0.5),
|
||||
max_block_proposal_slot_portion: None,
|
||||
telemetry: None,
|
||||
}).expect("Starts aura"));
|
||||
Ok((timestamp, slot))
|
||||
},
|
||||
force_authoring: false,
|
||||
backoff_authoring_blocks: Some(
|
||||
BackoffAuthoringOnFinalizedHeadLagging::default(),
|
||||
),
|
||||
keystore,
|
||||
can_author_with: sp_consensus::AlwaysCanAuthor,
|
||||
block_proposal_slot_portion: SlotProportion::new(0.5),
|
||||
max_block_proposal_slot_portion: None,
|
||||
telemetry: None,
|
||||
})
|
||||
.expect("Starts aura"),
|
||||
);
|
||||
}
|
||||
|
||||
futures::executor::block_on(future::select(
|
||||
@@ -759,10 +783,7 @@ mod tests {
|
||||
net.lock().poll(cx);
|
||||
Poll::<()>::Pending
|
||||
}),
|
||||
future::select(
|
||||
future::join_all(aura_futures),
|
||||
future::join_all(import_notifications)
|
||||
)
|
||||
future::select(future::join_all(aura_futures), future::join_all(import_notifications)),
|
||||
));
|
||||
}
|
||||
|
||||
@@ -771,11 +792,14 @@ mod tests {
|
||||
let client = substrate_test_runtime_client::new();
|
||||
|
||||
assert_eq!(client.chain_info().best_number, 0);
|
||||
assert_eq!(authorities(&client, &BlockId::Number(0)).unwrap(), vec![
|
||||
Keyring::Alice.public().into(),
|
||||
Keyring::Bob.public().into(),
|
||||
Keyring::Charlie.public().into()
|
||||
]);
|
||||
assert_eq!(
|
||||
authorities(&client, &BlockId::Number(0)).unwrap(),
|
||||
vec![
|
||||
Keyring::Alice.public().into(),
|
||||
Keyring::Bob.public().into(),
|
||||
Keyring::Charlie.public().into()
|
||||
]
|
||||
);
|
||||
}
|
||||
|
||||
#[test]
|
||||
@@ -785,12 +809,11 @@ mod tests {
|
||||
let mut authorities = vec![
|
||||
Keyring::Alice.public().into(),
|
||||
Keyring::Bob.public().into(),
|
||||
Keyring::Charlie.public().into()
|
||||
Keyring::Charlie.public().into(),
|
||||
];
|
||||
|
||||
let keystore_path = tempfile::tempdir().expect("Creates keystore path");
|
||||
let keystore = LocalKeystore::open(keystore_path.path(), None)
|
||||
.expect("Creates keystore.");
|
||||
let keystore = LocalKeystore::open(keystore_path.path(), None).expect("Creates keystore.");
|
||||
let public = SyncCryptoStore::sr25519_generate_new(&keystore, AuthorityPair::ID, None)
|
||||
.expect("Key should be created");
|
||||
authorities.push(public.into());
|
||||
@@ -822,7 +845,7 @@ mod tests {
|
||||
H256::from_low_u64_be(0),
|
||||
H256::from_low_u64_be(0),
|
||||
Default::default(),
|
||||
Default::default()
|
||||
Default::default(),
|
||||
);
|
||||
assert!(worker.claim_slot(&head, 0.into(), &authorities).is_none());
|
||||
assert!(worker.claim_slot(&head, 1.into(), &authorities).is_none());
|
||||
@@ -839,12 +862,13 @@ mod tests {
|
||||
let net = AuraTestNet::new(4);
|
||||
|
||||
let keystore_path = tempfile::tempdir().expect("Creates keystore path");
|
||||
let keystore = LocalKeystore::open(keystore_path.path(), None)
|
||||
.expect("Creates keystore.");
|
||||
let keystore = LocalKeystore::open(keystore_path.path(), None).expect("Creates keystore.");
|
||||
SyncCryptoStore::sr25519_generate_new(
|
||||
&keystore,
|
||||
AuthorityPair::ID, Some(&Keyring::Alice.to_seed()),
|
||||
).expect("Key should be created");
|
||||
AuthorityPair::ID,
|
||||
Some(&Keyring::Alice.to_seed()),
|
||||
)
|
||||
.expect("Key should be created");
|
||||
|
||||
let net = Arc::new(Mutex::new(net));
|
||||
|
||||
@@ -870,17 +894,16 @@ mod tests {
|
||||
|
||||
let head = client.header(&BlockId::Number(0)).unwrap().unwrap();
|
||||
|
||||
let res = futures::executor::block_on(worker.on_slot(
|
||||
SlotInfo {
|
||||
slot: 0.into(),
|
||||
timestamp: 0.into(),
|
||||
ends_at: Instant::now() + Duration::from_secs(100),
|
||||
inherent_data: InherentData::new(),
|
||||
duration: Duration::from_millis(1000),
|
||||
chain_head: head,
|
||||
block_size_limit: None,
|
||||
}
|
||||
)).unwrap();
|
||||
let res = futures::executor::block_on(worker.on_slot(SlotInfo {
|
||||
slot: 0.into(),
|
||||
timestamp: 0.into(),
|
||||
ends_at: Instant::now() + Duration::from_secs(100),
|
||||
inherent_data: InherentData::new(),
|
||||
duration: Duration::from_millis(1000),
|
||||
chain_head: head,
|
||||
block_size_limit: None,
|
||||
}))
|
||||
.unwrap();
|
||||
|
||||
// The returned block should be imported and we should be able to get its header by now.
|
||||
assert!(client.header(&BlockId::Hash(res.block.hash())).unwrap().is_some());
|
||||
|
||||
Reference in New Issue
Block a user