Migrate pallet-staking to pallet attribute macro (#9083)

* Migrate staking pallet to pallet attribute macro.

* HistoryDepth default value.

* Make all calls public.

* Update frame/staking/src/lib.rs

* remove externalities again

* Update lib.rs

Co-authored-by: Shawn Tabrizi <shawntabrizi@gmail.com>
This commit is contained in:
Shaun Wang
2021-06-12 12:22:40 +12:00
committed by GitHub
parent 68833498c6
commit 0869fdf9aa
10 changed files with 731 additions and 552 deletions
+17 -17
View File
@@ -18,7 +18,7 @@
//! Staking pallet benchmarking.
use super::*;
use crate::Module as Staking;
use crate::Pallet as Staking;
use testing_utils::*;
use sp_runtime::traits::One;
@@ -88,7 +88,7 @@ pub fn create_validator_with_nominators<T: Config>(
}
}
ValidatorCount::put(1);
ValidatorCount::<T>::put(1);
// Start a new Era
let new_validators = Staking::<T>::new_era(SessionIndex::one()).unwrap();
@@ -102,7 +102,7 @@ pub fn create_validator_with_nominators<T: Config>(
individual: points_individual.into_iter().collect(),
};
let current_era = CurrentEra::get().unwrap();
let current_era = CurrentEra::<T>::get().unwrap();
ErasRewardPoints::<T>::insert(current_era, reward);
// Create reward pool
@@ -164,7 +164,7 @@ benchmarks! {
add_slashing_spans::<T>(&stash, s);
let amount = T::Currency::minimum_balance() * 5u32.into(); // Half of total
Staking::<T>::unbond(RawOrigin::Signed(controller.clone()).into(), amount)?;
CurrentEra::put(EraIndex::max_value());
CurrentEra::<T>::put(EraIndex::max_value());
let ledger = Ledger::<T>::get(&controller).ok_or("ledger not created before")?;
let original_total: BalanceOf<T> = ledger.total;
whitelist_account!(controller);
@@ -183,7 +183,7 @@ benchmarks! {
add_slashing_spans::<T>(&stash, s);
let amount = T::Currency::minimum_balance() * 10u32.into();
Staking::<T>::unbond(RawOrigin::Signed(controller.clone()).into(), amount)?;
CurrentEra::put(EraIndex::max_value());
CurrentEra::<T>::put(EraIndex::max_value());
let ledger = Ledger::<T>::get(&controller).ok_or("ledger not created before")?;
let original_total: BalanceOf<T> = ledger.total;
whitelist_account!(controller);
@@ -303,17 +303,17 @@ benchmarks! {
let validator_count = MAX_VALIDATORS;
}: _(RawOrigin::Root, validator_count)
verify {
assert_eq!(ValidatorCount::get(), validator_count);
assert_eq!(ValidatorCount::<T>::get(), validator_count);
}
force_no_eras {}: _(RawOrigin::Root)
verify { assert_eq!(ForceEra::get(), Forcing::ForceNone); }
verify { assert_eq!(ForceEra::<T>::get(), Forcing::ForceNone); }
force_new_era {}: _(RawOrigin::Root)
verify { assert_eq!(ForceEra::get(), Forcing::ForceNew); }
verify { assert_eq!(ForceEra::<T>::get(), Forcing::ForceNew); }
force_new_era_always {}: _(RawOrigin::Root)
verify { assert_eq!(ForceEra::get(), Forcing::ForceAlways); }
verify { assert_eq!(ForceEra::<T>::get(), Forcing::ForceAlways); }
// Worst case scenario, the list of invulnerables is very long.
set_invulnerables {
@@ -361,7 +361,7 @@ benchmarks! {
RewardDestination::Controller,
)?;
let current_era = CurrentEra::get().unwrap();
let current_era = CurrentEra::<T>::get().unwrap();
// set the commission for this particular era as well.
<ErasValidatorPrefs<T>>::insert(current_era, validator.clone(), <Staking<T>>::validators(&validator));
@@ -394,7 +394,7 @@ benchmarks! {
RewardDestination::Staked,
)?;
let current_era = CurrentEra::get().unwrap();
let current_era = CurrentEra::<T>::get().unwrap();
// set the commission for this particular era as well.
<ErasValidatorPrefs<T>>::insert(current_era, validator.clone(), <Staking<T>>::validators(&validator));
@@ -444,8 +444,8 @@ benchmarks! {
set_history_depth {
let e in 1 .. 100;
HistoryDepth::put(e);
CurrentEra::put(e);
HistoryDepth::<T>::put(e);
CurrentEra::<T>::put(e);
for i in 0 .. e {
<ErasStakers<T>>::insert(i, T::AccountId::default(), Exposure::<T::AccountId, BalanceOf<T>>::default());
<ErasStakersClipped<T>>::insert(i, T::AccountId::default(), Exposure::<T::AccountId, BalanceOf<T>>::default());
@@ -453,11 +453,11 @@ benchmarks! {
<ErasValidatorReward<T>>::insert(i, BalanceOf::<T>::one());
<ErasRewardPoints<T>>::insert(i, EraRewardPoints::<T::AccountId>::default());
<ErasTotalStake<T>>::insert(i, BalanceOf::<T>::one());
ErasStartSessionIndex::insert(i, i);
ErasStartSessionIndex::<T>::insert(i, i);
}
}: _(RawOrigin::Root, EraIndex::zero(), u32::max_value())
verify {
assert_eq!(HistoryDepth::get(), 0);
assert_eq!(HistoryDepth::<T>::get(), 0);
}
reap_stash {
@@ -503,7 +503,7 @@ benchmarks! {
let new_validators = Staking::<T>::new_era(SessionIndex::one()).unwrap();
assert!(new_validators.len() == v as usize);
let current_era = CurrentEra::get().unwrap();
let current_era = CurrentEra::<T>::get().unwrap();
let mut points_total = 0;
let mut points_individual = Vec::new();
let mut payout_calls_arg = Vec::new();
@@ -636,7 +636,7 @@ mod tests {
assert_eq!(nominators.len() as u32, n);
let current_era = CurrentEra::get().unwrap();
let current_era = CurrentEra::<Test>::get().unwrap();
let original_free_balance = Balances::free_balance(&validator_stash);
assert_ok!(Staking::payout_stakers(Origin::signed(1337), validator_stash, current_era));
File diff suppressed because it is too large Load Diff
+6 -7
View File
@@ -21,9 +21,8 @@ use crate::*;
use crate as staking;
use frame_support::{
assert_ok, parameter_types,
traits::{Currency, FindAuthor, Get, OnFinalize, OnInitialize, OneSessionHandler},
traits::{Currency, FindAuthor, Get, OnInitialize, OneSessionHandler},
weights::constants::RocksDbWeight,
IterableStorageMap, StorageDoubleMap, StorageMap, StorageValue,
};
use sp_core::H256;
use sp_io;
@@ -194,7 +193,7 @@ impl pallet_authorship::Config for Test {
type FindAuthor = Author11;
type UncleGenerations = UncleGenerations;
type FilterUncle = ();
type EventHandler = Module<Test>;
type EventHandler = Pallet<Test>;
}
parameter_types! {
pub const MinimumPeriod: u64 = 5;
@@ -459,7 +458,7 @@ impl ExtBuilder {
ext.execute_with(|| {
System::set_block_number(1);
Session::on_initialize(1);
Staking::on_initialize(1);
<Staking as Hooks<u64>>::on_initialize(1);
Timestamp::set_timestamp(INIT_TIMESTAMP);
});
}
@@ -610,7 +609,7 @@ pub(crate) fn run_to_block(n: BlockNumber) {
for b in (System::block_number() + 1)..=n {
System::set_block_number(b);
Session::on_initialize(b);
Staking::on_initialize(b);
<Staking as Hooks<u64>>::on_initialize(b);
Timestamp::set_timestamp(System::block_number() * BLOCK_TIME + INIT_TIMESTAMP);
if b != n {
Staking::on_finalize(System::block_number());
@@ -696,7 +695,7 @@ pub(crate) fn reward_all_elected() {
.into_iter()
.map(|v| (v, 1));
<Module<Test>>::reward_by_ids(rewards)
<Pallet<Test>>::reward_by_ids(rewards)
}
pub(crate) fn validator_controllers() -> Vec<AccountId> {
@@ -714,7 +713,7 @@ pub(crate) fn on_offence_in_era(
slash_fraction: &[Perbill],
era: EraIndex,
) {
let bonded_eras = crate::BondedEras::get();
let bonded_eras = crate::BondedEras::<Test>::get();
for &(bonded_era, start_session) in bonded_eras.iter() {
if bonded_era == era {
let _ = Staking::on_offence(offenders, slash_fraction, start_session);
+26 -26
View File
@@ -50,12 +50,12 @@
//! Based on research at <https://w3f-research.readthedocs.io/en/latest/polkadot/slashing/npos.html>
use super::{
EraIndex, Config, Module, Store, BalanceOf, Exposure, Perbill, SessionInterface,
EraIndex, Config, Pallet, Store, BalanceOf, Exposure, Perbill, SessionInterface,
NegativeImbalanceOf, UnappliedSlash, Error,
};
use sp_runtime::{traits::{Zero, Saturating}, RuntimeDebug, DispatchResult};
use frame_support::{
StorageMap, StorageDoubleMap, ensure,
ensure,
traits::{Currency, OnUnbalanced, Imbalance},
};
use sp_std::vec::Vec;
@@ -239,7 +239,7 @@ pub(crate) fn compute_slash<T: Config>(params: SlashParams<T>)
return None;
}
let (prior_slash_p, _era_slash) = <Module<T> as Store>::ValidatorSlashInEra::get(
let (prior_slash_p, _era_slash) = <Pallet<T> as Store>::ValidatorSlashInEra::get(
&slash_era,
stash,
).unwrap_or((Perbill::zero(), Zero::zero()));
@@ -247,7 +247,7 @@ pub(crate) fn compute_slash<T: Config>(params: SlashParams<T>)
// compare slash proportions rather than slash values to avoid issues due to rounding
// error.
if slash.deconstruct() > prior_slash_p.deconstruct() {
<Module<T> as Store>::ValidatorSlashInEra::insert(
<Pallet<T> as Store>::ValidatorSlashInEra::insert(
&slash_era,
stash,
&(slash, own_slash),
@@ -285,12 +285,12 @@ pub(crate) fn compute_slash<T: Config>(params: SlashParams<T>)
// chill the validator - it misbehaved in the current span and should
// not continue in the next election. also end the slashing span.
spans.end_span(now);
<Module<T>>::chill_stash(stash);
<Pallet<T>>::chill_stash(stash);
// make sure to disable validator till the end of this session
if T::SessionInterface::disable_validator(stash).unwrap_or(false) {
// force a new era, to select a new validator set
<Module<T>>::ensure_new_era()
<Pallet<T>>::ensure_new_era()
}
}
}
@@ -325,12 +325,12 @@ fn kick_out_if_recent<T: Config>(
if spans.era_span(params.slash_era).map(|s| s.index) == Some(spans.span_index()) {
spans.end_span(params.now);
<Module<T>>::chill_stash(params.stash);
<Pallet<T>>::chill_stash(params.stash);
// make sure to disable validator till the end of this session
if T::SessionInterface::disable_validator(params.stash).unwrap_or(false) {
// force a new era, to select a new validator set
<Module<T>>::ensure_new_era()
<Pallet<T>>::ensure_new_era()
}
}
}
@@ -367,14 +367,14 @@ fn slash_nominators<T: Config>(
let own_slash_by_validator = slash * nominator.value;
let own_slash_difference = own_slash_by_validator.saturating_sub(own_slash_prior);
let mut era_slash = <Module<T> as Store>::NominatorSlashInEra::get(
let mut era_slash = <Pallet<T> as Store>::NominatorSlashInEra::get(
&slash_era,
stash,
).unwrap_or_else(|| Zero::zero());
era_slash += own_slash_difference;
<Module<T> as Store>::NominatorSlashInEra::insert(
<Pallet<T> as Store>::NominatorSlashInEra::insert(
&slash_era,
stash,
&era_slash,
@@ -437,9 +437,9 @@ fn fetch_spans<'a, T: Config + 'a>(
slash_of: &'a mut BalanceOf<T>,
reward_proportion: Perbill,
) -> InspectingSpans<'a, T> {
let spans = <Module<T> as Store>::SlashingSpans::get(stash).unwrap_or_else(|| {
let spans = <Pallet<T> as Store>::SlashingSpans::get(stash).unwrap_or_else(|| {
let spans = SlashingSpans::new(window_start);
<Module<T> as Store>::SlashingSpans::insert(stash, &spans);
<Pallet<T> as Store>::SlashingSpans::insert(stash, &spans);
spans
});
@@ -488,7 +488,7 @@ impl<'a, T: 'a + Config> InspectingSpans<'a, T> {
) -> Option<SpanIndex> {
let target_span = self.era_span(slash_era)?;
let span_slash_key = (self.stash.clone(), target_span.index);
let mut span_record = <Module<T> as Store>::SpanSlash::get(&span_slash_key);
let mut span_record = <Pallet<T> as Store>::SpanSlash::get(&span_slash_key);
let mut changed = false;
let reward = if span_record.slashed < slash {
@@ -519,7 +519,7 @@ impl<'a, T: 'a + Config> InspectingSpans<'a, T> {
if changed {
self.dirty = true;
<Module<T> as Store>::SpanSlash::insert(&span_slash_key, &span_record);
<Pallet<T> as Store>::SpanSlash::insert(&span_slash_key, &span_record);
}
Some(target_span.index)
@@ -533,18 +533,18 @@ impl<'a, T: 'a + Config> Drop for InspectingSpans<'a, T> {
if let Some((start, end)) = self.spans.prune(self.window_start) {
for span_index in start..end {
<Module<T> as Store>::SpanSlash::remove(&(self.stash.clone(), span_index));
<Pallet<T> as Store>::SpanSlash::remove(&(self.stash.clone(), span_index));
}
}
<Module<T> as Store>::SlashingSpans::insert(self.stash, &self.spans);
<Pallet<T> as Store>::SlashingSpans::insert(self.stash, &self.spans);
}
}
/// Clear slashing metadata for an obsolete era.
pub(crate) fn clear_era_metadata<T: Config>(obsolete_era: EraIndex) {
<Module<T> as Store>::ValidatorSlashInEra::remove_prefix(&obsolete_era);
<Module<T> as Store>::NominatorSlashInEra::remove_prefix(&obsolete_era);
<Pallet<T> as Store>::ValidatorSlashInEra::remove_prefix(&obsolete_era);
<Pallet<T> as Store>::NominatorSlashInEra::remove_prefix(&obsolete_era);
}
/// Clear slashing metadata for a dead account.
@@ -552,14 +552,14 @@ pub(crate) fn clear_stash_metadata<T: Config>(
stash: &T::AccountId,
num_slashing_spans: u32,
) -> DispatchResult {
let spans = match <Module<T> as Store>::SlashingSpans::get(stash) {
let spans = match <Pallet<T> as Store>::SlashingSpans::get(stash) {
None => return Ok(()),
Some(s) => s,
};
ensure!(num_slashing_spans as usize >= spans.iter().count(), Error::<T>::IncorrectSlashingSpans);
<Module<T> as Store>::SlashingSpans::remove(stash);
<Pallet<T> as Store>::SlashingSpans::remove(stash);
// kill slashing-span metadata for account.
//
@@ -567,7 +567,7 @@ pub(crate) fn clear_stash_metadata<T: Config>(
// in that case, they may re-bond, but it would count again as span 0. Further ancient
// slashes would slash into this new bond, since metadata has now been cleared.
for span in spans.iter() {
<Module<T> as Store>::SpanSlash::remove(&(stash.clone(), span.index));
<Pallet<T> as Store>::SpanSlash::remove(&(stash.clone(), span.index));
}
Ok(())
@@ -582,12 +582,12 @@ pub fn do_slash<T: Config>(
reward_payout: &mut BalanceOf<T>,
slashed_imbalance: &mut NegativeImbalanceOf<T>,
) {
let controller = match <Module<T>>::bonded(stash) {
let controller = match <Pallet<T>>::bonded(stash) {
None => return, // defensive: should always exist.
Some(c) => c,
};
let mut ledger = match <Module<T>>::ledger(&controller) {
let mut ledger = match <Pallet<T>>::ledger(&controller) {
Some(ledger) => ledger,
None => return, // nothing to do.
};
@@ -603,11 +603,11 @@ pub fn do_slash<T: Config>(
*reward_payout = reward_payout.saturating_sub(missing);
}
<Module<T>>::update_ledger(&controller, &ledger);
<Pallet<T>>::update_ledger(&controller, &ledger);
// trigger the event
<Module<T>>::deposit_event(
super::RawEvent::Slash(stash.clone(), value)
<Pallet<T>>::deposit_event(
super::Event::<T>::Slash(stash.clone(), value)
);
}
}
+3 -3
View File
@@ -19,7 +19,7 @@
//! bonding validators, nominators, and generating different types of solutions.
use crate::*;
use crate::Module as Staking;
use crate::Pallet as Staking;
use frame_benchmarking::account;
use frame_system::RawOrigin;
use sp_io::hashing::blake2_256;
@@ -166,12 +166,12 @@ pub fn create_validators_with_nominators_for_era<T: Config>(
Staking::<T>::nominate(RawOrigin::Signed(n_controller.clone()).into(), selected_validators)?;
}
ValidatorCount::put(validators);
ValidatorCount::<T>::put(validators);
Ok(validator_chosen)
}
/// get the current era.
pub fn current_era<T: Config>() -> EraIndex {
<Module<T>>::current_era().unwrap_or(0)
<Pallet<T>>::current_era().unwrap_or(0)
}
+36 -36
View File
@@ -17,7 +17,7 @@
//! Tests for the module.
use super::*;
use super::{*, Event};
use mock::*;
use sp_runtime::{
assert_eq_error_rate,
@@ -25,7 +25,7 @@ use sp_runtime::{
};
use sp_staking::offence::OffenceDetails;
use frame_support::{
assert_ok, assert_noop, StorageMap,
assert_ok, assert_noop,
traits::{Currency, ReservableCurrency, OnInitialize},
weights::{extract_actual_weight, GetDispatchInfo},
};
@@ -187,10 +187,10 @@ fn rewards_should_work() {
Payee::<Test>::insert(21, RewardDestination::Controller);
Payee::<Test>::insert(101, RewardDestination::Controller);
<Module<Test>>::reward_by_ids(vec![(11, 50)]);
<Module<Test>>::reward_by_ids(vec![(11, 50)]);
<Pallet<Test>>::reward_by_ids(vec![(11, 50)]);
<Pallet<Test>>::reward_by_ids(vec![(11, 50)]);
// This is the second validator of the current elected set.
<Module<Test>>::reward_by_ids(vec![(21, 50)]);
<Pallet<Test>>::reward_by_ids(vec![(21, 50)]);
// Compute total payout now for whole duration of the session.
let total_payout_0 = current_total_payout_for_duration(reward_time_per_era());
@@ -227,7 +227,7 @@ fn rewards_should_work() {
);
assert_eq!(
*mock::staking_events().last().unwrap(),
RawEvent::EraPayout(0, total_payout_0, maximum_payout - total_payout_0)
Event::EraPayout(0, total_payout_0, maximum_payout - total_payout_0)
);
mock::make_all_reward_payment(0);
@@ -253,7 +253,7 @@ fn rewards_should_work() {
assert_eq_error_rate!(Balances::total_balance(&101), init_balance_101, 2);
assert_eq_uvec!(Session::validators(), vec![11, 21]);
<Module<Test>>::reward_by_ids(vec![(11, 1)]);
<Pallet<Test>>::reward_by_ids(vec![(11, 1)]);
// Compute total payout now for whole duration as other parameter won't change
let total_payout_1 = current_total_payout_for_duration(reward_time_per_era());
@@ -265,7 +265,7 @@ fn rewards_should_work() {
);
assert_eq!(
*mock::staking_events().last().unwrap(),
RawEvent::EraPayout(1, total_payout_1, maximum_payout - total_payout_1)
Event::EraPayout(1, total_payout_1, maximum_payout - total_payout_1)
);
mock::make_all_reward_payment(1);
@@ -482,8 +482,8 @@ fn nominating_and_rewards_should_work() {
// the total reward for era 0
let total_payout_0 = current_total_payout_for_duration(reward_time_per_era());
<Module<Test>>::reward_by_ids(vec![(41, 1)]);
<Module<Test>>::reward_by_ids(vec![(31, 1)]);
<Pallet<Test>>::reward_by_ids(vec![(41, 1)]);
<Pallet<Test>>::reward_by_ids(vec![(31, 1)]);
mock::start_active_era(1);
@@ -524,8 +524,8 @@ fn nominating_and_rewards_should_work() {
// the total reward for era 1
let total_payout_1 = current_total_payout_for_duration(reward_time_per_era());
<Module<Test>>::reward_by_ids(vec![(21, 2)]);
<Module<Test>>::reward_by_ids(vec![(11, 1)]);
<Pallet<Test>>::reward_by_ids(vec![(21, 2)]);
<Pallet<Test>>::reward_by_ids(vec![(11, 1)]);
mock::start_active_era(2);
@@ -779,7 +779,7 @@ fn forcing_new_era_works() {
assert_eq!(active_era(), 1);
// no era change.
ForceEra::put(Forcing::ForceNone);
ForceEra::<Test>::put(Forcing::ForceNone);
start_session(4);
assert_eq!(active_era(), 1);
@@ -795,7 +795,7 @@ fn forcing_new_era_works() {
// back to normal.
// this immediately starts a new session.
ForceEra::put(Forcing::NotForcing);
ForceEra::<Test>::put(Forcing::NotForcing);
start_session(8);
assert_eq!(active_era(), 1);
@@ -803,7 +803,7 @@ fn forcing_new_era_works() {
start_session(9);
assert_eq!(active_era(), 2);
// forceful change
ForceEra::put(Forcing::ForceAlways);
ForceEra::<Test>::put(Forcing::ForceAlways);
start_session(10);
assert_eq!(active_era(), 2);
@@ -815,10 +815,10 @@ fn forcing_new_era_works() {
assert_eq!(active_era(), 4);
// just one forceful change
ForceEra::put(Forcing::ForceNew);
ForceEra::<Test>::put(Forcing::ForceNew);
start_session(13);
assert_eq!(active_era(), 5);
assert_eq!(ForceEra::get(), Forcing::NotForcing);
assert_eq!(ForceEra::<Test>::get(), Forcing::NotForcing);
start_session(14);
assert_eq!(active_era(), 6);
@@ -917,7 +917,7 @@ fn reward_destination_works() {
// Compute total payout now for whole duration as other parameter won't change
let total_payout_0 = current_total_payout_for_duration(reward_time_per_era());
<Module<Test>>::reward_by_ids(vec![(11, 1)]);
<Pallet<Test>>::reward_by_ids(vec![(11, 1)]);
mock::start_active_era(1);
mock::make_all_reward_payment(0);
@@ -940,7 +940,7 @@ fn reward_destination_works() {
// Compute total payout now for whole duration as other parameter won't change
let total_payout_1 = current_total_payout_for_duration(reward_time_per_era());
<Module<Test>>::reward_by_ids(vec![(11, 1)]);
<Pallet<Test>>::reward_by_ids(vec![(11, 1)]);
mock::start_active_era(2);
mock::make_all_reward_payment(1);
@@ -968,7 +968,7 @@ fn reward_destination_works() {
// Compute total payout now for whole duration as other parameter won't change
let total_payout_2 = current_total_payout_for_duration(reward_time_per_era());
<Module<Test>>::reward_by_ids(vec![(11, 1)]);
<Pallet<Test>>::reward_by_ids(vec![(11, 1)]);
mock::start_active_era(3);
mock::make_all_reward_payment(2);
@@ -1015,7 +1015,7 @@ fn validator_payment_prefs_work() {
// Compute total payout now for whole duration as other parameter won't change
let total_payout_1 = current_total_payout_for_duration(reward_time_per_era());
let exposure_1 = Staking::eras_stakers(Staking::active_era().unwrap().index, 11);
<Module<Test>>::reward_by_ids(vec![(11, 1)]);
<Pallet<Test>>::reward_by_ids(vec![(11, 1)]);
mock::start_active_era(2);
mock::make_all_reward_payment(1);
@@ -1508,8 +1508,8 @@ fn reward_to_stake_works() {
// Compute total payout now for whole duration as other parameter won't change
let total_payout_0 = current_total_payout_for_duration(reward_time_per_era());
<Module<Test>>::reward_by_ids(vec![(11, 1)]);
<Module<Test>>::reward_by_ids(vec![(21, 1)]);
<Pallet<Test>>::reward_by_ids(vec![(11, 1)]);
<Pallet<Test>>::reward_by_ids(vec![(21, 1)]);
// New era --> rewards are paid --> stakes are changed
mock::start_active_era(1);
@@ -2009,10 +2009,10 @@ fn reward_from_authorship_event_handler_works() {
assert_eq!(<pallet_authorship::Pallet<Test>>::author(), 11);
<Module<Test>>::note_author(11);
<Module<Test>>::note_uncle(21, 1);
<Pallet<Test>>::note_author(11);
<Pallet<Test>>::note_uncle(21, 1);
// Rewarding the same two times works.
<Module<Test>>::note_uncle(11, 1);
<Pallet<Test>>::note_uncle(11, 1);
// Not mandatory but must be coherent with rewards
assert_eq_uvec!(Session::validators(), vec![11, 21]);
@@ -2035,13 +2035,13 @@ fn add_reward_points_fns_works() {
// Not mandatory but must be coherent with rewards
assert_eq_uvec!(Session::validators(), vec![21, 11]);
<Module<Test>>::reward_by_ids(vec![
<Pallet<Test>>::reward_by_ids(vec![
(21, 1),
(11, 1),
(11, 1),
]);
<Module<Test>>::reward_by_ids(vec![
<Pallet<Test>>::reward_by_ids(vec![
(21, 1),
(11, 1),
(11, 1),
@@ -2084,7 +2084,7 @@ fn era_is_always_same_length() {
assert_eq!(Staking::eras_start_session_index(current_era()).unwrap(), session_per_era * 2u32);
let session = Session::current_index();
ForceEra::put(Forcing::ForceNew);
ForceEra::<Test>::put(Forcing::ForceNew);
advance_session();
advance_session();
assert_eq!(current_era(), 3);
@@ -2992,13 +2992,13 @@ fn claim_reward_at_the_last_era_and_no_double_claim_and_invalid_claim() {
Payee::<Test>::insert(11, RewardDestination::Controller);
Payee::<Test>::insert(101, RewardDestination::Controller);
<Module<Test>>::reward_by_ids(vec![(11, 1)]);
<Pallet<Test>>::reward_by_ids(vec![(11, 1)]);
// Compute total payout now for whole duration as other parameter won't change
let total_payout_0 = current_total_payout_for_duration(reward_time_per_era());
mock::start_active_era(1);
<Module<Test>>::reward_by_ids(vec![(11, 1)]);
<Pallet<Test>>::reward_by_ids(vec![(11, 1)]);
// Change total issuance in order to modify total payout
let _ = Balances::deposit_creating(&999, 1_000_000_000);
// Compute total payout now for whole duration as other parameter won't change
@@ -3007,7 +3007,7 @@ fn claim_reward_at_the_last_era_and_no_double_claim_and_invalid_claim() {
mock::start_active_era(2);
<Module<Test>>::reward_by_ids(vec![(11, 1)]);
<Pallet<Test>>::reward_by_ids(vec![(11, 1)]);
// Change total issuance in order to modify total payout
let _ = Balances::deposit_creating(&999, 1_000_000_000);
// Compute total payout now for whole duration as other parameter won't change
@@ -3168,7 +3168,7 @@ fn test_max_nominator_rewarded_per_validator_and_cant_steal_someone_else_reward(
}
mock::start_active_era(1);
<Module<Test>>::reward_by_ids(vec![(11, 1)]);
<Pallet<Test>>::reward_by_ids(vec![(11, 1)]);
// compute and ensure the reward amount is greater than zero.
let _ = current_total_payout_for_duration(reward_time_per_era());
@@ -3832,7 +3832,7 @@ fn do_not_die_when_active_is_ed() {
fn on_finalize_weight_is_nonzero() {
ExtBuilder::default().build_and_execute(|| {
let on_finalize_weight = <Test as frame_system::Config>::DbWeight::get().reads(1);
assert!(Staking::on_initialize(1) >= on_finalize_weight);
assert!(<Staking as Hooks<u64>>::on_initialize(1) >= on_finalize_weight);
})
}
@@ -3954,7 +3954,7 @@ mod election_data_provider {
assert_eq!(staking_events().len(), 1);
assert_eq!(
*staking_events().last().unwrap(),
RawEvent::StakingElection
Event::StakingElection
);
for b in 21..45 {
@@ -3968,7 +3968,7 @@ mod election_data_provider {
assert_eq!(staking_events().len(), 3);
assert_eq!(
*staking_events().last().unwrap(),
RawEvent::StakingElection
Event::StakingElection
);
})
}