Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add event and unit test for stakes interval set #484

Merged
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
24 changes: 24 additions & 0 deletions pallets/admin-utils/tests/tests.rs
Original file line number Diff line number Diff line change
Expand Up @@ -1108,3 +1108,27 @@ fn test_sudo_set_min_delegate_take() {
assert_eq!(SubtensorModule::get_min_delegate_take(), to_be_set);
});
}

#[test]
fn test_sudo_set_target_stakes_per_interval() {
new_test_ext().execute_with(|| {
let to_be_set = 100;
let init_value = SubtensorModule::get_target_stakes_per_interval();
assert_eq!(
AdminUtils::sudo_set_target_stakes_per_interval(
<<Test as Config>::RuntimeOrigin>::signed(U256::from(1)),
to_be_set
),
Err(DispatchError::BadOrigin)
);
assert_eq!(
SubtensorModule::get_target_stakes_per_interval(),
init_value
);
assert_ok!(AdminUtils::sudo_set_target_stakes_per_interval(
<<Test as Config>::RuntimeOrigin>::root(),
to_be_set
));
assert_eq!(SubtensorModule::get_target_stakes_per_interval(), to_be_set);
});
}
2 changes: 2 additions & 0 deletions pallets/subtensor/src/events.rs
Original file line number Diff line number Diff line change
Expand Up @@ -130,5 +130,7 @@ mod events {
MaxDelegateTakeSet(u16),
/// minimum delegate take is set by sudo/admin transaction
MinDelegateTakeSet(u16),
/// the target stakes per interval is set by sudo/admin transaction
TargetStakesPerIntervalSet(u64),
}
}
5 changes: 4 additions & 1 deletion pallets/subtensor/src/utils.rs
Original file line number Diff line number Diff line change
Expand Up @@ -143,7 +143,10 @@ impl<T: Config> Pallet<T> {
Self::deposit_event(Event::WeightsMinStake(min_stake));
}
pub fn set_target_stakes_per_interval(target_stakes_per_interval: u64) {
TargetStakesPerInterval::<T>::set(target_stakes_per_interval)
TargetStakesPerInterval::<T>::set(target_stakes_per_interval);
Self::deposit_event(Event::TargetStakesPerIntervalSet(
target_stakes_per_interval,
));
}
pub fn set_stakes_this_interval_for_coldkey_hotkey(
coldkey: &T::AccountId,
Expand Down
Loading