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:
Shawn Tabrizi
2020-04-07 11:35:00 +02:00
committed by GitHub
parent 3e9e5e1bac
commit d3cc051419
28 changed files with 667 additions and 116 deletions
@@ -19,6 +19,8 @@
#![cfg_attr(not(feature = "std"), no_std)]
mod mock;
use sp_std::prelude::*;
use sp_std::vec;
@@ -42,16 +44,33 @@ benchmarks! {
set_keys {
let n in 1 .. MAX_NOMINATIONS as u32;
let validator = create_validator_with_nominators::<T>(n, MAX_NOMINATIONS as u32)?;
let v_stash = create_validator_with_nominators::<T>(n, MAX_NOMINATIONS as u32)?;
let v_controller = pallet_staking::Module::<T>::bonded(&v_stash).ok_or("not stash")?;
let keys = T::Keys::default();
let proof: Vec<u8> = vec![0,1,2,3];
}: _(RawOrigin::Signed(validator), keys, proof)
}: _(RawOrigin::Signed(v_controller), keys, proof)
purge_keys {
let n in 1 .. MAX_NOMINATIONS as u32;
let validator = create_validator_with_nominators::<T>(n, MAX_NOMINATIONS as u32)?;
let v_stash = create_validator_with_nominators::<T>(n, MAX_NOMINATIONS as u32)?;
let v_controller = pallet_staking::Module::<T>::bonded(&v_stash).ok_or("not stash")?;
let keys = T::Keys::default();
let proof: Vec<u8> = vec![0,1,2,3];
Session::<T>::set_keys(RawOrigin::Signed(validator.clone()).into(), keys, proof)?;
}: _(RawOrigin::Signed(validator))
Session::<T>::set_keys(RawOrigin::Signed(v_controller.clone()).into(), keys, proof)?;
}: _(RawOrigin::Signed(v_controller))
}
#[cfg(test)]
mod tests {
use super::*;
use crate::mock::{new_test_ext, Test};
use frame_support::assert_ok;
#[test]
fn test_benchmarks() {
new_test_ext().execute_with(|| {
assert_ok!(test_benchmark_set_keys::<Test>());
assert_ok!(test_benchmark_purge_keys::<Test>());
});
}
}