referrerpolicy=no-referrer-when-downgrade

pallet_oracle/
benchmarking.rs

1// This file is part of Substrate.
2
3// Copyright (C) 2020-2025 Acala Foundation.
4// SPDX-License-Identifier: Apache-2.0
5
6// Licensed under the Apache License, Version 2.0 (the "License");
7// you may not use this file except in compliance with the License.
8// You may obtain a copy of the License at
9//
10// 	http://www.apache.org/licenses/LICENSE-2.0
11//
12// Unless required by applicable law or agreed to in writing, software
13// distributed under the License is distributed on an "AS IS" BASIS,
14// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
15// See the License for the specific language governing permissions and
16// limitations under the License.
17
18use super::*;
19use crate::Pallet as Oracle;
20
21use frame_benchmarking::v2::*;
22
23use frame_support::assert_ok;
24use frame_system::{Pallet as System, RawOrigin};
25
26#[instance_benchmarks]
27mod benchmarks {
28	use super::*;
29
30	#[benchmark]
31	fn feed_values(
32		x: Linear<0, { T::BenchmarkHelper::get_currency_id_value_pairs().len() as u32 }>,
33	) {
34		// Register the caller
35		let caller: T::AccountId = whitelisted_caller();
36		T::Members::add(&caller);
37
38		let values = T::BenchmarkHelper::get_currency_id_value_pairs()[..x as usize]
39			.to_vec()
40			.try_into()
41			.expect("Must succeed since at worst the length remained the same.");
42
43		#[extrinsic_call]
44		_(RawOrigin::Signed(caller.clone()), values);
45
46		assert!(HasDispatched::<T, I>::get().contains(&caller));
47	}
48
49	#[benchmark]
50	fn on_finalize() {
51		// Register the caller
52		let caller: T::AccountId = whitelisted_caller();
53		T::Members::add(&caller);
54
55		// Feed some values before running `on_finalize` hook
56		System::<T>::set_block_number(1u32.into());
57		let values = T::BenchmarkHelper::get_currency_id_value_pairs();
58		assert_ok!(Oracle::<T, I>::feed_values(RawOrigin::Signed(caller).into(), values));
59
60		#[block]
61		{
62			Oracle::<T, I>::on_finalize(System::<T>::block_number());
63		}
64
65		assert!(!HasDispatched::<T, I>::exists());
66	}
67
68	impl_benchmark_test_suite! {
69		Oracle,
70		crate::mock::new_test_ext(),
71		crate::mock::Test,
72	}
73}