Skip to content

Commit 3dcd297

Browse files
authored
Rename pallet trait Trait to Config (#7599)
* rename Trait to Config * add test asserting using Trait is still valid. * fix ui tests
1 parent 5ab38aa commit 3dcd297

File tree

4 files changed

+26
-26
lines changed

4 files changed

+26
-26
lines changed

src/benchmarking.rs

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -25,9 +25,9 @@ use frame_benchmarking::{benchmarks, account, whitelisted_caller};
2525

2626
const SEED: u32 = 0;
2727

28-
fn assert_last_event<T: Trait>(generic_event: <T as Trait>::Event) {
28+
fn assert_last_event<T: Config>(generic_event: <T as Config>::Event) {
2929
let events = frame_system::Module::<T>::events();
30-
let system_event: <T as frame_system::Trait>::Event = generic_event.into();
30+
let system_event: <T as frame_system::Config>::Event = generic_event.into();
3131
// compare to the last event record
3232
let EventRecord { event, .. } = &events[events.len() - 1];
3333
assert_eq!(event, &system_event);
@@ -38,7 +38,7 @@ benchmarks! {
3838

3939
batch {
4040
let c in 0 .. 1000;
41-
let mut calls: Vec<<T as Trait>::Call> = Vec::new();
41+
let mut calls: Vec<<T as Config>::Call> = Vec::new();
4242
for i in 0 .. c {
4343
let call = frame_system::Call::remark(vec![]).into();
4444
calls.push(call);
@@ -59,7 +59,7 @@ benchmarks! {
5959

6060
batch_all {
6161
let c in 0 .. 1000;
62-
let mut calls: Vec<<T as Trait>::Call> = Vec::new();
62+
let mut calls: Vec<<T as Config>::Call> = Vec::new();
6363
for i in 0 .. c {
6464
let call = frame_system::Call::remark(vec![]).into();
6565
calls.push(call);

src/lib.rs

Lines changed: 12 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -18,7 +18,7 @@
1818
//! # Utility Module
1919
//! A stateless module with helpers for dispatch management which does no re-authentication.
2020
//!
21-
//! - [`utility::Trait`](./trait.Trait.html)
21+
//! - [`utility::Config`](./trait.Config.html)
2222
//! - [`Call`](./enum.Call.html)
2323
//!
2424
//! ## Overview
@@ -50,7 +50,7 @@
5050
//! * `as_derivative` - Dispatch a call from a derivative signed origin.
5151
//!
5252
//! [`Call`]: ./enum.Call.html
53-
//! [`Trait`]: ./trait.Trait.html
53+
//! [`Config`]: ./trait.Config.html
5454
5555
// Ensure we're `no_std` when compiling for Wasm.
5656
#![cfg_attr(not(feature = "std"), no_std)]
@@ -74,9 +74,9 @@ use sp_runtime::{DispatchError, traits::Dispatchable};
7474
pub use weights::WeightInfo;
7575

7676
/// Configuration trait.
77-
pub trait Trait: frame_system::Trait {
77+
pub trait Config: frame_system::Config {
7878
/// The overarching event type.
79-
type Event: From<Event> + Into<<Self as frame_system::Trait>::Event>;
79+
type Event: From<Event> + Into<<Self as frame_system::Config>::Event>;
8080

8181
/// The overarching call type.
8282
type Call: Parameter + Dispatchable<Origin=Self::Origin, PostInfo=PostDispatchInfo>
@@ -88,7 +88,7 @@ pub trait Trait: frame_system::Trait {
8888
}
8989

9090
decl_storage! {
91-
trait Store for Module<T: Trait> as Utility {}
91+
trait Store for Module<T: Config> as Utility {}
9292
}
9393

9494
decl_event! {
@@ -111,7 +111,7 @@ impl TypeId for IndexedUtilityModuleId {
111111
}
112112

113113
decl_module! {
114-
pub struct Module<T: Trait> for enum Call where origin: T::Origin {
114+
pub struct Module<T: Config> for enum Call where origin: T::Origin {
115115
/// Deposit one of this module's events by using the default implementation.
116116
fn deposit_event() = default;
117117

@@ -122,7 +122,7 @@ decl_module! {
122122
/// - `calls`: The calls to be dispatched from the same origin.
123123
///
124124
/// If origin is root then call are dispatch without checking origin filter. (This includes
125-
/// bypassing `frame_system::Trait::BaseCallFilter`).
125+
/// bypassing `frame_system::Config::BaseCallFilter`).
126126
///
127127
/// # <weight>
128128
/// - Complexity: O(C) where C is the number of calls to be batched.
@@ -149,7 +149,7 @@ decl_module! {
149149
}
150150
},
151151
)]
152-
fn batch(origin, calls: Vec<<T as Trait>::Call>) -> DispatchResultWithPostInfo {
152+
fn batch(origin, calls: Vec<<T as Config>::Call>) -> DispatchResultWithPostInfo {
153153
let is_root = ensure_root(origin.clone()).is_ok();
154154
let calls_len = calls.len();
155155
// Track the actual weight of each of the batch calls.
@@ -197,7 +197,7 @@ decl_module! {
197197
.saturating_add(T::DbWeight::get().reads_writes(1, 1)),
198198
call.get_dispatch_info().class,
199199
)]
200-
fn as_derivative(origin, index: u16, call: Box<<T as Trait>::Call>) -> DispatchResultWithPostInfo {
200+
fn as_derivative(origin, index: u16, call: Box<<T as Config>::Call>) -> DispatchResultWithPostInfo {
201201
let mut origin = origin;
202202
let who = ensure_signed(origin.clone())?;
203203
let pseudonym = Self::derivative_account_id(who, index);
@@ -222,7 +222,7 @@ decl_module! {
222222
/// - `calls`: The calls to be dispatched from the same origin.
223223
///
224224
/// If origin is root then call are dispatch without checking origin filter. (This includes
225-
/// bypassing `frame_system::Trait::BaseCallFilter`).
225+
/// bypassing `frame_system::Config::BaseCallFilter`).
226226
///
227227
/// # <weight>
228228
/// - Complexity: O(C) where C is the number of calls to be batched.
@@ -244,7 +244,7 @@ decl_module! {
244244
},
245245
)]
246246
#[transactional]
247-
fn batch_all(origin, calls: Vec<<T as Trait>::Call>) -> DispatchResultWithPostInfo {
247+
fn batch_all(origin, calls: Vec<<T as Config>::Call>) -> DispatchResultWithPostInfo {
248248
let is_root = ensure_root(origin.clone()).is_ok();
249249
let calls_len = calls.len();
250250
// Track the actual weight of each of the batch calls.
@@ -274,7 +274,7 @@ decl_module! {
274274
}
275275
}
276276

277-
impl<T: Trait> Module<T> {
277+
impl<T: Config> Module<T> {
278278
/// Derive a derivative account ID from the owner account and the sub-account index.
279279
pub fn derivative_account_id(who: T::AccountId, index: u16) -> T::AccountId {
280280
let entropy = (b"modlpy/utilisuba", who, index).using_encoded(blake2_256);

src/tests.rs

Lines changed: 9 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -37,10 +37,10 @@ use crate as utility;
3737
pub mod example {
3838
use super::*;
3939
use frame_support::dispatch::WithPostDispatchInfo;
40-
pub trait Trait: frame_system::Trait { }
40+
pub trait Config: frame_system::Config { }
4141

4242
decl_module! {
43-
pub struct Module<T: Trait> for enum Call where origin: <T as frame_system::Trait>::Origin {
43+
pub struct Module<T: Config> for enum Call where origin: <T as frame_system::Config>::Origin {
4444
#[weight = *weight]
4545
fn noop(_origin, weight: Weight) { }
4646

@@ -97,7 +97,7 @@ parameter_types! {
9797
pub const MaximumBlockLength: u32 = 2 * 1024;
9898
pub const AvailableBlockRatio: Perbill = Perbill::one();
9999
}
100-
impl frame_system::Trait for Test {
100+
impl frame_system::Config for Test {
101101
type BaseCallFilter = TestBaseCallFilter;
102102
type Origin = Origin;
103103
type Index = u64;
@@ -127,7 +127,7 @@ impl frame_system::Trait for Test {
127127
parameter_types! {
128128
pub const ExistentialDeposit: u64 = 1;
129129
}
130-
impl pallet_balances::Trait for Test {
130+
impl pallet_balances::Config for Test {
131131
type MaxLocks = ();
132132
type Balance = u64;
133133
type DustRemoval = ();
@@ -142,7 +142,7 @@ parameter_types! {
142142
pub const MaxSignatories: u16 = 3;
143143
}
144144

145-
impl example::Trait for Test {}
145+
impl example::Config for Test {}
146146

147147
pub struct TestBaseCallFilter;
148148
impl Filter<Call> for TestBaseCallFilter {
@@ -158,7 +158,7 @@ impl Filter<Call> for TestBaseCallFilter {
158158
}
159159
}
160160
}
161-
impl Trait for Test {
161+
impl Config for Test {
162162
type Event = TestEvent;
163163
type Call = Call;
164164
type WeightInfo = ();
@@ -428,7 +428,7 @@ fn batch_handles_weight_refund() {
428428
assert_eq!(
429429
extract_actual_weight(&result, &info),
430430
// Real weight is 2 calls at end_weight
431-
<Test as Trait>::WeightInfo::batch(2) + end_weight * 2,
431+
<Test as Config>::WeightInfo::batch(2) + end_weight * 2,
432432
);
433433
});
434434
}
@@ -465,7 +465,7 @@ fn batch_all_revert() {
465465
]),
466466
DispatchErrorWithPostInfo {
467467
post_info: PostDispatchInfo {
468-
actual_weight: Some(<Test as Trait>::WeightInfo::batch_all(2) + info.weight * 2),
468+
actual_weight: Some(<Test as Config>::WeightInfo::batch_all(2) + info.weight * 2),
469469
pays_fee: Pays::Yes
470470
},
471471
error: pallet_balances::Error::<Test, _>::InsufficientBalance.into()
@@ -536,7 +536,7 @@ fn batch_all_handles_weight_refund() {
536536
assert_eq!(
537537
extract_actual_weight(&result, &info),
538538
// Real weight is 2 calls at end_weight
539-
<Test as Trait>::WeightInfo::batch_all(2) + end_weight * 2,
539+
<Test as Config>::WeightInfo::batch_all(2) + end_weight * 2,
540540
);
541541
});
542542
}

src/weights.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -51,7 +51,7 @@ pub trait WeightInfo {
5151

5252
/// Weights for pallet_utility using the Substrate node and recommended hardware.
5353
pub struct SubstrateWeight<T>(PhantomData<T>);
54-
impl<T: frame_system::Trait> WeightInfo for SubstrateWeight<T> {
54+
impl<T: frame_system::Config> WeightInfo for SubstrateWeight<T> {
5555
fn batch(c: u32, ) -> Weight {
5656
(20_071_000 as Weight)
5757
.saturating_add((2_739_000 as Weight).saturating_mul(c as Weight))

0 commit comments

Comments
 (0)