Skip to content

Commit

Permalink
Add event
Browse files Browse the repository at this point in the history
  • Loading branch information
Dinonard committed Feb 6, 2025
1 parent b4ccdcc commit c7f8b19
Show file tree
Hide file tree
Showing 3 changed files with 19 additions and 3 deletions.
6 changes: 6 additions & 0 deletions pallets/dapp-staking/src/benchmarking/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -1151,6 +1151,12 @@ mod benchmarks {
_(RawOrigin::Root, tier_params.clone());

assert_eq!(StaticTierParams::<T>::get(), tier_params);
assert_last_event::<T>(
Event::<T>::NewTierParameters {
params: tier_params,
}
.into(),
);
}

impl_benchmark_test_suite!(
Expand Down
12 changes: 9 additions & 3 deletions pallets/dapp-staking/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -316,6 +316,10 @@ pub mod pallet {
ExpiredEntriesRemoved { account: T::AccountId, count: u16 },
/// Privileged origin has forced a new era and possibly a subperiod to start from next block.
Force { forcing_type: ForcingType },
/// Tier parameters, used to calculate tier configuration, have been updated, and will be applicable from next era.
NewTierParameters {
params: TierParameters<T::NumberOfTiers>,
},
}

#[pallet::error]
Expand Down Expand Up @@ -1531,13 +1535,15 @@ pub mod pallet {
#[pallet::weight(T::WeightInfo::set_static_tier_params())]
pub fn set_static_tier_params(
origin: OriginFor<T>,
tier_params: TierParameters<T::NumberOfTiers>,
params: TierParameters<T::NumberOfTiers>,
) -> DispatchResult {
Self::ensure_pallet_enabled()?;
ensure_root(origin)?;
ensure!(tier_params.is_valid(), Error::<T>::InvalidTierParams);
ensure!(params.is_valid(), Error::<T>::InvalidTierParams);

StaticTierParams::<T>::set(params.clone());

StaticTierParams::<T>::set(tier_params);
Self::deposit_event(Event::<T>::NewTierParameters { params });

Ok(())
}
Expand Down
4 changes: 4 additions & 0 deletions pallets/dapp-staking/src/test/tests.rs
Original file line number Diff line number Diff line change
Expand Up @@ -3543,6 +3543,10 @@ fn set_static_tier_params_works() {
RuntimeOrigin::root(),
tier_params.clone()
));

assert_eq!(StaticTierParams::<Test>::get(), tier_params);
System::assert_last_event(RuntimeEvent::DappStaking(Event::NewTierParameters {
params: tier_params,
}));
})
}

0 comments on commit c7f8b19

Please sign in to comment.