#![cfg(feature = "runtime-benchmarks")]
use crate::*;
use frame_benchmarking::v2::*;
use frame_system::RawOrigin;
use sp_runtime::traits::Bounded;
const SEED: u32 = 0;
#[benchmarks]
mod benchmarks {
use super::*;
#[benchmark]
fn claim() {
let account_index = T::AccountIndex::from(SEED);
let caller: T::AccountId = whitelisted_caller();
T::Currency::make_free_balance_be(&caller, BalanceOf::<T>::max_value());
#[extrinsic_call]
_(RawOrigin::Signed(caller.clone()), account_index);
assert_eq!(Accounts::<T>::get(account_index).unwrap().0, caller);
}
#[benchmark]
fn transfer() -> Result<(), BenchmarkError> {
let account_index = T::AccountIndex::from(SEED);
let caller: T::AccountId = whitelisted_caller();
T::Currency::make_free_balance_be(&caller, BalanceOf::<T>::max_value());
let recipient: T::AccountId = account("recipient", 0, SEED);
let recipient_lookup = T::Lookup::unlookup(recipient.clone());
T::Currency::make_free_balance_be(&recipient, BalanceOf::<T>::max_value());
Pallet::<T>::claim(RawOrigin::Signed(caller.clone()).into(), account_index)?;
#[extrinsic_call]
_(RawOrigin::Signed(caller.clone()), recipient_lookup, account_index);
assert_eq!(Accounts::<T>::get(account_index).unwrap().0, recipient);
Ok(())
}
#[benchmark]
fn free() -> Result<(), BenchmarkError> {
let account_index = T::AccountIndex::from(SEED);
let caller: T::AccountId = whitelisted_caller();
T::Currency::make_free_balance_be(&caller, BalanceOf::<T>::max_value());
Pallet::<T>::claim(RawOrigin::Signed(caller.clone()).into(), account_index)?;
#[extrinsic_call]
_(RawOrigin::Signed(caller.clone()), account_index);
assert_eq!(Accounts::<T>::get(account_index), None);
Ok(())
}
#[benchmark]
fn force_transfer() -> Result<(), BenchmarkError> {
let account_index = T::AccountIndex::from(SEED);
let original: T::AccountId = account("original", 0, SEED);
T::Currency::make_free_balance_be(&original, BalanceOf::<T>::max_value());
let recipient: T::AccountId = account("recipient", 0, SEED);
let recipient_lookup = T::Lookup::unlookup(recipient.clone());
T::Currency::make_free_balance_be(&recipient, BalanceOf::<T>::max_value());
Pallet::<T>::claim(RawOrigin::Signed(original).into(), account_index)?;
#[extrinsic_call]
_(RawOrigin::Root, recipient_lookup, account_index, false);
assert_eq!(Accounts::<T>::get(account_index).unwrap().0, recipient);
Ok(())
}
#[benchmark]
fn freeze() -> Result<(), BenchmarkError> {
let account_index = T::AccountIndex::from(SEED);
let caller: T::AccountId = whitelisted_caller();
T::Currency::make_free_balance_be(&caller, BalanceOf::<T>::max_value());
Pallet::<T>::claim(RawOrigin::Signed(caller.clone()).into(), account_index)?;
#[extrinsic_call]
_(RawOrigin::Signed(caller.clone()), account_index);
assert_eq!(Accounts::<T>::get(account_index).unwrap().2, true);
Ok(())
}
impl_benchmark_test_suite!(Pallet, mock::new_test_ext(), mock::Test);
}