Skip to content

Commit

Permalink
impl BenchmarkHelper for ()
Browse files Browse the repository at this point in the history
  • Loading branch information
zjb0807 committed Apr 25, 2024
1 parent e576f86 commit 7e15e25
Show file tree
Hide file tree
Showing 3 changed files with 9 additions and 12 deletions.
3 changes: 1 addition & 2 deletions oracle/src/benchmarking.rs
Original file line number Diff line number Diff line change
Expand Up @@ -5,14 +5,13 @@ 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 }>) {
fn feed_values(x: Linear<0, { T::BenchmarkHelper::get_currency_id_value_pairs().len() as u32 }>) {
// Register the caller
let caller: T::AccountId = whitelisted_caller();
T::Members::add(&caller);
Expand Down
7 changes: 7 additions & 0 deletions oracle/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -63,6 +63,13 @@ pub trait BenchmarkHelper<OracleKey, OracleValue, L: Get<u32>> {
fn get_currency_id_value_pairs() -> BoundedVec<(OracleKey, OracleValue), L>;
}

#[cfg(feature = "runtime-benchmarks")]
impl<OracleKey, OracleValue, L: Get<u32>> BenchmarkHelper<OracleKey, OracleValue, L> for () {
fn get_currency_id_value_pairs() -> BoundedVec<(OracleKey, OracleValue), L> {
BoundedVec::default()

Check warning on line 69 in oracle/src/lib.rs

View check run for this annotation

Codecov / codecov/patch

oracle/src/lib.rs#L68-L69

Added lines #L68 - L69 were not covered by tests
}
}

#[frame_support::pallet]
pub mod module {
use super::*;
Expand Down
11 changes: 1 addition & 10 deletions oracle/src/mock.rs
Original file line number Diff line number Diff line change
Expand Up @@ -63,15 +63,6 @@ impl SortedMembers<AccountId> for Members {
}
}

#[cfg(feature = "runtime-benchmarks")]
pub struct BenchmarkHelper;
#[cfg(feature = "runtime-benchmarks")]
impl crate::BenchmarkHelper<Key, Value, MaxFeedValues> for BenchmarkHelper {
fn get_currency_id_value_pairs() -> BoundedVec<(Key, Value), MaxFeedValues> {
vec![(1, 1), (2, 2), (3, 3)].try_into().unwrap()
}
}

impl Config for Test {
type RuntimeEvent = RuntimeEvent;
type OnNewData = ();
Expand All @@ -85,7 +76,7 @@ impl Config for Test {
type MaxHasDispatchedSize = ConstU32<100>;
type MaxFeedValues = MaxFeedValues;
#[cfg(feature = "runtime-benchmarks")]
type BenchmarkHelper = BenchmarkHelper;
type BenchmarkHelper = ();
}

type Block = frame_system::mocking::MockBlock<Test>;
Expand Down

0 comments on commit 7e15e25

Please sign in to comment.