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
+4 -4
View File
@@ -25,9 +25,9 @@ use frame_benchmarking::{benchmarks, account, whitelisted_caller};
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);
@@ -38,7 +38,7 @@ benchmarks! {
batch {
let c in 0 .. 1000;
let mut calls: Vec<<T as Trait>::Call> = Vec::new();
let mut calls: Vec<<T as Config>::Call> = Vec::new();
for i in 0 .. c {
let call = frame_system::Call::remark(vec![]).into();
calls.push(call);
@@ -59,7 +59,7 @@ benchmarks! {
batch_all {
let c in 0 .. 1000;
let mut calls: Vec<<T as Trait>::Call> = Vec::new();
let mut calls: Vec<<T as Config>::Call> = Vec::new();
for i in 0 .. c {
let call = frame_system::Call::remark(vec![]).into();
calls.push(call);
+12 -12
View File
@@ -18,7 +18,7 @@
//! # Utility Module
//! A stateless module with helpers for dispatch management which does no re-authentication.
//!
//! - [`utility::Trait`](./trait.Trait.html)
//! - [`utility::Config`](./trait.Config.html)
//! - [`Call`](./enum.Call.html)
//!
//! ## Overview
@@ -50,7 +50,7 @@
//! * `as_derivative` - Dispatch a call from a derivative signed origin.
//!
//! [`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)]
@@ -74,9 +74,9 @@ use sp_runtime::{DispatchError, traits::Dispatchable};
pub use weights::WeightInfo;
/// Configuration trait.
pub trait Trait: frame_system::Trait {
pub trait Config: frame_system::Config {
/// The overarching event type.
type Event: From<Event> + Into<<Self as frame_system::Trait>::Event>;
type Event: From<Event> + Into<<Self as frame_system::Config>::Event>;
/// The overarching call type.
type Call: Parameter + Dispatchable<Origin=Self::Origin, PostInfo=PostDispatchInfo>
@@ -88,7 +88,7 @@ pub trait Trait: frame_system::Trait {
}
decl_storage! {
trait Store for Module<T: Trait> as Utility {}
trait Store for Module<T: Config> as Utility {}
}
decl_event! {
@@ -111,7 +111,7 @@ impl TypeId for IndexedUtilityModuleId {
}
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 {
/// Deposit one of this module's events by using the default implementation.
fn deposit_event() = default;
@@ -122,7 +122,7 @@ decl_module! {
/// - `calls`: The calls to be dispatched from the same origin.
///
/// If origin is root then call are dispatch without checking origin filter. (This includes
/// bypassing `frame_system::Trait::BaseCallFilter`).
/// bypassing `frame_system::Config::BaseCallFilter`).
///
/// # <weight>
/// - Complexity: O(C) where C is the number of calls to be batched.
@@ -149,7 +149,7 @@ decl_module! {
}
},
)]
fn batch(origin, calls: Vec<<T as Trait>::Call>) -> DispatchResultWithPostInfo {
fn batch(origin, calls: Vec<<T as Config>::Call>) -> DispatchResultWithPostInfo {
let is_root = ensure_root(origin.clone()).is_ok();
let calls_len = calls.len();
// Track the actual weight of each of the batch calls.
@@ -197,7 +197,7 @@ decl_module! {
.saturating_add(T::DbWeight::get().reads_writes(1, 1)),
call.get_dispatch_info().class,
)]
fn as_derivative(origin, index: u16, call: Box<<T as Trait>::Call>) -> DispatchResultWithPostInfo {
fn as_derivative(origin, index: u16, call: Box<<T as Config>::Call>) -> DispatchResultWithPostInfo {
let mut origin = origin;
let who = ensure_signed(origin.clone())?;
let pseudonym = Self::derivative_account_id(who, index);
@@ -222,7 +222,7 @@ decl_module! {
/// - `calls`: The calls to be dispatched from the same origin.
///
/// If origin is root then call are dispatch without checking origin filter. (This includes
/// bypassing `frame_system::Trait::BaseCallFilter`).
/// bypassing `frame_system::Config::BaseCallFilter`).
///
/// # <weight>
/// - Complexity: O(C) where C is the number of calls to be batched.
@@ -244,7 +244,7 @@ decl_module! {
},
)]
#[transactional]
fn batch_all(origin, calls: Vec<<T as Trait>::Call>) -> DispatchResultWithPostInfo {
fn batch_all(origin, calls: Vec<<T as Config>::Call>) -> DispatchResultWithPostInfo {
let is_root = ensure_root(origin.clone()).is_ok();
let calls_len = calls.len();
// Track the actual weight of each of the batch calls.
@@ -274,7 +274,7 @@ decl_module! {
}
}
impl<T: Trait> Module<T> {
impl<T: Config> Module<T> {
/// Derive a derivative account ID from the owner account and the sub-account index.
pub fn derivative_account_id(who: T::AccountId, index: u16) -> T::AccountId {
let entropy = (b"modlpy/utilisuba", who, index).using_encoded(blake2_256);
+9 -9
View File
@@ -37,10 +37,10 @@ use crate as utility;
pub mod example {
use super::*;
use frame_support::dispatch::WithPostDispatchInfo;
pub trait Trait: frame_system::Trait { }
pub trait Config: frame_system::Config { }
decl_module! {
pub struct Module<T: Trait> for enum Call where origin: <T as frame_system::Trait>::Origin {
pub struct Module<T: Config> for enum Call where origin: <T as frame_system::Config>::Origin {
#[weight = *weight]
fn noop(_origin, weight: Weight) { }
@@ -97,7 +97,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 = TestBaseCallFilter;
type Origin = Origin;
type Index = u64;
@@ -127,7 +127,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 DustRemoval = ();
@@ -142,7 +142,7 @@ parameter_types! {
pub const MaxSignatories: u16 = 3;
}
impl example::Trait for Test {}
impl example::Config for Test {}
pub struct TestBaseCallFilter;
impl Filter<Call> for TestBaseCallFilter {
@@ -158,7 +158,7 @@ impl Filter<Call> for TestBaseCallFilter {
}
}
}
impl Trait for Test {
impl Config for Test {
type Event = TestEvent;
type Call = Call;
type WeightInfo = ();
@@ -428,7 +428,7 @@ fn batch_handles_weight_refund() {
assert_eq!(
extract_actual_weight(&result, &info),
// Real weight is 2 calls at end_weight
<Test as Trait>::WeightInfo::batch(2) + end_weight * 2,
<Test as Config>::WeightInfo::batch(2) + end_weight * 2,
);
});
}
@@ -465,7 +465,7 @@ fn batch_all_revert() {
]),
DispatchErrorWithPostInfo {
post_info: PostDispatchInfo {
actual_weight: Some(<Test as Trait>::WeightInfo::batch_all(2) + info.weight * 2),
actual_weight: Some(<Test as Config>::WeightInfo::batch_all(2) + info.weight * 2),
pays_fee: Pays::Yes
},
error: pallet_balances::Error::<Test, _>::InsufficientBalance.into()
@@ -536,7 +536,7 @@ fn batch_all_handles_weight_refund() {
assert_eq!(
extract_actual_weight(&result, &info),
// Real weight is 2 calls at end_weight
<Test as Trait>::WeightInfo::batch_all(2) + end_weight * 2,
<Test as Config>::WeightInfo::batch_all(2) + end_weight * 2,
);
});
}
+1 -1
View File
@@ -51,7 +51,7 @@ pub trait WeightInfo {
/// Weights for pallet_utility 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 batch(c: u32, ) -> Weight {
(20_071_000 as Weight)
.saturating_add((2_739_000 as Weight).saturating_mul(c as Weight))