Skip to content
This repository has been archived by the owner on Feb 29, 2024. It is now read-only.

Commit

Permalink
Companion for 96, fix benchmark
Browse files Browse the repository at this point in the history
  • Loading branch information
boundless-forest committed Jun 9, 2022
1 parent 734a603 commit ef11f5f
Showing 1 changed file with 21 additions and 21 deletions.
42 changes: 21 additions & 21 deletions modules/fee-market/src/benchmarking.rs
Original file line number Diff line number Diff line change
Expand Up @@ -21,14 +21,14 @@

use super::*;
use crate::Pallet as FeeMarket;
use frame_benchmarking::{account, benchmarks};
use frame_benchmarking::{account, benchmarks_instance_pallet};
use frame_support::assert_ok;
use frame_system::RawOrigin;
use sp_runtime::traits::Saturating;

const SEED: u32 = 0;

fn fee_market_ready<T: Config>() {
fn fee_market_ready<T: Config<I>, I: 'static>() {
let caller0: T::AccountId = account("source", 0, SEED);
let caller1: T::AccountId = account("source", 1, SEED);
let caller2: T::AccountId = account("source", 2, SEED);
Expand All @@ -41,78 +41,78 @@ fn fee_market_ready<T: Config>() {
assert_ne!(caller0, caller1);
assert_ne!(caller1, caller2);

assert_ok!(<FeeMarket<T>>::enroll_and_lock_collateral(
assert_ok!(<FeeMarket<T, I>>::enroll_and_lock_collateral(
RawOrigin::Signed(caller0).into(),
collateral,
None
));
assert_ok!(<FeeMarket<T>>::enroll_and_lock_collateral(
assert_ok!(<FeeMarket<T, I>>::enroll_and_lock_collateral(
RawOrigin::Signed(caller1).into(),
collateral,
None
));
assert_ok!(<FeeMarket<T>>::enroll_and_lock_collateral(
assert_ok!(<FeeMarket<T, I>>::enroll_and_lock_collateral(
RawOrigin::Signed(caller2).into(),
collateral,
None
));
assert_ok!(<FeeMarket<T>>::enroll_and_lock_collateral(
assert_ok!(<FeeMarket<T, I>>::enroll_and_lock_collateral(
RawOrigin::Signed(caller3).into(),
collateral,
None
));
assert!(<FeeMarket<T>>::market_fee().is_some());
assert_eq!(<FeeMarket<T>>::relayers().len(), 4);
assert!(<FeeMarket<T, I>>::market_fee().is_some());
assert_eq!(<FeeMarket<T, I>>::relayers().len(), 4);
}

benchmarks! {
benchmarks_instance_pallet! {
enroll_and_lock_collateral {
fee_market_ready::<T>();
fee_market_ready::<T, I>();
let relayer: T::AccountId = account("source", 100, SEED);
T::Currency::make_free_balance_be(&relayer, T::CollateralPerOrder::get().saturating_mul(10u32.into()));
let lock_collateral = T::CollateralPerOrder::get().saturating_mul(5u32.into());
}: enroll_and_lock_collateral(RawOrigin::Signed(relayer.clone()), lock_collateral, None)
verify {
assert!(<FeeMarket<T>>::is_enrolled(&relayer));
assert_eq!(<FeeMarket<T>>::relayers().len(), 5);
assert!(<FeeMarket<T, I>>::is_enrolled(&relayer));
assert_eq!(<FeeMarket<T, I>>::relayers().len(), 5);
}

update_locked_collateral {
fee_market_ready::<T>();
fee_market_ready::<T, I>();
let caller3: T::AccountId = account("source", 3, SEED);
let new_collateral = T::CollateralPerOrder::get().saturating_mul(5u32.into());
}: update_locked_collateral(RawOrigin::Signed(caller3.clone()), new_collateral)
verify {
let relayer = <FeeMarket<T>>::relayer(&caller3);
let relayer = <FeeMarket<T, I>>::relayer(&caller3);
assert_eq!(relayer.collateral, T::CollateralPerOrder::get().saturating_mul(5u32.into()));
}

update_relay_fee {
fee_market_ready::<T>();
fee_market_ready::<T, I>();
let caller3: T::AccountId = account("source", 3, SEED);
let new_fee = T::CollateralPerOrder::get().saturating_mul(10u32.into());
}: update_relay_fee(RawOrigin::Signed(caller3.clone()), new_fee)
verify {
let relayer = <FeeMarket<T>>::relayer(&caller3);
let relayer = <FeeMarket<T, I>>::relayer(&caller3);
assert_eq!(relayer.fee, T::CollateralPerOrder::get().saturating_mul(10u32.into()));
}

cancel_enrollment {
fee_market_ready::<T>();
fee_market_ready::<T, I>();
let caller1: T::AccountId = account("source", 1, SEED);
}: cancel_enrollment(RawOrigin::Signed(caller1.clone()))
verify {
assert!(!<FeeMarket<T>>::is_enrolled(&caller1));
assert_eq!(<FeeMarket<T>>::relayers().len(), 3);
assert!(!<FeeMarket<T, I>>::is_enrolled(&caller1));
assert_eq!(<FeeMarket<T, I>>::relayers().len(), 3);
}

set_slash_protect {
}:set_slash_protect(RawOrigin::Root, T::CollateralPerOrder::get().saturating_mul(1u32.into()))

set_assigned_relayers_number{
fee_market_ready::<T>();
fee_market_ready::<T, I>();
}: set_assigned_relayers_number(RawOrigin::Root, 1)
verify {
assert_eq!(<FeeMarket<T>>::assigned_relayers().unwrap().len(), 1);
assert_eq!(<FeeMarket<T, I>>::assigned_relayers().unwrap().len(), 1);
}
}

0 comments on commit ef11f5f

Please sign in to comment.