mirror of
https://github.com/pezkuwichain/pezkuwi-subxt.git
synced 2026-06-12 22:51:13 +00:00
Generate Unit Tests for Benchmarks (#5527)
* Update to latest staking * generate tests for benchmarking * add tests, fix warnings * starting on democracy * impl_benchmark_tests * Way more readable * add test feature flag (does this work?) * Fix `successful_origin` impl * democracry benchmark tests * Fix example benchmarks, add tests * identity benchmark tests * Update im-online benchmark tests * try to add session benchmarking tests (problem with mock) * staking and timestamp * add test for treasury, issue with dynamic contains * utility * Vesting * test instead of check * hide until we figure out what is wrong * add docs * close code * Create custom mock for session-pallet-benchmarking * Use refcell pattern * make un-pub * test-linux-stable includes `runtime-benchmarks` feature * Revert "test-linux-stable includes `runtime-benchmarks` feature" This reverts commit a2dab38abd18ac3eb8a6220e4a00e687740bd38c. * run tests in `--release` * undo balance change * build wasm
This commit is contained in:
@@ -98,8 +98,8 @@ pub fn create_validators_with_nominators_for_era<T: Trait>(v: u32, n: u32) -> Re
|
||||
Ok(())
|
||||
}
|
||||
|
||||
// This function generates one validator being nominated by n nominators.
|
||||
// It starts an era and creates pending payouts.
|
||||
// This function generates one validator being nominated by n nominators, and returns
|
||||
//the validator stash account. It also starts an era and creates pending payouts.
|
||||
pub fn create_validator_with_nominators<T: Trait>(n: u32, upper_bound: u32) -> Result<T::AccountId, &'static str> {
|
||||
let mut points_total = 0;
|
||||
let mut points_individual = Vec::new();
|
||||
@@ -114,7 +114,7 @@ pub fn create_validator_with_nominators<T: Trait>(n: u32, upper_bound: u32) -> R
|
||||
let stash_lookup: <T::Lookup as StaticLookup>::Source = T::Lookup::unlookup(v_stash.clone());
|
||||
|
||||
points_total += 10;
|
||||
points_individual.push((v_stash, 10));
|
||||
points_individual.push((v_stash.clone(), 10));
|
||||
|
||||
// Give the validator n nominators, but keep total users in the system the same.
|
||||
for i in 0 .. upper_bound {
|
||||
@@ -144,7 +144,7 @@ pub fn create_validator_with_nominators<T: Trait>(n: u32, upper_bound: u32) -> R
|
||||
let total_payout = T::Currency::minimum_balance() * 1000.into();
|
||||
<ErasValidatorReward<T>>::insert(current_era, total_payout);
|
||||
|
||||
Ok(v_controller)
|
||||
Ok(v_stash)
|
||||
}
|
||||
|
||||
benchmarks! {
|
||||
@@ -368,16 +368,10 @@ benchmarks! {
|
||||
|
||||
#[cfg(test)]
|
||||
mod tests {
|
||||
use crate::*;
|
||||
use crate::mock::*;
|
||||
use super::*;
|
||||
use crate::mock::{ExtBuilder, Test, Balances, Staking, Origin};
|
||||
use frame_support::assert_ok;
|
||||
|
||||
use crate::benchmarking::{
|
||||
create_validators_with_nominators_for_era,
|
||||
create_validator_with_nominators,
|
||||
SelectedBenchmark,
|
||||
};
|
||||
|
||||
#[test]
|
||||
fn create_validators_with_nominators_for_era_works() {
|
||||
ExtBuilder::default().has_stakers(false).build().execute_with(|| {
|
||||
@@ -399,19 +393,16 @@ mod tests {
|
||||
ExtBuilder::default().has_stakers(false).build().execute_with(|| {
|
||||
let n = 10;
|
||||
|
||||
let validator = create_validator_with_nominators::<Test>(
|
||||
let validator_stash = create_validator_with_nominators::<Test>(
|
||||
n,
|
||||
MAX_NOMINATIONS as u32,
|
||||
).unwrap();
|
||||
|
||||
let current_era = CurrentEra::get().unwrap();
|
||||
let controller = validator;
|
||||
let ledger = Staking::ledger(&controller).unwrap();
|
||||
let stash = ledger.stash;
|
||||
|
||||
let original_free_balance = Balances::free_balance(&stash);
|
||||
assert_ok!(Staking::payout_stakers(Origin::signed(1337), stash, current_era));
|
||||
let new_free_balance = Balances::free_balance(&stash);
|
||||
let original_free_balance = Balances::free_balance(&validator_stash);
|
||||
assert_ok!(Staking::payout_stakers(Origin::signed(1337), validator_stash, current_era));
|
||||
let new_free_balance = Balances::free_balance(&validator_stash);
|
||||
|
||||
assert!(original_free_balance < new_free_balance);
|
||||
});
|
||||
@@ -434,4 +425,33 @@ mod tests {
|
||||
assert_ok!(closure_to_benchmark());
|
||||
});
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn test_benchmarks() {
|
||||
ExtBuilder::default().has_stakers(false).build().execute_with(|| {
|
||||
assert_ok!(test_benchmark_bond::<Test>());
|
||||
assert_ok!(test_benchmark_bond_extra::<Test>());
|
||||
assert_ok!(test_benchmark_unbond::<Test>());
|
||||
assert_ok!(test_benchmark_withdraw_unbonded::<Test>());
|
||||
assert_ok!(test_benchmark_validate::<Test>());
|
||||
assert_ok!(test_benchmark_nominate::<Test>());
|
||||
assert_ok!(test_benchmark_chill::<Test>());
|
||||
assert_ok!(test_benchmark_set_payee::<Test>());
|
||||
assert_ok!(test_benchmark_set_controller::<Test>());
|
||||
assert_ok!(test_benchmark_set_validator_count::<Test>());
|
||||
assert_ok!(test_benchmark_force_no_eras::<Test>());
|
||||
assert_ok!(test_benchmark_force_new_era::<Test>());
|
||||
assert_ok!(test_benchmark_force_new_era_always::<Test>());
|
||||
assert_ok!(test_benchmark_set_invulnerables::<Test>());
|
||||
assert_ok!(test_benchmark_force_unstake::<Test>());
|
||||
assert_ok!(test_benchmark_cancel_deferred_slash::<Test>());
|
||||
assert_ok!(test_benchmark_payout_stakers::<Test>());
|
||||
assert_ok!(test_benchmark_rebond::<Test>());
|
||||
assert_ok!(test_benchmark_set_history_depth::<Test>());
|
||||
assert_ok!(test_benchmark_reap_stash::<Test>());
|
||||
assert_ok!(test_benchmark_new_era::<Test>());
|
||||
assert_ok!(test_benchmark_do_slash::<Test>());
|
||||
assert_ok!(test_benchmark_payout_all::<Test>());
|
||||
});
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user