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:
Shawn Tabrizi
2021-08-02 12:47:33 +02:00
committed by GitHub
parent 30e3012270
commit ff5d56fb76
350 changed files with 20617 additions and 21266 deletions
@@ -18,23 +18,23 @@
//! Utilities for End to end runtime tests
use test_runner::{
Node, ChainInfo, SignatureVerificationOverride, task_executor,
build_runtime, client_parts, ConfigOrChainSpec,
};
use grandpa::GrandpaBlockImport;
use sc_service::{TFullBackend, TFullClient};
use sp_runtime::generic::Era;
use sc_consensus_babe::BabeBlockImport;
use polkadot_runtime_common::claims;
use sp_runtime::AccountId32;
use support::{weights::Weight, StorageValue};
use democracy::{AccountVote, Conviction, Vote};
use polkadot_runtime::{FastTrackVotingPeriod, Runtime, RuntimeApi, Event, TechnicalCollective, CouncilCollective};
use std::{str::FromStr, future::Future, error::Error};
use codec::Encode;
use democracy::{AccountVote, Conviction, Vote};
use grandpa::GrandpaBlockImport;
use polkadot_runtime::{
CouncilCollective, Event, FastTrackVotingPeriod, Runtime, RuntimeApi, TechnicalCollective,
};
use polkadot_runtime_common::claims;
use sc_consensus_babe::BabeBlockImport;
use sc_consensus_manual_seal::consensus::babe::SlotTimestampProvider;
use sp_runtime::app_crypto::sp_core::H256;
use sc_service::{TFullBackend, TFullClient};
use sp_runtime::{app_crypto::sp_core::H256, generic::Era, AccountId32};
use std::{error::Error, future::Future, str::FromStr};
use support::{weights::Weight, StorageValue};
use test_runner::{
build_runtime, client_parts, task_executor, ChainInfo, ConfigOrChainSpec, Node,
SignatureVerificationOverride,
};
type BlockImport<B, BE, C, SC> = BabeBlockImport<B, C, GrandpaBlockImport<BE, B, C, SC>>;
type Block = polkadot_primitives::v1::Block;
@@ -63,7 +63,8 @@ impl ChainInfo for PolkadotChainInfo {
Self::SelectChain,
>;
type SignedExtras = polkadot_runtime::SignedExtra;
type InherentDataProviders = (SlotTimestampProvider, sp_consensus_babe::inherents::InherentDataProvider);
type InherentDataProviders =
(SlotTimestampProvider, sp_consensus_babe::inherents::InherentDataProvider);
fn signed_extras(from: <Runtime as system::Config>::AccountId) -> Self::SignedExtras {
(
@@ -80,23 +81,25 @@ impl ChainInfo for PolkadotChainInfo {
}
/// Dispatch with root origin, via pallet-democracy
pub async fn dispatch_with_root<T>(call: impl Into<<T::Runtime as system::Config>::Call>, node: &Node<T>)
-> Result<(), Box<dyn Error>>
where
T: ChainInfo<
Block=Block,
Executor=Executor,
Runtime=Runtime,
RuntimeApi=RuntimeApi,
SelectChain=SelectChain,
BlockImport=BlockImport<
Block,
TFullBackend<Block>,
TFullClient<Block, RuntimeApi, Executor>,
SelectChain,
>,
SignedExtras=polkadot_runtime::SignedExtra
>
pub async fn dispatch_with_root<T>(
call: impl Into<<T::Runtime as system::Config>::Call>,
node: &Node<T>,
) -> Result<(), Box<dyn Error>>
where
T: ChainInfo<
Block = Block,
Executor = Executor,
Runtime = Runtime,
RuntimeApi = RuntimeApi,
SelectChain = SelectChain,
BlockImport = BlockImport<
Block,
TFullBackend<Block>,
TFullClient<Block, RuntimeApi, Executor>,
SelectChain,
>,
SignedExtras = polkadot_runtime::SignedExtra,
>,
{
type DemocracyCall = democracy::Call<Runtime>;
type CouncilCollectiveEvent = collective::Event<Runtime, CouncilCollective>;
@@ -109,37 +112,47 @@ pub async fn dispatch_with_root<T>(call: impl Into<<T::Runtime as system::Config
"1rvXMZpAj9nKLQkPFCymyH7Fg3ZyKJhJbrc7UtHbTVhJm1A",
"15j4dg5GzsL1bw2U2AWgeyAk6QTxq43V7ZPbXdAmbVLjvDCK",
]
.into_iter()
.map(|account| AccountId32::from_str(account).unwrap())
.collect::<Vec<_>>();
.into_iter()
.map(|account| AccountId32::from_str(account).unwrap())
.collect::<Vec<_>>();
// and these
let (technical_collective, council_collective) = node.with_state(|| (
collective::Members::<Runtime, TechnicalCollective>::get(),
collective::Members::<Runtime, CouncilCollective>::get()
));
let (technical_collective, council_collective) = node.with_state(|| {
(
collective::Members::<Runtime, TechnicalCollective>::get(),
collective::Members::<Runtime, CouncilCollective>::get(),
)
});
// hash of the proposal in democracy
let proposal_hash = {
// note the call (pre-image?) of the call.
node.submit_extrinsic(DemocracyCall::note_preimage(call.into().encode()), whales[0].clone()).await?;
node.submit_extrinsic(
DemocracyCall::note_preimage(call.into().encode()),
whales[0].clone(),
)
.await?;
node.seal_blocks(1).await;
// fetch proposal hash from event emitted by the runtime
let events = node.events();
events.iter()
events
.iter()
.filter_map(|event| match event.event {
Event::Democracy(democracy::Event::PreimageNoted(ref proposal_hash, _, _))
=> Some(proposal_hash.clone()),
_ => None
Event::Democracy(democracy::Event::PreimageNoted(ref proposal_hash, _, _)) =>
Some(proposal_hash.clone()),
_ => None,
})
.next()
.ok_or_else(|| format!("democracy::Event::PreimageNoted not found in events: {:#?}", events))?
.ok_or_else(|| {
format!("democracy::Event::PreimageNoted not found in events: {:#?}", events)
})?
};
// submit external_propose call through council collective
{
let external_propose = DemocracyCall::external_propose_majority(proposal_hash.clone().into());
let external_propose =
DemocracyCall::external_propose_majority(proposal_hash.clone().into());
let length = external_propose.using_encoded(|x| x.len()) as u32 + 1;
let weight = Weight::MAX / 100_000_000;
let proposal = CouncilCollectiveCall::propose(
@@ -153,16 +166,17 @@ pub async fn dispatch_with_root<T>(call: impl Into<<T::Runtime as system::Config
// fetch proposal index from event emitted by the runtime
let events = node.events();
let (index, hash): (u32, H256) = events.iter()
.filter_map(|event| {
match event.event {
Event::Council(CouncilCollectiveEvent::Proposed(_, index, ref hash, _)) =>
Some((index, hash.clone())),
_ => None
}
let (index, hash): (u32, H256) = events
.iter()
.filter_map(|event| match event.event {
Event::Council(CouncilCollectiveEvent::Proposed(_, index, ref hash, _)) =>
Some((index, hash.clone())),
_ => None,
})
.next()
.ok_or_else(|| format!("CouncilCollectiveEvent::Proposed not found in events: {:#?}", events))?;
.ok_or_else(|| {
format!("CouncilCollectiveEvent::Proposed not found in events: {:#?}", events)
})?;
// vote
for member in &council_collective[1..] {
@@ -177,21 +191,24 @@ pub async fn dispatch_with_root<T>(call: impl Into<<T::Runtime as system::Config
node.seal_blocks(1).await;
// assert that proposal has been passed on chain
let events = node.events()
let events = node
.events()
.into_iter()
.filter(|event| {
match event.event {
Event::Council(CouncilCollectiveEvent::Closed(_hash, _, _)) if hash == _hash => true,
Event::Council(CouncilCollectiveEvent::Approved(_hash, )) if hash == _hash => true,
Event::Council(CouncilCollectiveEvent::Executed(_hash, Ok(()))) if hash == _hash => true,
_ => false,
}
.filter(|event| match event.event {
Event::Council(CouncilCollectiveEvent::Closed(_hash, _, _)) if hash == _hash =>
true,
Event::Council(CouncilCollectiveEvent::Approved(_hash)) if hash == _hash => true,
Event::Council(CouncilCollectiveEvent::Executed(_hash, Ok(())))
if hash == _hash =>
true,
_ => false,
})
.collect::<Vec<_>>();
// make sure all 3 events are in state
assert_eq!(
events.len(), 3,
events.len(),
3,
"CouncilCollectiveEvent::{{Closed, Approved, Executed}} not found in events: {:#?}",
node.events(),
);
@@ -199,7 +216,8 @@ pub async fn dispatch_with_root<T>(call: impl Into<<T::Runtime as system::Config
// next technical collective must fast track the proposal.
{
let fast_track = DemocracyCall::fast_track(proposal_hash.into(), FastTrackVotingPeriod::get(), 0);
let fast_track =
DemocracyCall::fast_track(proposal_hash.into(), FastTrackVotingPeriod::get(), 0);
let weight = Weight::MAX / 100_000_000;
let length = fast_track.using_encoded(|x| x.len()) as u32 + 1;
let proposal = TechnicalCollectiveCall::propose(
@@ -212,16 +230,21 @@ pub async fn dispatch_with_root<T>(call: impl Into<<T::Runtime as system::Config
node.seal_blocks(1).await;
let events = node.events();
let (index, hash) = events.iter()
.filter_map(|event| {
match event.event {
Event::TechnicalCommittee(TechnicalCollectiveEvent::Proposed(_, index, ref hash, _))
=> Some((index, hash.clone())),
_ => None
}
let (index, hash) = events
.iter()
.filter_map(|event| match event.event {
Event::TechnicalCommittee(TechnicalCollectiveEvent::Proposed(
_,
index,
ref hash,
_,
)) => Some((index, hash.clone())),
_ => None,
})
.next()
.ok_or_else(|| format!("TechnicalCollectiveEvent::Proposed not found in events: {:#?}", events))?;
.ok_or_else(|| {
format!("TechnicalCollectiveEvent::Proposed not found in events: {:#?}", events)
})?;
// vote
for member in &technical_collective[1..] {
@@ -236,35 +259,44 @@ pub async fn dispatch_with_root<T>(call: impl Into<<T::Runtime as system::Config
node.seal_blocks(1).await;
// assert that fast-track proposal has been passed on chain
let events = node.events()
let events = node
.events()
.into_iter()
.filter(|event| {
match event.event {
Event::TechnicalCommittee(TechnicalCollectiveEvent::Closed(_hash, _, _)) if hash == _hash => true,
Event::TechnicalCommittee(TechnicalCollectiveEvent::Approved(_hash)) if hash == _hash => true,
Event::TechnicalCommittee(TechnicalCollectiveEvent::Executed(_hash, Ok(()))) if hash == _hash => true,
_ => false,
}
.filter(|event| match event.event {
Event::TechnicalCommittee(TechnicalCollectiveEvent::Closed(_hash, _, _))
if hash == _hash =>
true,
Event::TechnicalCommittee(TechnicalCollectiveEvent::Approved(_hash))
if hash == _hash =>
true,
Event::TechnicalCommittee(TechnicalCollectiveEvent::Executed(_hash, Ok(())))
if hash == _hash =>
true,
_ => false,
})
.collect::<Vec<_>>();
// make sure all 3 events are in state
assert_eq!(
events.len(), 3,
events.len(),
3,
"TechnicalCollectiveEvent::{{Closed, Approved, Executed}} not found in events: {:#?}",
node.events(),
);
}
// now runtime upgrade proposal is a fast-tracked referendum we can vote for.
let ref_index = node.events()
let ref_index = node
.events()
.into_iter()
.filter_map(|event| match event.event {
Event::Democracy(democracy::Event::Started(index, _)) => Some(index),
_ => None,
})
.next()
.ok_or_else(|| format!("democracy::Event::Started not found in events: {:#?}", node.events()))?;
.ok_or_else(|| {
format!("democracy::Event::Started not found in events: {:#?}", node.events())
})?;
let call = DemocracyCall::vote(
ref_index,
@@ -282,21 +314,24 @@ pub async fn dispatch_with_root<T>(call: impl Into<<T::Runtime as system::Config
node.seal_blocks(FastTrackVotingPeriod::get() as usize).await;
// assert that the proposal is passed by looking at events
let events = node.events()
let events = node
.events()
.into_iter()
.filter(|event| {
match event.event {
Event::Democracy(democracy::Event::Passed(_index)) if _index == ref_index => true,
Event::Democracy(democracy::Event::PreimageUsed(_hash, _, _)) if _hash == proposal_hash => true,
Event::Democracy(democracy::Event::Executed(_index, Ok(()))) if _index == ref_index => true,
_ => false,
}
.filter(|event| match event.event {
Event::Democracy(democracy::Event::Passed(_index)) if _index == ref_index => true,
Event::Democracy(democracy::Event::PreimageUsed(_hash, _, _))
if _hash == proposal_hash =>
true,
Event::Democracy(democracy::Event::Executed(_index, Ok(()))) if _index == ref_index =>
true,
_ => false,
})
.collect::<Vec<_>>();
// make sure all events were emitted
assert_eq!(
events.len(), 3,
events.len(),
3,
"democracy::Event::{{Passed, PreimageUsed, Executed}} not found in events: {:#?}",
node.events(),
);
@@ -305,12 +340,12 @@ pub async fn dispatch_with_root<T>(call: impl Into<<T::Runtime as system::Config
/// Runs the test-runner as a binary.
pub fn run<F, Fut>(callback: F) -> Result<(), Box<dyn Error>>
where
F: FnOnce(Node<PolkadotChainInfo>) -> Fut,
Fut: Future<Output=Result<(), Box<dyn Error>>>,
where
F: FnOnce(Node<PolkadotChainInfo>) -> Fut,
Fut: Future<Output = Result<(), Box<dyn Error>>>,
{
use structopt::StructOpt;
use sc_cli::{CliConfiguration, SubstrateCli};
use structopt::StructOpt;
let mut tokio_runtime = build_runtime()?;
let task_executor = task_executor(tokio_runtime.handle().clone());
@@ -326,7 +361,8 @@ pub fn run<F, Fut>(callback: F) -> Result<(), Box<dyn Error>>
sc_cli::print_node_infos::<polkadot_cli::Cli>(&config);
let (rpc, task_manager, client, pool, command_sink, backend) =
client_parts::<PolkadotChainInfo>(ConfigOrChainSpec::Config(config))?;
let node = Node::<PolkadotChainInfo>::new(rpc, task_manager, client, pool, command_sink, backend);
let node =
Node::<PolkadotChainInfo>::new(rpc, task_manager, client, pool, command_sink, backend);
// hand off node.
tokio_runtime.block_on(callback(node))?;
@@ -337,19 +373,22 @@ pub fn run<F, Fut>(callback: F) -> Result<(), Box<dyn Error>>
#[cfg(test)]
mod tests {
use super::*;
use sp_keyring::sr25519::Keyring::Alice;
use sp_runtime::{MultiSigner, traits::IdentifyAccount};
use polkadot_service::chain_spec::polkadot_development_config;
use sp_keyring::sr25519::Keyring::Alice;
use sp_runtime::{traits::IdentifyAccount, MultiSigner};
#[test]
fn test_runner() {
let mut runtime = build_runtime().unwrap();
let task_executor = task_executor(runtime.handle().clone());
let (rpc, task_manager, client, pool, command_sink, backend) =
client_parts::<PolkadotChainInfo>(
ConfigOrChainSpec::ChainSpec(Box::new(polkadot_development_config().unwrap()), task_executor)
).unwrap();
let node = Node::<PolkadotChainInfo>::new(rpc, task_manager, client, pool, command_sink, backend);
client_parts::<PolkadotChainInfo>(ConfigOrChainSpec::ChainSpec(
Box::new(polkadot_development_config().unwrap()),
task_executor,
))
.unwrap();
let node =
Node::<PolkadotChainInfo>::new(rpc, task_manager, client, pool, command_sink, backend);
runtime.block_on(async {
// seals blocks