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
@@ -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();