Add runtime benchmarking suite to all runtimes (#1034)

* Add benchmarking suite to all runtimes

* Add `runtime-benchmarks` feature to `test-linux-stable`

* Update Cargo.lock

* Update Cargo.lock

* Update Cargo.lock

* "user" instead of "caller"

* undo these changes
This commit is contained in:
Shawn Tabrizi
2020-04-27 16:19:46 +02:00
committed by GitHub
parent a09ed5e519
commit b15cfb736d
9 changed files with 319 additions and 143 deletions
+29 -4
View File
@@ -445,7 +445,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 = system::GenesisConfig::default().build_storage::<Test>().unwrap();
// We use default for brevity, but you can configure as desired if needed.
balances::GenesisConfig::<Test>::default().assimilate_storage(&mut t).unwrap();
@@ -678,14 +678,21 @@ mod benchmarking {
let vesting = Some((100_000.into(), 1_000.into(), 100.into()));
let signature = sig::<T>(&secret_key, &account.encode());
super::Module::<T>::mint_claim(RawOrigin::Root.into(), eth_address, VALUE.into(), vesting)?;
assert_eq!(Claims::<T>::get(eth_address), Some(VALUE.into()));
}: _(RawOrigin::None, account, signature)
verify {
assert_eq!(Claims::<T>::get(eth_address), None);
}
// Benchmark `mint_claim` when there already exists `c` claims in storage.
mint_claim {
let c in ...;
let account = account("user", c, SEED);
let eth_address = account("eth_address", c, SEED);
let vesting = Some((100_000.into(), 1_000.into(), 100.into()));
}: _(RawOrigin::Root, account, VALUE.into(), vesting)
}: _(RawOrigin::Root, eth_address, VALUE.into(), vesting)
verify {
assert_eq!(Claims::<T>::get(eth_address), Some(VALUE.into()));
}
// Benchmark the time it takes to execute `validate_unsigned`
validate_unsigned {
@@ -720,8 +727,26 @@ mod benchmarking {
let data = account.using_encoded(to_ascii_hex);
}: {
for _ in 0 .. i {
let _maybe_signer = super::Module::<T>::eth_recover(&signature, &data);
assert!(super::Module::<T>::eth_recover(&signature, &data).is_some());
}
}
}
#[cfg(test)]
mod tests {
use super::*;
use crate::claims::tests::{new_test_ext, Test};
use frame_support::assert_ok;
#[test]
fn test_benchmarks() {
new_test_ext().execute_with(|| {
assert_ok!(test_benchmark_claim::<Test>());
assert_ok!(test_benchmark_mint_claim::<Test>());
assert_ok!(test_benchmark_validate_unsigned::<Test>());
assert_ok!(test_benchmark_keccak256::<Test>());
assert_ok!(test_benchmark_eth_recover::<Test>());
});
}
}
}