Rename pallet trait Trait to Config (#7599)

* rename Trait to Config

* add test asserting using Trait is still valid.

* fix ui tests
This commit is contained in:
Guillaume Thiolliere
2020-11-30 15:34:54 +01:00
committed by GitHub
parent dd3c84c362
commit 1cbfc9257f
200 changed files with 1767 additions and 1607 deletions
+9 -9
View File
@@ -27,15 +27,15 @@ use crate::Module as Proxy;
const SEED: u32 = 0;
fn assert_last_event<T: Trait>(generic_event: <T as Trait>::Event) {
fn assert_last_event<T: Config>(generic_event: <T as Config>::Event) {
let events = frame_system::Module::<T>::events();
let system_event: <T as frame_system::Trait>::Event = generic_event.into();
let system_event: <T as frame_system::Config>::Event = generic_event.into();
// compare to the last event record
let EventRecord { event, .. } = &events[events.len() - 1];
assert_eq!(event, &system_event);
}
fn add_proxies<T: Trait>(n: u32, maybe_who: Option<T::AccountId>) -> Result<(), &'static str> {
fn add_proxies<T: Config>(n: u32, maybe_who: Option<T::AccountId>) -> Result<(), &'static str> {
let caller = maybe_who.unwrap_or_else(|| whitelisted_caller());
T::Currency::make_free_balance_be(&caller, BalanceOf::<T>::max_value());
for i in 0..n {
@@ -49,7 +49,7 @@ fn add_proxies<T: Trait>(n: u32, maybe_who: Option<T::AccountId>) -> Result<(),
Ok(())
}
fn add_announcements<T: Trait>(
fn add_announcements<T: Config>(
n: u32,
maybe_who: Option<T::AccountId>,
maybe_real: Option<T::AccountId>
@@ -91,7 +91,7 @@ benchmarks! {
T::Currency::make_free_balance_be(&caller, BalanceOf::<T>::max_value());
// ... and "real" is the traditional caller. This is not a typo.
let real: T::AccountId = whitelisted_caller();
let call: <T as Trait>::Call = frame_system::Call::<T>::remark(vec![]).into();
let call: <T as Config>::Call = frame_system::Call::<T>::remark(vec![]).into();
}: _(RawOrigin::Signed(caller), real, Some(T::ProxyType::default()), Box::new(call))
verify {
assert_last_event::<T>(RawEvent::ProxyExecuted(Ok(())).into())
@@ -106,7 +106,7 @@ benchmarks! {
T::Currency::make_free_balance_be(&delegate, BalanceOf::<T>::max_value());
// ... and "real" is the traditional caller. This is not a typo.
let real: T::AccountId = whitelisted_caller();
let call: <T as Trait>::Call = frame_system::Call::<T>::remark(vec![]).into();
let call: <T as Config>::Call = frame_system::Call::<T>::remark(vec![]).into();
Proxy::<T>::announce(
RawOrigin::Signed(delegate.clone()).into(),
real.clone(),
@@ -126,7 +126,7 @@ benchmarks! {
T::Currency::make_free_balance_be(&caller, BalanceOf::<T>::max_value());
// ... and "real" is the traditional caller. This is not a typo.
let real: T::AccountId = whitelisted_caller();
let call: <T as Trait>::Call = frame_system::Call::<T>::remark(vec![]).into();
let call: <T as Config>::Call = frame_system::Call::<T>::remark(vec![]).into();
Proxy::<T>::announce(
RawOrigin::Signed(caller.clone()).into(),
real.clone(),
@@ -147,7 +147,7 @@ benchmarks! {
T::Currency::make_free_balance_be(&caller, BalanceOf::<T>::max_value());
// ... and "real" is the traditional caller. This is not a typo.
let real: T::AccountId = whitelisted_caller();
let call: <T as Trait>::Call = frame_system::Call::<T>::remark(vec![]).into();
let call: <T as Config>::Call = frame_system::Call::<T>::remark(vec![]).into();
Proxy::<T>::announce(
RawOrigin::Signed(caller.clone()).into(),
real.clone(),
@@ -169,7 +169,7 @@ benchmarks! {
// ... and "real" is the traditional caller. This is not a typo.
let real: T::AccountId = whitelisted_caller();
add_announcements::<T>(a, Some(caller.clone()), None)?;
let call: <T as Trait>::Call = frame_system::Call::<T>::remark(vec![]).into();
let call: <T as Config>::Call = frame_system::Call::<T>::remark(vec![]).into();
let call_hash = T::CallHasher::hash_of(&call);
}: _(RawOrigin::Signed(caller.clone()), real.clone(), call_hash)
verify {
+20 -20
View File
@@ -23,7 +23,7 @@
//! wish to execute some duration prior to execution happens. In this case, the target account may
//! reject the announcement and in doing so, veto the execution.
//!
//! - [`proxy::Trait`](./trait.Trait.html)
//! - [`proxy::Config`](./trait.Config.html)
//! - [`Call`](./enum.Call.html)
//!
//! ## Overview
@@ -33,7 +33,7 @@
//! ### Dispatchable Functions
//!
//! [`Call`]: ./enum.Call.html
//! [`Trait`]: ./trait.Trait.html
//! [`Config`]: ./trait.Config.html
// Ensure we're `no_std` when compiling for Wasm.
#![cfg_attr(not(feature = "std"), no_std)]
@@ -55,17 +55,17 @@ use frame_system::{self as system, ensure_signed};
use frame_support::dispatch::DispatchError;
pub use weights::WeightInfo;
type BalanceOf<T> = <<T as Trait>::Currency as Currency<<T as frame_system::Trait>::AccountId>>::Balance;
type BalanceOf<T> = <<T as Config>::Currency as Currency<<T as frame_system::Config>::AccountId>>::Balance;
/// Configuration trait.
pub trait Trait: frame_system::Trait {
pub trait Config: frame_system::Config {
/// The overarching event type.
type Event: From<Event<Self>> + Into<<Self as frame_system::Trait>::Event>;
type Event: From<Event<Self>> + Into<<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>>
+ IsType<<Self as frame_system::Trait>::Call>;
+ IsType<<Self as frame_system::Config>::Call>;
/// The currency mechanism.
type Currency: ReservableCurrency<Self::AccountId>;
@@ -74,7 +74,7 @@ pub trait Trait: frame_system::Trait {
/// 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 Trait>::Call>
type ProxyType: Parameter + Member + Ord + PartialOrd + InstanceFilter<<Self as Config>::Call>
+ Default;
/// The base amount of currency needed to reserve for creating a proxy.
@@ -137,10 +137,10 @@ pub struct Announcement<AccountId, Hash, BlockNumber> {
height: BlockNumber,
}
type CallHashOf<T> = <<T as Trait>::CallHasher as Hash>::Output;
type CallHashOf<T> = <<T as Config>::CallHasher as Hash>::Output;
decl_storage! {
trait Store for Module<T: Trait> as Proxy {
trait Store for Module<T: Config> as Proxy {
/// The set of account proxies. Maps the account which has delegated to the accounts
/// which are being delegated to, together with the amount held on deposit.
pub Proxies get(fn proxies): map hasher(twox_64_concat) T::AccountId
@@ -153,7 +153,7 @@ decl_storage! {
}
decl_error! {
pub enum Error for Module<T: Trait> {
pub enum Error for Module<T: Config> {
/// There are too many proxies registered or too many announcements pending.
TooMany,
/// Proxy registration not found.
@@ -174,8 +174,8 @@ decl_error! {
decl_event! {
/// Events type.
pub enum Event<T> where
AccountId = <T as frame_system::Trait>::AccountId,
ProxyType = <T as Trait>::ProxyType,
AccountId = <T as frame_system::Config>::AccountId,
ProxyType = <T as Config>::ProxyType,
Hash = CallHashOf<T>,
{
/// A proxy was executed correctly, with the given \[result\].
@@ -189,7 +189,7 @@ decl_event! {
}
decl_module! {
pub struct Module<T: Trait> for enum Call where origin: T::Origin {
pub struct Module<T: Config> for enum Call where origin: T::Origin {
type Error = Error<T>;
/// Deposit one of this module's events by using the default implementation.
@@ -239,7 +239,7 @@ decl_module! {
fn proxy(origin,
real: T::AccountId,
force_proxy_type: Option<T::ProxyType>,
call: Box<<T as Trait>::Call>,
call: Box<<T as Config>::Call>,
) {
let who = ensure_signed(origin)?;
let def = Self::find_proxy(&real, &who, force_proxy_type)?;
@@ -509,7 +509,7 @@ decl_module! {
delegate: T::AccountId,
real: T::AccountId,
force_proxy_type: Option<T::ProxyType>,
call: Box<<T as Trait>::Call>,
call: Box<<T as Config>::Call>,
) {
ensure_signed(origin)?;
let def = Self::find_proxy(&real, &delegate, force_proxy_type)?;
@@ -525,7 +525,7 @@ decl_module! {
}
}
impl<T: Trait> Module<T> {
impl<T: Config> Module<T> {
/// Calculate the address of an anonymous account.
///
@@ -680,12 +680,12 @@ impl<T: Trait> Module<T> {
fn do_proxy(
def: ProxyDefinition<T::AccountId, T::ProxyType, T::BlockNumber>,
real: T::AccountId,
call: <T as Trait>::Call,
call: <T as Config>::Call,
) {
// This is a freshly authenticated new account, the origin restrictions doesn't apply.
let mut origin: T::Origin = frame_system::RawOrigin::Signed(real).into();
origin.add_filter(move |c: &<T as frame_system::Trait>::Call| {
let c = <T as Trait>::Call::from_ref(c);
origin.add_filter(move |c: &<T as frame_system::Config>::Call| {
let c = <T as Config>::Call::from_ref(c);
// We make sure the proxy call does access this pallet to change modify proxies.
match c.is_sub_type() {
// Proxy call cannot add or remove a proxy with more permissions than it already has.
@@ -714,7 +714,7 @@ pub mod migration {
/// `ProxyDefinition` which additionally included a `BlockNumber` delay value. This function,
/// simply takes any existing proxies using the old tuple format, and migrates it to the new
/// struct by setting the delay to zero.
pub fn migrate_to_time_delayed_proxies<T: Trait>() -> Weight {
pub fn migrate_to_time_delayed_proxies<T: Config>() -> Weight {
Proxies::<T>::translate::<(Vec<(T::AccountId, T::ProxyType)>, BalanceOf<T>), _>(
|_, (targets, deposit)| Some((
targets.into_iter()
+4 -4
View File
@@ -61,7 +61,7 @@ parameter_types! {
pub const MaximumBlockLength: u32 = 2 * 1024;
pub const AvailableBlockRatio: Perbill = Perbill::one();
}
impl frame_system::Trait for Test {
impl frame_system::Config for Test {
type BaseCallFilter = BaseFilter;
type Origin = Origin;
type Index = u64;
@@ -91,7 +91,7 @@ impl frame_system::Trait for Test {
parameter_types! {
pub const ExistentialDeposit: u64 = 1;
}
impl pallet_balances::Trait for Test {
impl pallet_balances::Config for Test {
type MaxLocks = ();
type Balance = u64;
type Event = TestEvent;
@@ -100,7 +100,7 @@ impl pallet_balances::Trait for Test {
type AccountStore = System;
type WeightInfo = ();
}
impl pallet_utility::Trait for Test {
impl pallet_utility::Config for Test {
type Event = TestEvent;
type Call = Call;
type WeightInfo = ();
@@ -143,7 +143,7 @@ impl Filter<Call> for BaseFilter {
}
}
}
impl Trait for Test {
impl Config for Test {
type Event = TestEvent;
type Call = Call;
type Currency = Balances;
+1 -1
View File
@@ -58,7 +58,7 @@ pub trait WeightInfo {
/// Weights for pallet_proxy using the Substrate node and recommended hardware.
pub struct SubstrateWeight<T>(PhantomData<T>);
impl<T: frame_system::Trait> WeightInfo for SubstrateWeight<T> {
impl<T: frame_system::Config> WeightInfo for SubstrateWeight<T> {
fn proxy(p: u32, ) -> Weight {
(32_194_000 as Weight)
.saturating_add((215_000 as Weight).saturating_mul(p as Weight))