Skip to content

Commit

Permalink
fix: benchmarks
Browse files Browse the repository at this point in the history
  • Loading branch information
mustermeiszer committed May 6, 2024
1 parent b4854b1 commit 2aca1dd
Show file tree
Hide file tree
Showing 4 changed files with 19 additions and 14 deletions.
4 changes: 2 additions & 2 deletions pallets/pool-registry/src/mock.rs
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,7 @@ use cfg_types::{
};
use frame_support::{
derive_impl,
dispatch::DispatchResult,
dispatch::{DispatchResult, RawOrigin},
pallet_prelude::DispatchError,
parameter_types,
traits::{Contains, EnsureOriginWithArg, Hooks, PalletInfoAccess, SortedMembers},
Expand Down Expand Up @@ -125,7 +125,7 @@ impl EnsureOriginWithArg<RuntimeOrigin, PoolId> for All {

#[cfg(feature = "runtime-benchmarks")]
fn try_successful_origin(_: &PoolId) -> Result<RuntimeOrigin, ()> {
Ok(RuntimeOrigin::root())
Ok(RawOrigin::Root.into())
}
}

Expand Down
15 changes: 7 additions & 8 deletions pallets/pool-system/src/benchmarking.rs
Original file line number Diff line number Diff line change
Expand Up @@ -73,12 +73,10 @@ benchmarks! {
let m in 0..T::PoolFees::get_max_fees_per_bucket();

let admin: T::AccountId = create_admin::<T>(0);
let caller: T::AccountId = create_admin::<T>(1);
let max_reserve = MAX_RESERVE / 2;
prepare_asset_registry::<T>();
create_pool::<T>(1, m, admin.clone())?;
set_liquidity_admin::<T>(caller.clone())?;
}: set_max_reserve(RawOrigin::Signed(caller), POOL, max_reserve)
}: set_max_reserve(RawOrigin::Signed(admin), POOL, max_reserve)
verify {
assert_eq!(get_pool::<T>().reserve.max, max_reserve);
}
Expand Down Expand Up @@ -125,9 +123,9 @@ benchmarks! {
let admin: T::AccountId = create_admin::<T>(0);
prepare_asset_registry::<T>();
create_pool::<T>(n, m, admin.clone())?;

T::AssetsUnderManagementNAV::initialise(RawOrigin::Signed(admin.clone()).into(), POOL, 0.into())?;
unrestrict_epoch_close::<T>();

let investment = MAX_RESERVE / 2;
let investor = create_investor::<T>(0, TRANCHE, None)?;
let origin = RawOrigin::Signed(investor.clone()).into();
Expand Down Expand Up @@ -176,7 +174,6 @@ benchmarks! {
let admin: T::AccountId = create_admin::<T>(0);
prepare_asset_registry::<T>();
create_pool::<T>(n, m, admin.clone())?;

T::AssetsUnderManagementNAV::initialise(RawOrigin::Signed(admin.clone()).into(), POOL, 0.into())?;
unrestrict_epoch_close::<T>();

Expand Down Expand Up @@ -293,13 +290,14 @@ where

fn set_liquidity_admin<T: Config<PoolId = u64>>(target: T::AccountId) -> DispatchResult
where
T::Permission: Permissions<T::AccountId, Ok = ()>,
T::Permission: Permissions<T::AccountId>,
{
T::Permission::add(
PermissionScope::Pool(POOL),
target,
Role::PoolRole(PoolRole::LiquidityAdmin),
)
.map(|_| ())

Check warning on line 300 in pallets/pool-system/src/benchmarking.rs

View check run for this annotation

Codecov / codecov/patch

pallets/pool-system/src/benchmarking.rs#L300

Added line #L300 was not covered by tests
}

pub fn create_pool<T>(num_tranches: u32, num_pool_fees: u32, caller: T::AccountId) -> DispatchResult
Expand All @@ -314,7 +312,7 @@ where
let tranches = build_bench_input_tranches::<T>(num_tranches);
Pallet::<T>::create(
caller.clone(),
caller,
caller.clone(),

Check warning on line 315 in pallets/pool-system/src/benchmarking.rs

View check run for this annotation

Codecov / codecov/patch

pallets/pool-system/src/benchmarking.rs#L315

Added line #L315 was not covered by tests
POOL,
tranches,
AUSD_CURRENCY_ID,
Expand All @@ -323,7 +321,8 @@ where
.into_iter()
.map(|fee| (PoolFeeBucket::Top, fee))
.collect(),
)
)?;
set_liquidity_admin::<T>(caller)

Check warning on line 325 in pallets/pool-system/src/benchmarking.rs

View check run for this annotation

Codecov / codecov/patch

pallets/pool-system/src/benchmarking.rs#L325

Added line #L325 was not covered by tests
}

