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
+21 -6
View File
@@ -671,26 +671,41 @@ mod benchmarking {
// This will measure the execution time of `set_dummy` for b in [1..1000] range.
set_dummy {
let b in ...;
let caller = account("caller", 0, 0);
}: set_dummy (RawOrigin::Signed(caller), b.into())
}: set_dummy (RawOrigin::Root, b.into())
// This will measure the execution time of `set_dummy` for b in [1..10] range.
another_set_dummy {
let b in 1 .. 10;
let caller = account("caller", 0, 0);
}: set_dummy (RawOrigin::Signed(caller), b.into())
}: set_dummy (RawOrigin::Root, b.into())
// This will measure the execution time of sorting a vector.
sort_vector {
let x in 0 .. 10000;
let mut m = Vec::<u32>::new();
for i in 0..x {
for i in (0..x).rev() {
m.push(i);
}
}: {
m.sort();
}
}
#[cfg(test)]
mod tests {
use super::*;
use crate::tests::{new_test_ext, Test};
use frame_support::assert_ok;
#[test]
fn test_benchmarks() {
new_test_ext().execute_with(|| {
assert_ok!(test_benchmark_accumulate_dummy::<Test>());
assert_ok!(test_benchmark_set_dummy::<Test>());
assert_ok!(test_benchmark_another_set_dummy::<Test>());
assert_ok!(test_benchmark_sort_vector::<Test>());
});
}
}
}
#[cfg(test)]
@@ -764,7 +779,7 @@ mod tests {
// This function basically just builds a genesis storage key/value store according to
// our desired mockup.
fn new_test_ext() -> sp_io::TestExternalities {
pub fn new_test_ext() -> sp_io::TestExternalities {
let mut t = frame_system::GenesisConfig::default().build_storage::<Test>().unwrap();
// We use default for brevity, but you can configure as desired if needed.
pallet_balances::GenesisConfig::<Test>::default().assimilate_storage(&mut t).unwrap();