mirror of
https://github.com/pezkuwichain/pezkuwi-subxt.git
synced 2026-05-30 03:31:05 +00:00
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:
committed by
GitHub
parent
dd3c84c362
commit
1cbfc9257f
@@ -30,7 +30,7 @@ const BALANCE_FACTOR: u32 = 250;
|
||||
const MAX_VOTERS: u32 = 500;
|
||||
const MAX_CANDIDATES: u32 = 200;
|
||||
|
||||
type Lookup<T> = <<T as frame_system::Trait>::Lookup as StaticLookup>::Source;
|
||||
type Lookup<T> = <<T as frame_system::Config>::Lookup as StaticLookup>::Source;
|
||||
|
||||
macro_rules! whitelist {
|
||||
($acc:ident) => {
|
||||
@@ -41,7 +41,7 @@ macro_rules! whitelist {
|
||||
}
|
||||
|
||||
/// grab new account with infinite balance.
|
||||
fn endowed_account<T: Trait>(name: &'static str, index: u32) -> T::AccountId {
|
||||
fn endowed_account<T: Config>(name: &'static str, index: u32) -> T::AccountId {
|
||||
let account: T::AccountId = account(name, index, 0);
|
||||
let amount = default_stake::<T>(BALANCE_FACTOR);
|
||||
let _ = T::Currency::make_free_balance_be(&account, amount);
|
||||
@@ -53,28 +53,28 @@ fn endowed_account<T: Trait>(name: &'static str, index: u32) -> T::AccountId {
|
||||
}
|
||||
|
||||
/// Account to lookup type of system trait.
|
||||
fn as_lookup<T: Trait>(account: T::AccountId) -> Lookup<T> {
|
||||
fn as_lookup<T: Config>(account: T::AccountId) -> Lookup<T> {
|
||||
T::Lookup::unlookup(account)
|
||||
}
|
||||
|
||||
/// Get a reasonable amount of stake based on the execution trait's configuration
|
||||
fn default_stake<T: Trait>(factor: u32) -> BalanceOf<T> {
|
||||
fn default_stake<T: Config>(factor: u32) -> BalanceOf<T> {
|
||||
let factor = BalanceOf::<T>::from(factor);
|
||||
T::Currency::minimum_balance() * factor
|
||||
}
|
||||
|
||||
/// Get the current number of candidates.
|
||||
fn candidate_count<T: Trait>() -> u32 {
|
||||
fn candidate_count<T: Config>() -> u32 {
|
||||
<Candidates<T>>::decode_len().unwrap_or(0usize) as u32
|
||||
}
|
||||
|
||||
/// Get the number of votes of a voter.
|
||||
fn vote_count_of<T: Trait>(who: &T::AccountId) -> u32 {
|
||||
fn vote_count_of<T: Config>(who: &T::AccountId) -> u32 {
|
||||
<Voting<T>>::get(who).1.len() as u32
|
||||
}
|
||||
|
||||
/// A `DefunctVoter` struct with correct value
|
||||
fn defunct_for<T: Trait>(who: T::AccountId) -> DefunctVoter<Lookup<T>> {
|
||||
fn defunct_for<T: Config>(who: T::AccountId) -> DefunctVoter<Lookup<T>> {
|
||||
DefunctVoter {
|
||||
who: as_lookup::<T>(who.clone()),
|
||||
candidate_count: candidate_count::<T>(),
|
||||
@@ -83,7 +83,7 @@ fn defunct_for<T: Trait>(who: T::AccountId) -> DefunctVoter<Lookup<T>> {
|
||||
}
|
||||
|
||||
/// Add `c` new candidates.
|
||||
fn submit_candidates<T: Trait>(c: u32, prefix: &'static str)
|
||||
fn submit_candidates<T: Config>(c: u32, prefix: &'static str)
|
||||
-> Result<Vec<T::AccountId>, &'static str>
|
||||
{
|
||||
(0..c).map(|i| {
|
||||
@@ -97,7 +97,7 @@ fn submit_candidates<T: Trait>(c: u32, prefix: &'static str)
|
||||
}
|
||||
|
||||
/// Add `c` new candidates with self vote.
|
||||
fn submit_candidates_with_self_vote<T: Trait>(c: u32, prefix: &'static str)
|
||||
fn submit_candidates_with_self_vote<T: Config>(c: u32, prefix: &'static str)
|
||||
-> Result<Vec<T::AccountId>, &'static str>
|
||||
{
|
||||
let candidates = submit_candidates::<T>(c, prefix)?;
|
||||
@@ -110,7 +110,7 @@ fn submit_candidates_with_self_vote<T: Trait>(c: u32, prefix: &'static str)
|
||||
|
||||
|
||||
/// Submit one voter.
|
||||
fn submit_voter<T: Trait>(caller: T::AccountId, votes: Vec<T::AccountId>, stake: BalanceOf<T>)
|
||||
fn submit_voter<T: Config>(caller: T::AccountId, votes: Vec<T::AccountId>, stake: BalanceOf<T>)
|
||||
-> Result<(), sp_runtime::DispatchError>
|
||||
{
|
||||
<Elections<T>>::vote(RawOrigin::Signed(caller).into(), votes, stake)
|
||||
@@ -118,7 +118,7 @@ fn submit_voter<T: Trait>(caller: T::AccountId, votes: Vec<T::AccountId>, stake:
|
||||
|
||||
/// create `num_voter` voters who randomly vote for at most `votes` of `all_candidates` if
|
||||
/// available.
|
||||
fn distribute_voters<T: Trait>(mut all_candidates: Vec<T::AccountId>, num_voters: u32, votes: usize)
|
||||
fn distribute_voters<T: Config>(mut all_candidates: Vec<T::AccountId>, num_voters: u32, votes: usize)
|
||||
-> Result<(), &'static str>
|
||||
{
|
||||
let stake = default_stake::<T>(BALANCE_FACTOR);
|
||||
@@ -138,7 +138,7 @@ fn distribute_voters<T: Trait>(mut all_candidates: Vec<T::AccountId>, num_voters
|
||||
|
||||
/// Fill the seats of members and runners-up up until `m`. Note that this might include either only
|
||||
/// members, or members and runners-up.
|
||||
fn fill_seats_up_to<T: Trait>(m: u32) -> Result<Vec<T::AccountId>, &'static str> {
|
||||
fn fill_seats_up_to<T: Config>(m: u32) -> Result<Vec<T::AccountId>, &'static str> {
|
||||
let _ = submit_candidates_with_self_vote::<T>(m, "fill_seats_up_to")?;
|
||||
assert_eq!(<Elections<T>>::candidates().len() as u32, m, "wrong number of candidates.");
|
||||
<Elections<T>>::do_phragmen();
|
||||
@@ -158,7 +158,7 @@ fn fill_seats_up_to<T: Trait>(m: u32) -> Result<Vec<T::AccountId>, &'static str>
|
||||
}
|
||||
|
||||
/// removes all the storage items to reverse any genesis state.
|
||||
fn clean<T: Trait>() {
|
||||
fn clean<T: Config>() {
|
||||
<Members<T>>::kill();
|
||||
<Candidates<T>>::kill();
|
||||
<RunnersUp<T>>::kill();
|
||||
|
||||
@@ -77,7 +77,7 @@
|
||||
//!
|
||||
//! ### Module Information
|
||||
//!
|
||||
//! - [`election_sp_phragmen::Trait`](./trait.Trait.html)
|
||||
//! - [`election_sp_phragmen::Config`](./trait.Config.html)
|
||||
//! - [`Call`](./enum.Call.html)
|
||||
//! - [`Module`](./struct.Module.html)
|
||||
|
||||
@@ -112,9 +112,9 @@ pub use weights::WeightInfo;
|
||||
pub const MAXIMUM_VOTE: usize = 16;
|
||||
|
||||
type BalanceOf<T> =
|
||||
<<T as Trait>::Currency as Currency<<T as frame_system::Trait>::AccountId>>::Balance;
|
||||
<<T as Config>::Currency as Currency<<T as frame_system::Config>::AccountId>>::Balance;
|
||||
type NegativeImbalanceOf<T> =
|
||||
<<T as Trait>::Currency as Currency<<T as frame_system::Trait>::AccountId>>::NegativeImbalance;
|
||||
<<T as Config>::Currency as Currency<<T as frame_system::Config>::AccountId>>::NegativeImbalance;
|
||||
|
||||
/// An indication that the renouncing account currently has which of the below roles.
|
||||
#[derive(Encode, Decode, Clone, PartialEq, RuntimeDebug)]
|
||||
@@ -140,9 +140,9 @@ pub struct DefunctVoter<AccountId> {
|
||||
pub candidate_count: u32
|
||||
}
|
||||
|
||||
pub trait Trait: frame_system::Trait {
|
||||
pub trait Config: frame_system::Config {
|
||||
/// The overarching event type.c
|
||||
type Event: From<Event<Self>> + Into<<Self as frame_system::Trait>::Event>;
|
||||
type Event: From<Event<Self>> + Into<<Self as frame_system::Config>::Event>;
|
||||
|
||||
/// Identifier for the elections-phragmen pallet's lock
|
||||
type ModuleId: Get<LockIdentifier>;
|
||||
@@ -193,7 +193,7 @@ pub trait Trait: frame_system::Trait {
|
||||
}
|
||||
|
||||
decl_storage! {
|
||||
trait Store for Module<T: Trait> as PhragmenElection {
|
||||
trait Store for Module<T: Config> as PhragmenElection {
|
||||
// ---- State
|
||||
/// The current elected membership. Sorted based on account id.
|
||||
pub Members get(fn members): Vec<(T::AccountId, BalanceOf<T>)>;
|
||||
@@ -251,7 +251,7 @@ decl_storage! {
|
||||
}
|
||||
|
||||
decl_error! {
|
||||
pub enum Error for Module<T: Trait> {
|
||||
pub enum Error for Module<T: Config> {
|
||||
/// Cannot vote when no candidates or members exist.
|
||||
UnableToVote,
|
||||
/// Must vote for at least one candidate.
|
||||
@@ -290,7 +290,7 @@ decl_error! {
|
||||
}
|
||||
|
||||
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>;
|
||||
|
||||
fn deposit_event() = default;
|
||||
@@ -667,7 +667,7 @@ decl_module! {
|
||||
decl_event!(
|
||||
pub enum Event<T> where
|
||||
Balance = BalanceOf<T>,
|
||||
<T as frame_system::Trait>::AccountId,
|
||||
<T as frame_system::Config>::AccountId,
|
||||
{
|
||||
/// A new term with \[new_members\]. This indicates that enough candidates existed to run the
|
||||
/// election, not that enough have has been elected. The inner value must be examined for
|
||||
@@ -694,7 +694,7 @@ decl_event!(
|
||||
}
|
||||
);
|
||||
|
||||
impl<T: Trait> Module<T> {
|
||||
impl<T: Config> Module<T> {
|
||||
/// Attempts to remove a member `who`. If a runner-up exists, it is used as the replacement and
|
||||
/// Ok(true). is returned.
|
||||
///
|
||||
@@ -1027,7 +1027,7 @@ impl<T: Trait> Module<T> {
|
||||
}
|
||||
}
|
||||
|
||||
impl<T: Trait> Contains<T::AccountId> for Module<T> {
|
||||
impl<T: Config> Contains<T::AccountId> for Module<T> {
|
||||
fn contains(who: &T::AccountId) -> bool {
|
||||
Self::is_member(who)
|
||||
}
|
||||
@@ -1046,7 +1046,7 @@ impl<T: Trait> Contains<T::AccountId> for Module<T> {
|
||||
}
|
||||
}
|
||||
|
||||
impl<T: Trait> ContainsLengthBound for Module<T> {
|
||||
impl<T: Config> ContainsLengthBound for Module<T> {
|
||||
fn min_len() -> usize { 0 }
|
||||
|
||||
/// Implementation uses a parameter type so calling is cost-free.
|
||||
@@ -1076,7 +1076,7 @@ mod tests {
|
||||
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;
|
||||
@@ -1108,7 +1108,7 @@ mod tests {
|
||||
pub const ExistentialDeposit: u64 = 1;
|
||||
}
|
||||
|
||||
impl pallet_balances::Trait for Test {
|
||||
impl pallet_balances::Config for Test {
|
||||
type Balance = u64;
|
||||
type Event = Event;
|
||||
type DustRemoval = ();
|
||||
@@ -1175,7 +1175,7 @@ mod tests {
|
||||
pub const ElectionsPhragmenModuleId: LockIdentifier = *b"phrelect";
|
||||
}
|
||||
|
||||
impl Trait for Test {
|
||||
impl Config for Test {
|
||||
type ModuleId = ElectionsPhragmenModuleId;
|
||||
type Event = Event;
|
||||
type Currency = Balances;
|
||||
|
||||
@@ -59,7 +59,7 @@ pub trait WeightInfo {
|
||||
|
||||
/// Weights for pallet_elections_phragmen 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 vote(v: u32, ) -> Weight {
|
||||
(89_627_000 as Weight)
|
||||
.saturating_add((197_000 as Weight).saturating_mul(v as Weight))
|
||||
|
||||
Reference in New Issue
Block a user