mirror of
https://github.com/pezkuwichain/pezkuwi-subxt.git
synced 2026-04-27 12:48:00 +00:00
Some benchmarks for phragmen (#2650)
* Add some benchmarks for phragmen * Fix dep. import. * Clean up with some macros. * more details. * Fix dual import. * Remove wrong assertions. * Add a few more.
This commit is contained in:
@@ -16,50 +16,13 @@
|
||||
|
||||
//! Tests for the module.
|
||||
|
||||
#![cfg(test)]
|
||||
|
||||
use super::*;
|
||||
use runtime_io::with_externalities;
|
||||
use phragmen;
|
||||
use srml_support::{assert_ok, assert_noop, assert_eq_uvec, EnumerableStorageMap};
|
||||
use mock::{Balances, Session, Staking, System, Timestamp, Test, ExtBuilder, Origin};
|
||||
use mock::*;
|
||||
use srml_support::traits::{Currency, ReservableCurrency};
|
||||
|
||||
#[inline]
|
||||
fn check_exposure(acc: u64) {
|
||||
let expo = Staking::stakers(&acc);
|
||||
assert_eq!(expo.total as u128, expo.own as u128 + expo.others.iter().map(|e| e.value as u128).sum::<u128>());
|
||||
}
|
||||
|
||||
#[inline]
|
||||
fn check_exposure_all() {
|
||||
Staking::current_elected().into_iter().for_each(|acc| check_exposure(acc));
|
||||
}
|
||||
|
||||
#[inline]
|
||||
fn assert_total_expo(acc: u64, val: u64) {
|
||||
let expo = Staking::stakers(&acc);
|
||||
assert_eq!(expo.total, val);
|
||||
}
|
||||
|
||||
#[inline]
|
||||
fn bond_validator(acc: u64, val: u64) {
|
||||
// a = controller
|
||||
// a + 1 = stash
|
||||
let _ = Balances::make_free_balance_be(&(acc+1), val);
|
||||
assert_ok!(Staking::bond(Origin::signed(acc+1), acc, val, RewardDestination::Controller));
|
||||
assert_ok!(Staking::validate(Origin::signed(acc), ValidatorPrefs::default()));
|
||||
}
|
||||
|
||||
#[inline]
|
||||
fn bond_nominator(acc: u64, val: u64, target: Vec<u64>) {
|
||||
// a = controller
|
||||
// a + 1 = stash
|
||||
let _ = Balances::make_free_balance_be(&(acc+1), val);
|
||||
assert_ok!(Staking::bond(Origin::signed(acc+1), acc, val, RewardDestination::Controller));
|
||||
assert_ok!(Staking::nominate(Origin::signed(acc), target));
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn basic_setup_works() {
|
||||
// Verifies initial conditions of mock
|
||||
|
||||
Reference in New Issue
Block a user