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
+12 -12
View File
@@ -29,16 +29,16 @@ use crate::Module as Identity;
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);
}
// Adds `r` registrars to the Identity Pallet. These registrars will have set fees and fields.
fn add_registrars<T: Trait>(r: u32) -> Result<(), &'static str> {
fn add_registrars<T: Config>(r: u32) -> Result<(), &'static str> {
for i in 0..r {
let registrar: T::AccountId = account("registrar", i, SEED);
let _ = T::Currency::make_free_balance_be(&registrar, BalanceOf::<T>::max_value());
@@ -57,7 +57,7 @@ fn add_registrars<T: Trait>(r: u32) -> Result<(), &'static str> {
// Create `s` sub-accounts for the identity of `who` and return them.
// Each will have 32 bytes of raw data added to it.
fn create_sub_accounts<T: Trait>(who: &T::AccountId, s: u32) -> Result<Vec<(T::AccountId, Data)>, &'static str> {
fn create_sub_accounts<T: Config>(who: &T::AccountId, s: u32) -> Result<Vec<(T::AccountId, Data)>, &'static str> {
let mut subs = Vec::new();
let who_origin = RawOrigin::Signed(who.clone());
let data = Data::Raw(vec![0; 32]);
@@ -77,7 +77,7 @@ fn create_sub_accounts<T: Trait>(who: &T::AccountId, s: u32) -> Result<Vec<(T::A
// Adds `s` sub-accounts to the identity of `who`. Each will have 32 bytes of raw data added to it.
// This additionally returns the vector of sub-accounts so it can be modified if needed.
fn add_sub_accounts<T: Trait>(who: &T::AccountId, s: u32) -> Result<Vec<(T::AccountId, Data)>, &'static str> {
fn add_sub_accounts<T: Config>(who: &T::AccountId, s: u32) -> Result<Vec<(T::AccountId, Data)>, &'static str> {
let who_origin = RawOrigin::Signed(who.clone());
let subs = create_sub_accounts::<T>(who, s)?;
@@ -88,7 +88,7 @@ fn add_sub_accounts<T: Trait>(who: &T::AccountId, s: u32) -> Result<Vec<(T::Acco
// This creates an `IdentityInfo` object with `num_fields` extra fields.
// All data is pre-populated with some arbitrary bytes.
fn create_identity_info<T: Trait>(num_fields: u32) -> IdentityInfo {
fn create_identity_info<T: Config>(num_fields: u32) -> IdentityInfo {
let data = Data::Raw(vec![0; 32]);
let info = IdentityInfo {
@@ -121,7 +121,7 @@ benchmarks! {
// Create their main identity with x additional fields
let info = create_identity_info::<T>(x);
let caller: T::AccountId = whitelisted_caller();
let caller_origin = <T as frame_system::Trait>::Origin::from(RawOrigin::Signed(caller));
let caller_origin = <T as frame_system::Config>::Origin::from(RawOrigin::Signed(caller));
Identity::<T>::set_identity(caller_origin, info)?;
};
}
@@ -143,7 +143,7 @@ benchmarks! {
// The target user
let caller: T::AccountId = whitelisted_caller();
let caller_lookup: <T::Lookup as StaticLookup>::Source = T::Lookup::unlookup(caller.clone());
let caller_origin: <T as frame_system::Trait>::Origin = RawOrigin::Signed(caller.clone()).into();
let caller_origin: <T as frame_system::Config>::Origin = RawOrigin::Signed(caller.clone()).into();
let _ = T::Currency::make_free_balance_be(&caller, BalanceOf::<T>::max_value());
// Add an initial identity
@@ -200,7 +200,7 @@ benchmarks! {
clear_identity {
let caller: T::AccountId = whitelisted_caller();
let caller_origin = <T as frame_system::Trait>::Origin::from(RawOrigin::Signed(caller.clone()));
let caller_origin = <T as frame_system::Config>::Origin::from(RawOrigin::Signed(caller.clone()));
let caller_lookup = <T::Lookup as StaticLookup>::unlookup(caller.clone());
let _ = T::Currency::make_free_balance_be(&caller, BalanceOf::<T>::max_value());
@@ -237,7 +237,7 @@ benchmarks! {
cancel_request {
let caller: T::AccountId = whitelisted_caller();
let caller_origin = <T as frame_system::Trait>::Origin::from(RawOrigin::Signed(caller.clone()));
let caller_origin = <T as frame_system::Config>::Origin::from(RawOrigin::Signed(caller.clone()));
let _ = T::Currency::make_free_balance_be(&caller, BalanceOf::<T>::max_value());
let r in ...;
@@ -300,7 +300,7 @@ benchmarks! {
provide_judgement {
// The user
let user: T::AccountId = account("user", r, SEED);
let user_origin = <T as frame_system::Trait>::Origin::from(RawOrigin::Signed(user.clone()));
let user_origin = <T as frame_system::Config>::Origin::from(RawOrigin::Signed(user.clone()));
let user_lookup = <T::Lookup as StaticLookup>::unlookup(user.clone());
let _ = T::Currency::make_free_balance_be(&user, BalanceOf::<T>::max_value());
@@ -328,7 +328,7 @@ benchmarks! {
let x in _ .. _ => {};
let target: T::AccountId = account("target", 0, SEED);
let target_origin: <T as frame_system::Trait>::Origin = RawOrigin::Signed(target.clone()).into();
let target_origin: <T as frame_system::Config>::Origin = RawOrigin::Signed(target.clone()).into();
let target_lookup: <T::Lookup as StaticLookup>::Source = T::Lookup::unlookup(target.clone());
let _ = T::Currency::make_free_balance_be(&target, BalanceOf::<T>::max_value());
+11 -11
View File
@@ -17,7 +17,7 @@
//! # Identity Module
//!
//! - [`identity::Trait`](./trait.Trait.html)
//! - [`identity::Config`](./trait.Config.html)
//! - [`Call`](./enum.Call.html)
//!
//! ## Overview
@@ -68,7 +68,7 @@
//! * `kill_identity` - Forcibly remove the associated identity; the deposit is lost.
//!
//! [`Call`]: ./enum.Call.html
//! [`Trait`]: ./trait.Trait.html
//! [`Config`]: ./trait.Config.html
#![cfg_attr(not(feature = "std"), no_std)]
@@ -91,12 +91,12 @@ use frame_support::{
use frame_system::ensure_signed;
pub use weights::WeightInfo;
type BalanceOf<T> = <<T as Trait>::Currency as Currency<<T as frame_system::Trait>::AccountId>>::Balance;
type NegativeImbalanceOf<T> = <<T as Trait>::Currency as Currency<<T as frame_system::Trait>::AccountId>>::NegativeImbalance;
type BalanceOf<T> = <<T as Config>::Currency as Currency<<T as frame_system::Config>::AccountId>>::Balance;
type NegativeImbalanceOf<T> = <<T as Config>::Currency as Currency<<T as frame_system::Config>::AccountId>>::NegativeImbalance;
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 currency trait.
type Currency: ReservableCurrency<Self::AccountId>;
@@ -399,7 +399,7 @@ pub struct RegistrarInfo<
}
decl_storage! {
trait Store for Module<T: Trait> as Identity {
trait Store for Module<T: Config> as Identity {
/// Information that is pertinent to identify the entity behind an account.
///
/// TWOX-NOTE: OK ― `AccountId` is a secure hash.
@@ -428,7 +428,7 @@ decl_storage! {
}
decl_event!(
pub enum Event<T> where AccountId = <T as frame_system::Trait>::AccountId, Balance = BalanceOf<T> {
pub enum Event<T> where AccountId = <T as frame_system::Config>::AccountId, Balance = BalanceOf<T> {
/// A name was set or reset (which will remove all judgements). \[who\]
IdentitySet(AccountId),
/// A name was cleared, and the given balance returned. \[who, deposit\]
@@ -456,7 +456,7 @@ decl_event!(
decl_error! {
/// Error for the identity module.
pub enum Error for Module<T: Trait> {
pub enum Error for Module<T: Config> {
/// Too many subs-accounts.
TooManySubAccounts,
/// Account isn't found.
@@ -494,7 +494,7 @@ decl_error! {
decl_module! {
/// Identity module declaration.
pub struct Module<T: Trait> for enum Call where origin: T::Origin {
pub struct Module<T: Config> for enum Call where origin: T::Origin {
/// The amount held on deposit for a registered identity.
const BasicDeposit: BalanceOf<T> = T::BasicDeposit::get();
@@ -1125,7 +1125,7 @@ decl_module! {
}
}
impl<T: Trait> Module<T> {
impl<T: Config> Module<T> {
/// Get the subs of an account.
pub fn subs(who: &T::AccountId) -> Vec<(T::AccountId, Data)> {
SubsOf::<T>::get(who).1
+3 -3
View File
@@ -42,7 +42,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 = ();
type Origin = Origin;
type Index = u64;
@@ -72,7 +72,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 Balance = u64;
type Event = ();
type DustRemoval = ();
@@ -103,7 +103,7 @@ type EnsureTwoOrRoot = EnsureOneOf<
EnsureRoot<u64>,
EnsureSignedBy<Two, u64>
>;
impl Trait for Test {
impl Config for Test {
type Event = ();
type Currency = Balances;
type Slashed = ();
+1 -1
View File
@@ -64,7 +64,7 @@ pub trait WeightInfo {
/// Weights for pallet_identity 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 add_registrar(r: u32, ) -> Weight {
(28_965_000 as Weight)
.saturating_add((421_000 as Weight).saturating_mul(r as Weight))