Benchmark Timestamp Pallet (#4891)

* Add selected_benchmark! macro.

* Use selected_benchmark! in Identity pallet.

* Implement timestamp pallet benchmark.

* Fix some nits.

* Bump impl_version.
This commit is contained in:
Marcio Diaz
2020-02-12 11:00:08 +01:00
committed by GitHub
parent b34df420f8
commit ae70b10326
6 changed files with 163 additions and 43 deletions
@@ -1333,6 +1333,55 @@ pub trait BenchmarkingSetup<T, Call, RawOrigin> {
fn instance(&self, components: &[(BenchmarkParameter, u32)]) -> Result<(Call, RawOrigin), &'static str>;
}
/// Creates a `SelectedBenchmark` enum implementing `BenchmarkingSetup`.
///
/// Every variant must implement [`BenchmarkingSetup`](crate::traits::BenchmarkingSetup).
///
/// ```nocompile
///
/// struct Transfer;
/// impl BenchmarkingSetup for Transfer { ... }
///
/// struct SetBalance;
/// impl BenchmarkingSetup for SetBalance { ... }
///
/// selected_benchmark!(Transfer, SetBalance);
/// ```
#[macro_export]
macro_rules! selected_benchmark {
($($bench:ident),*) => {
// The list of available benchmarks for this pallet.
enum SelectedBenchmark {
$( $bench, )*
}
// Allow us to select a benchmark from the list of available benchmarks.
impl<T: Trait> $crate::traits::BenchmarkingSetup<T, Call<T>, RawOrigin<T::AccountId>> for SelectedBenchmark {
fn components(&self) -> Vec<(BenchmarkParameter, u32, u32)> {
match self {
$( Self::$bench => <$bench as $crate::traits::BenchmarkingSetup<
T,
Call<T>,
RawOrigin<T::AccountId>,
>>::components(&$bench), )*
}
}
fn instance(&self, components: &[(BenchmarkParameter, u32)])
-> Result<(Call<T>, RawOrigin<T::AccountId>), &'static str>
{
match self {
$( Self::$bench => <$bench as $crate::traits::BenchmarkingSetup<
T,
Call<T>,
RawOrigin<T::AccountId>,
>>::instance(&$bench, components), )*
}
}
}
};
}
#[cfg(test)]
mod tests {
use super::*;