pub fn update_pool<T: Config<PoolId = u64>>(
Expand Down
8 changes: 7 additions & 1 deletion pallets/pool-system/src/mock.rs
Original file line number Diff line number Diff line change
Expand Up @@ -388,6 +388,12 @@ pub struct LiquidityAndPoolAdmin;
impl EnsureOriginWithArg<RuntimeOrigin, PoolId> for LiquidityAndPoolAdmin {
type Success = ();

#[cfg(feature = "runtime-benchmarks")]
fn try_origin(_: RuntimeOrigin, _: &PoolId) -> Result<Self::Success, RuntimeOrigin> {
Ok(())
}

#[cfg(not(feature = "runtime-benchmarks"))]
fn try_origin(o: RuntimeOrigin, _: &PoolId) -> Result<Self::Success, RuntimeOrigin> {
<RuntimeOrigin as Into<Result<RawOrigin<AccountId>, RuntimeOrigin>>>::into(o).and_then(
|r| match r {
Expand All @@ -406,7 +412,7 @@ impl EnsureOriginWithArg<RuntimeOrigin, PoolId> for LiquidityAndPoolAdmin {

#[cfg(feature = "runtime-benchmarks")]
fn try_successful_origin(_: &PoolId) -> Result<RuntimeOrigin, ()> {
Ok(RuntimeOrigin::Signed(DEFAULT_POOL_OWNER))
Ok(RawOrigin::Signed(DEFAULT_POOL_OWNER).into())
}
}

Expand Down
6 changes: 3 additions & 3 deletions runtime/common/src/pool.rs
Original file line number Diff line number Diff line change
Expand Up @@ -48,15 +48,15 @@ where
) {
Ok(())

Check warning on line 49 in runtime/common/src/pool.rs

View check run for this annotation

Codecov / codecov/patch

runtime/common/src/pool.rs#L49

Added line #L49 was not covered by tests
} else {
Err(T::RuntimeOrigin::from(RawOrigin::Signed(by)))
Err(RawOrigin::Signed(by).into())

Check warning on line 51 in runtime/common/src/pool.rs

View check run for this annotation

Codecov / codecov/patch

runtime/common/src/pool.rs#L51

Added line #L51 was not covered by tests
}
}
RawOrigin::None => Err(T::RuntimeOrigin::from(RawOrigin::None)),
RawOrigin::None => Err(RawOrigin::None.into()),

Check warning on line 54 in runtime/common/src/pool.rs

View check run for this annotation

Codecov / codecov/patch

runtime/common/src/pool.rs#L54

Added line #L54 was not covered by tests
})
}

#[cfg(feature = "runtime-benchmarks")]
fn try_successful_origin(_: &T::PoolId) -> Result<T::RuntimeOrigin, ()> {
Ok(T::RuntimeOrigin::root())
Ok(RawOrigin::Root.into())

Check warning on line 60 in runtime/common/src/pool.rs

View check run for this annotation

Codecov / codecov/patch

runtime/common/src/pool.rs#L59-L60

Added lines #L59 - L60 were not covered by tests
}
}

0 comments on commit 2aca1dd

Please sign in to comment.