#![cfg(feature = "runtime-benchmarks")]
use crate::*;
use bp_relayers::RewardsAccountOwner;
use frame_benchmarking::{benchmarks_instance_pallet, whitelisted_caller};
use frame_system::RawOrigin;
use sp_runtime::traits::One;
const REWARD_AMOUNT: u32 = u32::MAX;
pub struct Pallet<T: Config<I>, I: 'static = ()>(crate::Pallet<T, I>);
pub trait Config<I: 'static = ()>: crate::Config<I> {
fn bench_lane_id() -> Self::LaneId {
Self::LaneId::default()
}
fn prepare_rewards_account(
account_params: RewardsAccountParams<Self::LaneId>,
reward: Self::Reward,
);
fn deposit_account(account: Self::AccountId, balance: Self::Reward);
}
benchmarks_instance_pallet! {
claim_rewards {
let lane = T::bench_lane_id();
let account_params =
RewardsAccountParams::new(lane, *b"test", RewardsAccountOwner::ThisChain);
let relayer: T::AccountId = whitelisted_caller();
let reward = T::Reward::from(REWARD_AMOUNT);
T::prepare_rewards_account(account_params, reward);
RelayerRewards::<T, I>::insert(&relayer, account_params, reward);
}: _(RawOrigin::Signed(relayer), account_params)
verify {
}
register {
let relayer: T::AccountId = whitelisted_caller();
let valid_till = frame_system::Pallet::<T>::block_number()
.saturating_add(crate::Pallet::<T, I>::required_registration_lease())
.saturating_add(One::one())
.saturating_add(One::one());
T::deposit_account(relayer.clone(), crate::Pallet::<T, I>::required_stake());
}: _(RawOrigin::Signed(relayer.clone()), valid_till)
verify {
assert!(crate::Pallet::<T, I>::is_registration_active(&relayer));
}
deregister {
let relayer: T::AccountId = whitelisted_caller();
let valid_till = frame_system::Pallet::<T>::block_number()
.saturating_add(crate::Pallet::<T, I>::required_registration_lease())
.saturating_add(One::one())
.saturating_add(One::one());
T::deposit_account(relayer.clone(), crate::Pallet::<T, I>::required_stake());
crate::Pallet::<T, I>::register(RawOrigin::Signed(relayer.clone()).into(), valid_till).unwrap();
frame_system::Pallet::<T>::set_block_number(valid_till.saturating_add(One::one()));
}: _(RawOrigin::Signed(relayer.clone()))
verify {
assert!(!crate::Pallet::<T, I>::is_registration_active(&relayer));
}
slash_and_deregister {
let relayer: T::AccountId = whitelisted_caller();
let valid_till = frame_system::Pallet::<T>::block_number()
.saturating_add(crate::Pallet::<T, I>::required_registration_lease())
.saturating_add(One::one())
.saturating_add(One::one());
T::deposit_account(relayer.clone(), crate::Pallet::<T, I>::required_stake());
crate::Pallet::<T, I>::register(RawOrigin::Signed(relayer.clone()).into(), valid_till).unwrap();
let lane = T::bench_lane_id();
let slash_destination = RewardsAccountParams::new(lane, *b"test", RewardsAccountOwner::ThisChain);
T::prepare_rewards_account(slash_destination, Zero::zero());
}: {
crate::Pallet::<T, I>::slash_and_deregister(&relayer, slash_destination.into())
}
verify {
assert!(!crate::Pallet::<T, I>::is_registration_active(&relayer));
}
register_relayer_reward {
let lane = T::bench_lane_id();
let relayer: T::AccountId = whitelisted_caller();
let account_params =
RewardsAccountParams::new(lane, *b"test", RewardsAccountOwner::ThisChain);
}: {
crate::Pallet::<T, I>::register_relayer_reward(account_params, &relayer, One::one());
}
verify {
assert_eq!(RelayerRewards::<T, I>::get(relayer, &account_params), Some(One::one()));
}
impl_benchmark_test_suite!(Pallet, crate::mock::new_test_ext(), crate::mock::TestRuntime)
}