Skip to content

Commit

Permalink
fix benchmarks
Browse files Browse the repository at this point in the history
  • Loading branch information
lemunozm committed Sep 23, 2024
1 parent 6da9a85 commit 3304a10
Show file tree
Hide file tree
Showing 3 changed files with 17 additions and 5 deletions.
2 changes: 1 addition & 1 deletion libs/traits/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -154,7 +154,7 @@ pub trait PoolMutate<AccountId, PoolId> {
#[cfg(feature = "runtime-benchmarks")]
fn fund_depositor(_: &AccountId) {}

/// Creates the heviest pool possible
/// Creates the heaviest pool possible
#[cfg(feature = "runtime-benchmarks")]
fn create_heaviest_pool(_: PoolId, _: AccountId, _: Self::CurrencyId, _num_tranches: u32) {}
}
Expand Down
18 changes: 14 additions & 4 deletions pallets/pool-registry/src/benchmarking.rs
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@

use frame_benchmarking::{v2::*, whitelisted_caller};
use frame_system::RawOrigin;
use sp_std::cmp::min;
use sp_std::{cmp::min, vec::Vec};

use super::*;

Expand All @@ -24,7 +24,12 @@ fn init_mocks() {
crate::mock::PoolSystem::mock_worst_pool_changes(|changes| changes.unwrap_or(0));
crate::mock::PoolSystem::mock_create(|_, _, _, _, _, _, _| Ok(()));
crate::mock::PoolSystem::mock_update(|_, changes| Ok(UpdateState::Stored(changes)));
crate::mock::PoolSystem::mock_execute_update(|_| Ok(0));
crate::mock::PoolSystem::mock_execute_update(|_| {
crate::mock::PoolSystem::mock_execute_update(|_| {
Err(DispatchError::Other("Second time fails"))
});
Ok(0)
});
crate::mock::Permissions::mock_add(|_, _, _| Ok(()));
crate::mock::Permissions::mock_has(|_, _, _| true);
}
Expand Down Expand Up @@ -125,14 +130,19 @@ mod benchmarks {

assert_eq!(update_state, UpdateState::Stored(n));

// TODO overpass T::MinUpdateDelay to be able to execute it correctly

#[extrinsic_call]
_(
RawOrigin::Signed(whitelisted_caller()),
T::PoolId::default(),
);

// If the above is executed correctly, executing again will fail:
assert!(Pallet::<T>::execute_update(
RawOrigin::Signed(whitelisted_caller()).into(),
T::PoolId::default(),
)
.is_err());

Ok(())
}

Expand Down
2 changes: 2 additions & 0 deletions pallets/pool-system/src/impls.rs
Original file line number Diff line number Diff line change
Expand Up @@ -290,6 +290,8 @@ impl<T: Config> PoolMutate<T::AccountId, T::PoolId> for Pallet<T> {
ScheduledUpdate::<T>::try_get(pool_id).map_err(|_| Error::<T>::NoScheduledUpdate)?;

let now = T::Time::now();

#[cfg(not(feature = "runtime-benchmarks"))]
ensure!(
now >= update.submitted_at.ensure_add(T::MinUpdateDelay::get())?,
Error::<T>::ScheduledTimeHasNotPassed
Expand Down

0 comments on commit 3304a10

Please sign in to comment.