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:
Bastian Köcher
2021-07-21 16:32:32 +02:00
committed by GitHub
parent d451c38c1c
commit 7b56ab15b4
1010 changed files with 53339 additions and 51208 deletions
+98 -62
View File
@@ -21,13 +21,16 @@
use super::*;
use frame_support::{
assert_ok, assert_noop, parameter_types, RuntimeDebug, dispatch::DispatchError, traits::Filter,
};
use codec::{Encode, Decode};
use sp_core::H256;
use sp_runtime::{traits::{BlakeTwo256, IdentityLookup}, testing::Header};
use crate as proxy;
use codec::{Decode, Encode};
use frame_support::{
assert_noop, assert_ok, dispatch::DispatchError, parameter_types, traits::Filter, RuntimeDebug,
};
use sp_core::H256;
use sp_runtime::{
testing::Header,
traits::{BlakeTwo256, IdentityLookup},
};
type UncheckedExtrinsic = frame_system::mocking::MockUncheckedExtrinsic<Test>;
type Block = frame_system::mocking::MockBlock<Test>;
@@ -102,18 +105,25 @@ parameter_types! {
pub const AnnouncementDepositBase: u64 = 1;
pub const AnnouncementDepositFactor: u64 = 1;
}
#[derive(Copy, Clone, Eq, PartialEq, Ord, PartialOrd, Encode, Decode, RuntimeDebug, MaxEncodedLen)]
#[derive(
Copy, Clone, Eq, PartialEq, Ord, PartialOrd, Encode, Decode, RuntimeDebug, MaxEncodedLen,
)]
pub enum ProxyType {
Any,
JustTransfer,
JustUtility,
}
impl Default for ProxyType { fn default() -> Self { Self::Any } }
impl Default for ProxyType {
fn default() -> Self {
Self::Any
}
}
impl InstanceFilter<Call> for ProxyType {
fn filter(&self, c: &Call) -> bool {
match self {
ProxyType::Any => true,
ProxyType::JustTransfer => matches!(c, Call::Balances(pallet_balances::Call::transfer(..))),
ProxyType::JustTransfer =>
matches!(c, Call::Balances(pallet_balances::Call::transfer(..))),
ProxyType::JustUtility => matches!(c, Call::Utility(..)),
}
}
@@ -147,27 +157,31 @@ impl Config for Test {
type AnnouncementDepositFactor = AnnouncementDepositFactor;
}
use super::{Call as ProxyCall, Event as ProxyEvent};
use frame_system::Call as SystemCall;
use pallet_balances::Call as BalancesCall;
use pallet_balances::Error as BalancesError;
use pallet_balances::Event as BalancesEvent;
use pallet_utility::Call as UtilityCall;
use pallet_utility::Event as UtilityEvent;
use super::Event as ProxyEvent;
use super::Call as ProxyCall;
use pallet_balances::{Call as BalancesCall, Error as BalancesError, Event as BalancesEvent};
use pallet_utility::{Call as UtilityCall, Event as UtilityEvent};
pub fn new_test_ext() -> sp_io::TestExternalities {
let mut t = frame_system::GenesisConfig::default().build_storage::<Test>().unwrap();
pallet_balances::GenesisConfig::<Test> {
balances: vec![(1, 10), (2, 10), (3, 10), (4, 10), (5, 2)],
}.assimilate_storage(&mut t).unwrap();
}
.assimilate_storage(&mut t)
.unwrap();
let mut ext = sp_io::TestExternalities::new(t);
ext.execute_with(|| System::set_block_number(1));
ext
}
fn last_events(n: usize) -> Vec<Event> {
system::Pallet::<Test>::events().into_iter().rev().take(n).rev().map(|e| e.event).collect()
system::Pallet::<Test>::events()
.into_iter()
.rev()
.take(n)
.rev()
.map(|e| e.event)
.collect()
}
fn expect_events(e: Vec<Event>) {
@@ -183,27 +197,21 @@ fn announcement_works() {
assert_ok!(Proxy::announce(Origin::signed(3), 1, [1; 32].into()));
let announcements = Announcements::<Test>::get(3);
assert_eq!(announcements.0, vec![Announcement {
real: 1,
call_hash: [1; 32].into(),
height: 1,
}]);
assert_eq!(
announcements.0,
vec![Announcement { real: 1, call_hash: [1; 32].into(), height: 1 }]
);
assert_eq!(Balances::reserved_balance(3), announcements.1);
assert_ok!(Proxy::announce(Origin::signed(3), 2, [2; 32].into()));
let announcements = Announcements::<Test>::get(3);
assert_eq!(announcements.0, vec![
Announcement {
real: 1,
call_hash: [1; 32].into(),
height: 1,
},
Announcement {
real: 2,
call_hash: [2; 32].into(),
height: 1,
},
]);
assert_eq!(
announcements.0,
vec![
Announcement { real: 1, call_hash: [1; 32].into(), height: 1 },
Announcement { real: 2, call_hash: [2; 32].into(), height: 1 },
]
);
assert_eq!(Balances::reserved_balance(3), announcements.1);
assert_noop!(Proxy::announce(Origin::signed(3), 2, [3; 32].into()), Error::<Test>::TooMany);
@@ -221,11 +229,10 @@ fn remove_announcement_works() {
assert_noop!(Proxy::remove_announcement(Origin::signed(3), 1, [0; 32].into()), e);
assert_ok!(Proxy::remove_announcement(Origin::signed(3), 1, [1; 32].into()));
let announcements = Announcements::<Test>::get(3);
assert_eq!(announcements.0, vec![Announcement {
real: 2,
call_hash: [2; 32].into(),
height: 1,
}]);
assert_eq!(
announcements.0,
vec![Announcement { real: 2, call_hash: [2; 32].into(), height: 1 }]
);
assert_eq!(Balances::reserved_balance(3), announcements.1);
});
}
@@ -243,11 +250,10 @@ fn reject_announcement_works() {
assert_noop!(Proxy::reject_announcement(Origin::signed(4), 3, [1; 32].into()), e);
assert_ok!(Proxy::reject_announcement(Origin::signed(1), 3, [1; 32].into()));
let announcements = Announcements::<Test>::get(3);
assert_eq!(announcements.0, vec![Announcement {
real: 2,
call_hash: [2; 32].into(),
height: 1,
}]);
assert_eq!(
announcements.0,
vec![Announcement { real: 2, call_hash: [2; 32].into(), height: 1 }]
);
assert_eq!(Balances::reserved_balance(3), announcements.1);
});
}
@@ -291,11 +297,7 @@ fn proxy_announced_removes_announcement_and_returns_deposit() {
system::Pallet::<Test>::set_block_number(2);
assert_ok!(Proxy::proxy_announced(Origin::signed(0), 3, 1, None, call.clone()));
let announcements = Announcements::<Test>::get(3);
assert_eq!(announcements.0, vec![Announcement {
real: 2,
call_hash,
height: 1,
}]);
assert_eq!(announcements.0, vec![Announcement { real: 2, call_hash, height: 1 }]);
assert_eq!(Balances::reserved_balance(3), announcements.1);
});
}
@@ -330,7 +332,10 @@ fn filtering_works() {
let call = Box::new(Call::Utility(UtilityCall::batch(vec![*inner])));
assert_ok!(Proxy::proxy(Origin::signed(2), 1, None, call.clone()));
expect_events(vec![UtilityEvent::BatchCompleted.into(), ProxyEvent::ProxyExecuted(Ok(())).into()]);
expect_events(vec![
UtilityEvent::BatchCompleted.into(),
ProxyEvent::ProxyExecuted(Ok(())).into(),
]);
assert_ok!(Proxy::proxy(Origin::signed(3), 1, None, call.clone()));
System::assert_last_event(ProxyEvent::ProxyExecuted(Err(DispatchError::BadOrigin)).into());
assert_ok!(Proxy::proxy(Origin::signed(4), 1, None, call.clone()));
@@ -342,7 +347,10 @@ fn filtering_works() {
let inner = Box::new(Call::Proxy(ProxyCall::add_proxy(5, ProxyType::Any, 0)));
let call = Box::new(Call::Utility(UtilityCall::batch(vec![*inner])));
assert_ok!(Proxy::proxy(Origin::signed(2), 1, None, call.clone()));
expect_events(vec![UtilityEvent::BatchCompleted.into(), ProxyEvent::ProxyExecuted(Ok(())).into()]);
expect_events(vec![
UtilityEvent::BatchCompleted.into(),
ProxyEvent::ProxyExecuted(Ok(())).into(),
]);
assert_ok!(Proxy::proxy(Origin::signed(3), 1, None, call.clone()));
System::assert_last_event(ProxyEvent::ProxyExecuted(Err(DispatchError::BadOrigin)).into());
assert_ok!(Proxy::proxy(Origin::signed(4), 1, None, call.clone()));
@@ -357,7 +365,10 @@ fn filtering_works() {
assert_ok!(Proxy::proxy(Origin::signed(4), 1, None, call.clone()));
System::assert_last_event(ProxyEvent::ProxyExecuted(Err(DispatchError::BadOrigin)).into());
assert_ok!(Proxy::proxy(Origin::signed(2), 1, None, call.clone()));
expect_events(vec![BalancesEvent::<Test>::Unreserved(1, 5).into(), ProxyEvent::ProxyExecuted(Ok(())).into()]);
expect_events(vec![
BalancesEvent::<Test>::Unreserved(1, 5).into(),
ProxyEvent::ProxyExecuted(Ok(())).into(),
]);
});
}
@@ -365,7 +376,10 @@ fn filtering_works() {
fn add_remove_proxies_works() {
new_test_ext().execute_with(|| {
assert_ok!(Proxy::add_proxy(Origin::signed(1), 2, ProxyType::Any, 0));
assert_noop!(Proxy::add_proxy(Origin::signed(1), 2, ProxyType::Any, 0), Error::<Test>::Duplicate);
assert_noop!(
Proxy::add_proxy(Origin::signed(1), 2, ProxyType::Any, 0),
Error::<Test>::Duplicate
);
assert_eq!(Balances::reserved_balance(1), 2);
assert_ok!(Proxy::add_proxy(Origin::signed(1), 2, ProxyType::JustTransfer, 0));
assert_eq!(Balances::reserved_balance(1), 3);
@@ -373,8 +387,14 @@ fn add_remove_proxies_works() {
assert_eq!(Balances::reserved_balance(1), 4);
assert_ok!(Proxy::add_proxy(Origin::signed(1), 4, ProxyType::JustUtility, 0));
assert_eq!(Balances::reserved_balance(1), 5);
assert_noop!(Proxy::add_proxy(Origin::signed(1), 4, ProxyType::Any, 0), Error::<Test>::TooMany);
assert_noop!(Proxy::remove_proxy(Origin::signed(1), 3, ProxyType::JustTransfer, 0), Error::<Test>::NotFound);
assert_noop!(
Proxy::add_proxy(Origin::signed(1), 4, ProxyType::Any, 0),
Error::<Test>::TooMany
);
assert_noop!(
Proxy::remove_proxy(Origin::signed(1), 3, ProxyType::JustTransfer, 0),
Error::<Test>::NotFound
);
assert_ok!(Proxy::remove_proxy(Origin::signed(1), 4, ProxyType::JustUtility, 0));
assert_eq!(Balances::reserved_balance(1), 4);
assert_ok!(Proxy::remove_proxy(Origin::signed(1), 3, ProxyType::Any, 0));
@@ -383,7 +403,10 @@ fn add_remove_proxies_works() {
assert_eq!(Balances::reserved_balance(1), 2);
assert_ok!(Proxy::remove_proxy(Origin::signed(1), 2, ProxyType::JustTransfer, 0));
assert_eq!(Balances::reserved_balance(1), 0);
assert_noop!(Proxy::add_proxy(Origin::signed(1), 1, ProxyType::Any, 0), Error::<Test>::NoSelfProxy);
assert_noop!(
Proxy::add_proxy(Origin::signed(1), 1, ProxyType::Any, 0),
Error::<Test>::NoSelfProxy
);
});
}
@@ -406,7 +429,10 @@ fn proxying_works() {
assert_ok!(Proxy::add_proxy(Origin::signed(1), 3, ProxyType::Any, 0));
let call = Box::new(Call::Balances(BalancesCall::transfer(6, 1)));
assert_noop!(Proxy::proxy(Origin::signed(4), 1, None, call.clone()), Error::<Test>::NotProxy);
assert_noop!(
Proxy::proxy(Origin::signed(4), 1, None, call.clone()),
Error::<Test>::NotProxy
);
assert_noop!(
Proxy::proxy(Origin::signed(2), 1, Some(ProxyType::Any), call.clone()),
Error::<Test>::NotProxy
@@ -420,7 +446,9 @@ fn proxying_works() {
System::assert_last_event(ProxyEvent::ProxyExecuted(Err(DispatchError::BadOrigin)).into());
let call = Box::new(Call::Balances(BalancesCall::transfer_keep_alive(6, 1)));
assert_ok!(Call::Proxy(super::Call::proxy(1, None, call.clone())).dispatch(Origin::signed(2)));
assert_ok!(
Call::Proxy(super::Call::proxy(1, None, call.clone())).dispatch(Origin::signed(2))
);
System::assert_last_event(ProxyEvent::ProxyExecuted(Err(DispatchError::BadOrigin)).into());
assert_ok!(Proxy::proxy(Origin::signed(3), 1, None, call.clone()));
System::assert_last_event(ProxyEvent::ProxyExecuted(Ok(())).into());
@@ -433,14 +461,19 @@ fn anonymous_works() {
new_test_ext().execute_with(|| {
assert_ok!(Proxy::anonymous(Origin::signed(1), ProxyType::Any, 0, 0));
let anon = Proxy::anonymous_account(&1, &ProxyType::Any, 0, None);
System::assert_last_event(ProxyEvent::AnonymousCreated(anon.clone(), 1, ProxyType::Any, 0).into());
System::assert_last_event(
ProxyEvent::AnonymousCreated(anon.clone(), 1, ProxyType::Any, 0).into(),
);
// other calls to anonymous allowed as long as they're not exactly the same.
assert_ok!(Proxy::anonymous(Origin::signed(1), ProxyType::JustTransfer, 0, 0));
assert_ok!(Proxy::anonymous(Origin::signed(1), ProxyType::Any, 0, 1));
let anon2 = Proxy::anonymous_account(&2, &ProxyType::Any, 0, None);
assert_ok!(Proxy::anonymous(Origin::signed(2), ProxyType::Any, 0, 0));
assert_noop!(Proxy::anonymous(Origin::signed(1), ProxyType::Any, 0, 0), Error::<Test>::Duplicate);
assert_noop!(
Proxy::anonymous(Origin::signed(1), ProxyType::Any, 0, 0),
Error::<Test>::Duplicate
);
System::set_extrinsic_index(1);
assert_ok!(Proxy::anonymous(Origin::signed(1), ProxyType::Any, 0, 0));
System::set_extrinsic_index(0);
@@ -464,6 +497,9 @@ fn anonymous_works() {
assert_eq!(Balances::free_balance(1), 0);
assert_ok!(Proxy::proxy(Origin::signed(1), anon, None, call.clone()));
assert_eq!(Balances::free_balance(1), 2);
assert_noop!(Proxy::proxy(Origin::signed(1), anon, None, call.clone()), Error::<Test>::NotProxy);
assert_noop!(
Proxy::proxy(Origin::signed(1), anon, None, call.clone()),
Error::<Test>::NotProxy
);
});
}