mirror of
https://github.com/pezkuwichain/pezkuwi-subxt.git
synced 2026-04-26 13:27:57 +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:
@@ -20,10 +20,10 @@
|
||||
#![cfg(feature = "runtime-benchmarks")]
|
||||
|
||||
use super::*;
|
||||
use frame_system::RawOrigin;
|
||||
use frame_benchmarking::{benchmarks, account, whitelisted_caller, impl_benchmark_test_suite};
|
||||
use sp_runtime::traits::Bounded;
|
||||
use crate::Pallet as Proxy;
|
||||
use frame_benchmarking::{account, benchmarks, impl_benchmark_test_suite, whitelisted_caller};
|
||||
use frame_system::RawOrigin;
|
||||
use sp_runtime::traits::Bounded;
|
||||
|
||||
const SEED: u32 = 0;
|
||||
|
||||
@@ -48,7 +48,7 @@ fn add_proxies<T: Config>(n: u32, maybe_who: Option<T::AccountId>) -> Result<(),
|
||||
fn add_announcements<T: Config>(
|
||||
n: u32,
|
||||
maybe_who: Option<T::AccountId>,
|
||||
maybe_real: Option<T::AccountId>
|
||||
maybe_real: Option<T::AccountId>,
|
||||
) -> Result<(), &'static str> {
|
||||
let caller = maybe_who.unwrap_or_else(|| account("caller", 0, SEED));
|
||||
T::Currency::make_free_balance_be(&caller, BalanceOf::<T>::max_value());
|
||||
@@ -247,8 +247,4 @@ benchmarks! {
|
||||
}
|
||||
}
|
||||
|
||||
impl_benchmark_test_suite!(
|
||||
Proxy,
|
||||
crate::tests::new_test_ext(),
|
||||
crate::tests::Test,
|
||||
);
|
||||
impl_benchmark_test_suite!(Proxy, crate::tests::new_test_ext(), crate::tests::Test,);
|
||||
|
||||
@@ -29,39 +29,39 @@
|
||||
// Ensure we're `no_std` when compiling for Wasm.
|
||||
#![cfg_attr(not(feature = "std"), no_std)]
|
||||
|
||||
mod tests;
|
||||
mod benchmarking;
|
||||
mod tests;
|
||||
pub mod weights;
|
||||
|
||||
use sp_std::{prelude::*, convert::TryInto};
|
||||
use codec::{Encode, Decode, MaxEncodedLen};
|
||||
use sp_io::hashing::blake2_256;
|
||||
use sp_runtime::{
|
||||
DispatchResult,
|
||||
traits::{Dispatchable, Zero, Hash, Saturating}
|
||||
};
|
||||
use codec::{Decode, Encode, MaxEncodedLen};
|
||||
use frame_support::{
|
||||
RuntimeDebug, ensure,
|
||||
dispatch::{DispatchResultWithPostInfo, PostDispatchInfo},
|
||||
traits::{
|
||||
Get, ReservableCurrency, Currency, InstanceFilter, OriginTrait,
|
||||
IsType, IsSubType,
|
||||
},
|
||||
weights::GetDispatchInfo,
|
||||
dispatch::{DispatchError, DispatchResultWithPostInfo, PostDispatchInfo},
|
||||
ensure,
|
||||
traits::{Currency, Get, InstanceFilter, IsSubType, IsType, OriginTrait, ReservableCurrency},
|
||||
weights::GetDispatchInfo,
|
||||
RuntimeDebug,
|
||||
};
|
||||
use frame_system::{self as system};
|
||||
use frame_support::dispatch::DispatchError;
|
||||
use sp_io::hashing::blake2_256;
|
||||
use sp_runtime::{
|
||||
traits::{Dispatchable, Hash, Saturating, Zero},
|
||||
DispatchResult,
|
||||
};
|
||||
use sp_std::{convert::TryInto, prelude::*};
|
||||
pub use weights::WeightInfo;
|
||||
|
||||
pub use pallet::*;
|
||||
|
||||
type CallHashOf<T> = <<T as Config>::CallHasher as Hash>::Output;
|
||||
|
||||
type BalanceOf<T> = <<T as Config>::Currency as Currency<<T as frame_system::Config>::AccountId>>::Balance;
|
||||
type BalanceOf<T> =
|
||||
<<T as Config>::Currency as Currency<<T as frame_system::Config>::AccountId>>::Balance;
|
||||
|
||||
/// The parameters under which a particular account has a proxy relationship with some other
|
||||
/// account.
|
||||
#[derive(Encode, Decode, Clone, Copy, Eq, PartialEq, Ord, PartialOrd, RuntimeDebug, MaxEncodedLen)]
|
||||
#[derive(
|
||||
Encode, Decode, Clone, Copy, Eq, PartialEq, Ord, PartialOrd, RuntimeDebug, MaxEncodedLen,
|
||||
)]
|
||||
pub struct ProxyDefinition<AccountId, ProxyType, BlockNumber> {
|
||||
/// The account which may act on behalf of another.
|
||||
pub delegate: AccountId,
|
||||
@@ -85,9 +85,9 @@ pub struct Announcement<AccountId, Hash, BlockNumber> {
|
||||
|
||||
#[frame_support::pallet]
|
||||
pub mod pallet {
|
||||
use super::{DispatchResult, *};
|
||||
use frame_support::pallet_prelude::*;
|
||||
use frame_system::pallet_prelude::*;
|
||||
use super::{*, DispatchResult};
|
||||
|
||||
#[pallet::pallet]
|
||||
#[pallet::generate_store(pub(super) trait Store)]
|
||||
@@ -101,8 +101,11 @@ pub mod pallet {
|
||||
type Event: From<Event<Self>> + IsType<<Self as frame_system::Config>::Event>;
|
||||
|
||||
/// The overarching call type.
|
||||
type Call: Parameter + Dispatchable<Origin=Self::Origin, PostInfo=PostDispatchInfo>
|
||||
+ GetDispatchInfo + From<frame_system::Call<Self>> + IsSubType<Call<Self>>
|
||||
type Call: Parameter
|
||||
+ Dispatchable<Origin = Self::Origin, PostInfo = PostDispatchInfo>
|
||||
+ GetDispatchInfo
|
||||
+ From<frame_system::Call<Self>>
|
||||
+ IsSubType<Call<Self>>
|
||||
+ IsType<<Self as frame_system::Config>::Call>;
|
||||
|
||||
/// The currency mechanism.
|
||||
@@ -112,8 +115,13 @@ pub mod pallet {
|
||||
/// The instance filter determines whether a given call may be proxied under this type.
|
||||
///
|
||||
/// IMPORTANT: `Default` must be provided and MUST BE the the *most permissive* value.
|
||||
type ProxyType: Parameter + Member + Ord + PartialOrd + InstanceFilter<<Self as Config>::Call>
|
||||
+ Default + MaxEncodedLen;
|
||||
type ProxyType: Parameter
|
||||
+ Member
|
||||
+ Ord
|
||||
+ PartialOrd
|
||||
+ InstanceFilter<<Self as Config>::Call>
|
||||
+ Default
|
||||
+ MaxEncodedLen;
|
||||
|
||||
/// The base amount of currency needed to reserve for creating a proxy.
|
||||
///
|
||||
@@ -291,21 +299,17 @@ pub mod pallet {
|
||||
origin: OriginFor<T>,
|
||||
proxy_type: T::ProxyType,
|
||||
delay: T::BlockNumber,
|
||||
index: u16
|
||||
index: u16,
|
||||
) -> DispatchResultWithPostInfo {
|
||||
let who = ensure_signed(origin)?;
|
||||
|
||||
let anonymous = Self::anonymous_account(&who, &proxy_type, index, None);
|
||||
ensure!(!Proxies::<T>::contains_key(&anonymous), Error::<T>::Duplicate);
|
||||
|
||||
let proxy_def = ProxyDefinition {
|
||||
delegate: who.clone(),
|
||||
proxy_type: proxy_type.clone(),
|
||||
delay,
|
||||
};
|
||||
let bounded_proxies: BoundedVec<_, T::MaxProxies> = vec![proxy_def]
|
||||
.try_into()
|
||||
.map_err(|_| Error::<T>::TooMany)?;
|
||||
let proxy_def =
|
||||
ProxyDefinition { delegate: who.clone(), proxy_type: proxy_type.clone(), delay };
|
||||
let bounded_proxies: BoundedVec<_, T::MaxProxies> =
|
||||
vec![proxy_def].try_into().map_err(|_| Error::<T>::TooMany)?;
|
||||
|
||||
let deposit = T::ProxyDepositBase::get() + T::ProxyDepositFactor::get();
|
||||
T::Currency::reserve(&who, deposit)?;
|
||||
@@ -382,10 +386,12 @@ pub mod pallet {
|
||||
pub fn announce(
|
||||
origin: OriginFor<T>,
|
||||
real: T::AccountId,
|
||||
call_hash: CallHashOf<T>
|
||||
) -> DispatchResultWithPostInfo{
|
||||
call_hash: CallHashOf<T>,
|
||||
) -> DispatchResultWithPostInfo {
|
||||
let who = ensure_signed(origin)?;
|
||||
Proxies::<T>::get(&real).0.into_iter()
|
||||
Proxies::<T>::get(&real)
|
||||
.0
|
||||
.into_iter()
|
||||
.find(|x| &x.delegate == &who)
|
||||
.ok_or(Error::<T>::NotProxy)?;
|
||||
|
||||
@@ -403,7 +409,10 @@ pub mod pallet {
|
||||
T::AnnouncementDepositBase::get(),
|
||||
T::AnnouncementDepositFactor::get(),
|
||||
pending.len(),
|
||||
).map(|d| d.expect("Just pushed; pending.len() > 0; rejig_deposit returns Some; qed"))
|
||||
)
|
||||
.map(|d| {
|
||||
d.expect("Just pushed; pending.len() > 0; rejig_deposit returns Some; qed")
|
||||
})
|
||||
.map(|d| *deposit = d)
|
||||
})?;
|
||||
Self::deposit_event(Event::Announced(real, who, call_hash));
|
||||
@@ -433,7 +442,7 @@ pub mod pallet {
|
||||
pub fn remove_announcement(
|
||||
origin: OriginFor<T>,
|
||||
real: T::AccountId,
|
||||
call_hash: CallHashOf<T>
|
||||
call_hash: CallHashOf<T>,
|
||||
) -> DispatchResultWithPostInfo {
|
||||
let who = ensure_signed(origin)?;
|
||||
Self::edit_announcements(&who, |ann| ann.real != real || ann.call_hash != call_hash)?;
|
||||
@@ -463,10 +472,12 @@ pub mod pallet {
|
||||
pub fn reject_announcement(
|
||||
origin: OriginFor<T>,
|
||||
delegate: T::AccountId,
|
||||
call_hash: CallHashOf<T>
|
||||
call_hash: CallHashOf<T>,
|
||||
) -> DispatchResultWithPostInfo {
|
||||
let who = ensure_signed(origin)?;
|
||||
Self::edit_announcements(&delegate, |ann| ann.real != who || ann.call_hash != call_hash)?;
|
||||
Self::edit_announcements(&delegate, |ann| {
|
||||
ann.real != who || ann.call_hash != call_hash
|
||||
})?;
|
||||
|
||||
Ok(().into())
|
||||
}
|
||||
@@ -508,9 +519,12 @@ pub mod pallet {
|
||||
|
||||
let call_hash = T::CallHasher::hash_of(&call);
|
||||
let now = system::Pallet::<T>::block_number();
|
||||
Self::edit_announcements(&delegate, |ann|
|
||||
ann.real != real || ann.call_hash != call_hash || now.saturating_sub(ann.height) < def.delay
|
||||
).map_err(|_| Error::<T>::Unannounced)?;
|
||||
Self::edit_announcements(&delegate, |ann| {
|
||||
ann.real != real ||
|
||||
ann.call_hash != call_hash ||
|
||||
now.saturating_sub(ann.height) < def.delay
|
||||
})
|
||||
.map_err(|_| Error::<T>::Unannounced)?;
|
||||
|
||||
Self::do_proxy(def, real, *call);
|
||||
|
||||
@@ -521,8 +535,7 @@ pub mod pallet {
|
||||
#[pallet::event]
|
||||
#[pallet::metadata(T::AccountId = "AccountId", T::ProxyType = "ProxyType", CallHashOf<T> = "Hash")]
|
||||
#[pallet::generate_deposit(pub(super) fn deposit_event)]
|
||||
pub enum Event<T: Config>
|
||||
{
|
||||
pub enum Event<T: Config> {
|
||||
/// A proxy was executed correctly, with the given \[result\].
|
||||
ProxyExecuted(DispatchResult),
|
||||
/// Anonymous account has been created by new proxy with given
|
||||
@@ -533,10 +546,10 @@ pub mod pallet {
|
||||
}
|
||||
|
||||
/// Old name generated by `decl_event`.
|
||||
#[deprecated(note="use `Event` instead")]
|
||||
#[deprecated(note = "use `Event` instead")]
|
||||
pub type RawEvent<T> = Event<T>;
|
||||
|
||||
#[pallet::error]
|
||||
#[pallet::error]
|
||||
pub enum Error<T> {
|
||||
/// There are too many proxies registered or too many announcements pending.
|
||||
TooMany,
|
||||
@@ -565,13 +578,10 @@ pub mod pallet {
|
||||
Twox64Concat,
|
||||
T::AccountId,
|
||||
(
|
||||
BoundedVec<
|
||||
ProxyDefinition<T::AccountId, T::ProxyType, T::BlockNumber>,
|
||||
T::MaxProxies,
|
||||
>,
|
||||
BalanceOf<T>
|
||||
BoundedVec<ProxyDefinition<T::AccountId, T::ProxyType, T::BlockNumber>, T::MaxProxies>,
|
||||
BalanceOf<T>,
|
||||
),
|
||||
ValueQuery
|
||||
ValueQuery,
|
||||
>;
|
||||
|
||||
/// The announcements made by the proxy (key).
|
||||
@@ -582,19 +592,14 @@ pub mod pallet {
|
||||
Twox64Concat,
|
||||
T::AccountId,
|
||||
(
|
||||
BoundedVec<
|
||||
Announcement<T::AccountId, CallHashOf<T>, T::BlockNumber>,
|
||||
T::MaxPending,
|
||||
>,
|
||||
BoundedVec<Announcement<T::AccountId, CallHashOf<T>, T::BlockNumber>, T::MaxPending>,
|
||||
BalanceOf<T>,
|
||||
),
|
||||
ValueQuery
|
||||
ValueQuery,
|
||||
>;
|
||||
|
||||
}
|
||||
|
||||
impl<T: Config> Pallet<T> {
|
||||
|
||||
/// Calculate the address of an anonymous account.
|
||||
///
|
||||
/// - `who`: The spawner account.
|
||||
@@ -612,10 +617,12 @@ impl<T: Config> Pallet<T> {
|
||||
index: u16,
|
||||
maybe_when: Option<(T::BlockNumber, u32)>,
|
||||
) -> T::AccountId {
|
||||
let (height, ext_index) = maybe_when.unwrap_or_else(|| (
|
||||
system::Pallet::<T>::block_number(),
|
||||
system::Pallet::<T>::extrinsic_index().unwrap_or_default()
|
||||
));
|
||||
let (height, ext_index) = maybe_when.unwrap_or_else(|| {
|
||||
(
|
||||
system::Pallet::<T>::block_number(),
|
||||
system::Pallet::<T>::extrinsic_index().unwrap_or_default(),
|
||||
)
|
||||
});
|
||||
let entropy = (b"modlpy/proxy____", who, height, ext_index, proxy_type, index)
|
||||
.using_encoded(blake2_256);
|
||||
T::AccountId::decode(&mut &entropy[..]).unwrap_or_default()
|
||||
@@ -698,26 +705,22 @@ impl<T: Config> Pallet<T> {
|
||||
factor: BalanceOf<T>,
|
||||
len: usize,
|
||||
) -> Result<Option<BalanceOf<T>>, DispatchError> {
|
||||
let new_deposit = if len == 0 {
|
||||
BalanceOf::<T>::zero()
|
||||
} else {
|
||||
base + factor * (len as u32).into()
|
||||
};
|
||||
let new_deposit =
|
||||
if len == 0 { BalanceOf::<T>::zero() } else { base + factor * (len as u32).into() };
|
||||
if new_deposit > old_deposit {
|
||||
T::Currency::reserve(&who, new_deposit - old_deposit)?;
|
||||
} else if new_deposit < old_deposit {
|
||||
T::Currency::unreserve(&who, old_deposit - new_deposit);
|
||||
}
|
||||
Ok(if len == 0 {
|
||||
None
|
||||
} else {
|
||||
Some(new_deposit)
|
||||
})
|
||||
Ok(if len == 0 { None } else { Some(new_deposit) })
|
||||
}
|
||||
|
||||
fn edit_announcements<
|
||||
F: FnMut(&Announcement<T::AccountId, CallHashOf<T>, T::BlockNumber>) -> bool
|
||||
>(delegate: &T::AccountId, f: F) -> DispatchResult {
|
||||
F: FnMut(&Announcement<T::AccountId, CallHashOf<T>, T::BlockNumber>) -> bool,
|
||||
>(
|
||||
delegate: &T::AccountId,
|
||||
f: F,
|
||||
) -> DispatchResult {
|
||||
Announcements::<T>::try_mutate_exists(delegate, |x| {
|
||||
let (mut pending, old_deposit) = x.take().ok_or(Error::<T>::NotFound)?;
|
||||
let orig_pending_len = pending.len();
|
||||
@@ -729,7 +732,8 @@ impl<T: Config> Pallet<T> {
|
||||
T::AnnouncementDepositBase::get(),
|
||||
T::AnnouncementDepositFactor::get(),
|
||||
pending.len(),
|
||||
)?.map(|deposit| (pending, deposit));
|
||||
)?
|
||||
.map(|deposit| (pending, deposit));
|
||||
Ok(())
|
||||
})
|
||||
}
|
||||
@@ -740,7 +744,8 @@ impl<T: Config> Pallet<T> {
|
||||
force_proxy_type: Option<T::ProxyType>,
|
||||
) -> Result<ProxyDefinition<T::AccountId, T::ProxyType, T::BlockNumber>, DispatchError> {
|
||||
let f = |x: &ProxyDefinition<T::AccountId, T::ProxyType, T::BlockNumber>| -> bool {
|
||||
&x.delegate == delegate && force_proxy_type.as_ref().map_or(true, |y| &x.proxy_type == y)
|
||||
&x.delegate == delegate &&
|
||||
force_proxy_type.as_ref().map_or(true, |y| &x.proxy_type == y)
|
||||
};
|
||||
Ok(Proxies::<T>::get(real).0.into_iter().find(f).ok_or(Error::<T>::NotProxy)?)
|
||||
}
|
||||
@@ -758,11 +763,13 @@ impl<T: Config> Pallet<T> {
|
||||
match c.is_sub_type() {
|
||||
// Proxy call cannot add or remove a proxy with more permissions than it already has.
|
||||
Some(Call::add_proxy(_, ref pt, _)) | Some(Call::remove_proxy(_, ref pt, _))
|
||||
if !def.proxy_type.is_superset(&pt) => false,
|
||||
if !def.proxy_type.is_superset(&pt) =>
|
||||
false,
|
||||
// Proxy call cannot remove all proxies or kill anonymous proxies unless it has full permissions.
|
||||
Some(Call::remove_proxies(..)) | Some(Call::kill_anonymous(..))
|
||||
if def.proxy_type != T::ProxyType::default() => false,
|
||||
_ => def.proxy_type.filter(c)
|
||||
if def.proxy_type != T::ProxyType::default() =>
|
||||
false,
|
||||
_ => def.proxy_type.filter(c),
|
||||
}
|
||||
});
|
||||
let e = call.dispatch(origin);
|
||||
|
||||
@@ -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
|
||||
);
|
||||
});
|
||||
}
|
||||
|
||||
@@ -36,6 +36,7 @@
|
||||
// --template=./.maintain/frame-weight-template.hbs
|
||||
|
||||
|
||||
#![cfg_attr(rustfmt, rustfmt_skip)]
|
||||
#![allow(unused_parens)]
|
||||
#![allow(unused_imports)]
|
||||
|
||||
|
||||
Reference in New Issue
Block a user