forked from open-web3-stack/open-runtime-module-library
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Add benchmarks to oracle (open-web3-stack#985)
* Add benchmarks to oracle * Add cfg for runtime-benchmarks * toml format
- Loading branch information
Showing
5 changed files
with
103 additions
and
4 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,55 @@ | ||
use super::*; | ||
use crate::Pallet as Oracle; | ||
|
||
use frame_benchmarking::v2::*; | ||
|
||
use frame_support::assert_ok; | ||
use frame_system::{Pallet as System, RawOrigin}; | ||
use sp_std::vec; | ||
|
||
#[instance_benchmarks] | ||
mod benchmarks { | ||
use super::*; | ||
|
||
#[benchmark] | ||
fn feed_values(x: Linear<1, { T::BenchmarkHelper::get_currency_id_value_pairs().len() as u32 }>) { | ||
// Register the caller | ||
let caller: T::AccountId = whitelisted_caller(); | ||
T::Members::add(&caller); | ||
|
||
let values = T::BenchmarkHelper::get_currency_id_value_pairs()[..x as usize] | ||
.to_vec() | ||
.try_into() | ||
.expect("Must succeed since at worst the length remained the same."); | ||
|
||
#[extrinsic_call] | ||
_(RawOrigin::Signed(caller.clone()), values); | ||
|
||
assert!(HasDispatched::<T, I>::get().contains(&caller)); | ||
} | ||
|
||
#[benchmark] | ||
fn on_finalize() { | ||
// Register the caller | ||
let caller: T::AccountId = whitelisted_caller(); | ||
T::Members::add(&caller); | ||
|
||
// Feed some values before running `on_finalize` hook | ||
System::<T>::set_block_number(1u32.into()); | ||
let values = T::BenchmarkHelper::get_currency_id_value_pairs(); | ||
assert_ok!(Oracle::<T, I>::feed_values(RawOrigin::Signed(caller).into(), values)); | ||
|
||
#[block] | ||
{ | ||
Oracle::<T, I>::on_finalize(System::<T>::block_number()); | ||
} | ||
|
||
assert!(!HasDispatched::<T, I>::exists()); | ||
} | ||
|
||
impl_benchmark_test_suite! { | ||
Oracle, | ||
crate::mock::new_test_ext(), | ||
crate::mock::Test, | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters