Skip to content

Commit

Permalink
Fix reap_identity benchmark
Browse files Browse the repository at this point in the history
  • Loading branch information
bkontur committed Jun 7, 2024
1 parent 61e3e5b commit 27811dd
Show file tree
Hide file tree
Showing 2 changed files with 34 additions and 0 deletions.
30 changes: 30 additions & 0 deletions relay/polkadot/src/impls.rs
Original file line number Diff line number Diff line change
Expand Up @@ -216,3 +216,33 @@ where
I::ensure_successful(asset_kind)
}
}

#[cfg(feature = "runtime-benchmarks")]
pub mod benchmarks {
use super::{xcm_config::CheckAccount, ExistentialDeposit};
use crate::Balances;
use frame_support::{
dispatch::RawOrigin,
traits::{Currency, EnsureOrigin},
};

pub struct InitializeReaperForBenchmarking<A, E>(core::marker::PhantomData<(A, E)>);
impl<A, O: Into<Result<RawOrigin<A>, O>> + From<RawOrigin<A>>, E: EnsureOrigin<O>>
EnsureOrigin<O> for InitializeReaperForBenchmarking<A, E>
{
type Success = E::Success;

fn try_origin(o: O) -> Result<E::Success, O> {
E::try_origin(o)
}

#[cfg(feature = "runtime-benchmarks")]
fn try_successful_origin() -> Result<O, ()> {
// initialize the XCM Check Account with the existential deposit
Balances::make_free_balance_be(&CheckAccount::get(), ExistentialDeposit::get());

// call the real implementation
E::try_successful_origin()
}
}
}
4 changes: 4 additions & 0 deletions relay/polkadot/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -860,7 +860,11 @@ impl pallet_identity::Config for Runtime {
impl identity_migrator::Config for Runtime {
type RuntimeEvent = RuntimeEvent;
// To be updated to `EnsureSigned` once the parachain is producing blocks.
#[cfg(not(feature = "runtime-benchmarks"))]
type Reaper = EnsureRoot<AccountId>;
#[cfg(feature = "runtime-benchmarks")]
type Reaper =
impls::benchmarks::InitializeReaperForBenchmarking<AccountId, EnsureRoot<AccountId>>;
type ReapIdentityHandler = ToParachainIdentityReaper<Runtime, Self::AccountId>;
type WeightInfo = weights::runtime_common_identity_migrator::WeightInfo<Runtime>;
}
Expand Down

0 comments on commit 27811dd

Please sign in to comment.