pallet_staking_async_rc_client/
benchmarking.rs1use alloc::vec::Vec;
21use frame_benchmarking::v2::*;
22use frame_system::RawOrigin;
23use xcm::latest::Location;
24use xcm_builder::EnsureDelivery;
25
26use crate::*;
27
28pub struct Pallet<T: Config>(crate::Pallet<T>);
30
31pub trait Config: crate::Config {
36 type DeliveryHelper: EnsureDelivery;
38
39 fn relay_chain_location() -> Location {
41 Location::parent()
42 }
43
44 fn account_to_location(account: Self::AccountId) -> Location;
46
47 fn generate_session_keys_and_proof(owner: Self::AccountId) -> (Vec<u8>, Vec<u8>);
51
52 fn setup_validator() -> Self::AccountId;
58}
59
60#[benchmarks]
61mod benchmarks {
62 use super::*;
63 use xcm_executor::traits::FeeReason;
64
65 #[benchmark]
66 fn set_keys() -> Result<(), BenchmarkError> {
67 let stash = T::setup_validator();
68 let (keys, proof) = T::generate_session_keys_and_proof(stash.clone());
69
70 let stash_location = T::account_to_location(stash.clone());
72 let dest = T::relay_chain_location();
73 T::DeliveryHelper::ensure_successful_delivery(
74 &stash_location,
75 &dest,
76 FeeReason::ChargeFees,
77 );
78
79 #[extrinsic_call]
80 crate::Pallet::<T>::set_keys(RawOrigin::Signed(stash), keys, proof, None);
81
82 Ok(())
83 }
84
85 #[benchmark]
86 fn purge_keys() -> Result<(), BenchmarkError> {
87 let caller = T::setup_validator();
88 let (keys, proof) = T::generate_session_keys_and_proof(caller.clone());
89
90 let caller_location = T::account_to_location(caller.clone());
92 let dest = T::relay_chain_location();
93 T::DeliveryHelper::ensure_successful_delivery(
94 &caller_location,
95 &dest,
96 FeeReason::ChargeFees,
97 );
98 crate::Pallet::<T>::set_keys(RawOrigin::Signed(caller.clone()).into(), keys, proof, None)?;
99
100 T::DeliveryHelper::ensure_successful_delivery(
102 &caller_location,
103 &dest,
104 FeeReason::ChargeFees,
105 );
106
107 #[extrinsic_call]
108 crate::Pallet::<T>::purge_keys(RawOrigin::Signed(caller), None);
109
110 Ok(())
111 }
112}