Skip to content
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
37 changes: 28 additions & 9 deletions pallets/subtensor/src/tests/children.rs
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@
use super::mock::*;
use approx::assert_abs_diff_eq;
use frame_support::{assert_err, assert_noop, assert_ok};
use substrate_fixed::types::I96F32;
use substrate_fixed::types::{I64F64, I96F32};

use crate::{utils::rate_limiting::TransactionType, *};
use sp_core::U256;
Expand Down Expand Up @@ -2852,13 +2852,23 @@ fn test_set_weights_no_parent() {
let values: Vec<u16> = vec![u16::MAX]; // Use maximum value for u16
let version_key = SubtensorModule::get_weights_version_key(netuid);

// Set the min stake very high
SubtensorModule::set_stake_threshold(stake_to_give_child * 5);
// Check the stake weight
let curr_stake_weight =
SubtensorModule::get_stake_weights_for_hotkey_on_subnet(&hotkey, netuid).0;

// Set the min stake very high, above the stake weight of the key
SubtensorModule::set_stake_threshold(
curr_stake_weight
.saturating_mul(I64F64::saturating_from_num(5))
.saturating_to_num::<u64>(),
);

// Check the key has less stake than required
let curr_stake_threshold = SubtensorModule::get_stake_threshold();
assert!(
SubtensorModule::get_stake_for_hotkey_on_subnet(&hotkey, netuid)
< SubtensorModule::get_stake_threshold()
curr_stake_weight < curr_stake_threshold,
"{:?} is not less than {:?} ",
curr_stake_weight,
curr_stake_threshold
);

// Check the hotkey cannot set weights
Expand All @@ -2876,12 +2886,21 @@ fn test_set_weights_no_parent() {
assert!(!SubtensorModule::check_weights_min_stake(&hotkey, netuid));

// Set a minimum stake to set weights
SubtensorModule::set_stake_threshold(stake_to_give_child - 5);
SubtensorModule::set_stake_threshold(
curr_stake_weight
.saturating_sub(I64F64::saturating_from_num(5))
.saturating_to_num::<u64>(),
);

// Check if the stake for the hotkey is above
let new_stake_weight =
SubtensorModule::get_stake_weights_for_hotkey_on_subnet(&hotkey, netuid).0;
let new_stake_threshold = SubtensorModule::get_stake_threshold();
assert!(
SubtensorModule::get_stake_for_hotkey_on_subnet(&hotkey, netuid)
>= SubtensorModule::get_stake_threshold()
new_stake_weight >= new_stake_threshold,
"{:?} is not greater than or equal to {:?} ",
new_stake_weight,
new_stake_threshold
);

// Check the hotkey can set weights
Expand Down
2 changes: 1 addition & 1 deletion pallets/subtensor/src/tests/mock.rs
Original file line number Diff line number Diff line change
Expand Up @@ -133,7 +133,7 @@ parameter_types! {
pub const SDebug:u64 = 1;
pub const InitialRho: u16 = 30;
pub const InitialKappa: u16 = 32_767;
pub const InitialTempo: u16 = 0;
pub const InitialTempo: u16 = 360;
pub const SelfOwnership: u64 = 2;
pub const InitialImmunityPeriod: u16 = 2;
pub const InitialMaxAllowedUids: u16 = 2;
Expand Down
17 changes: 17 additions & 0 deletions pallets/subtensor/src/tests/networks.rs
Original file line number Diff line number Diff line change
Expand Up @@ -326,3 +326,20 @@ fn test_register_subnet_high_lock_cost() {
assert_eq!(SubnetAlphaIn::<Test>::get(netuid), lock_cost);
})
}

#[test]
fn test_tempo_greater_than_weight_set_rate_limit() {
new_test_ext(1).execute_with(|| {
let subnet_owner_hotkey = U256::from(1);
let subnet_owner_coldkey = U256::from(2);

let netuid = add_dynamic_network(&subnet_owner_hotkey, &subnet_owner_coldkey);

// Get tempo
let tempo = SubtensorModule::get_tempo(netuid);

let weights_set_rate_limit = SubtensorModule::get_weights_set_rate_limit(netuid);

assert!(tempo as u64 >= weights_set_rate_limit);
})
}
2 changes: 1 addition & 1 deletion runtime/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -1024,7 +1024,7 @@ impl pallet_commitments::Config for Runtime {
}

#[cfg(not(feature = "fast-blocks"))]
pub const INITIAL_SUBNET_TEMPO: u16 = 99;
pub const INITIAL_SUBNET_TEMPO: u16 = 360;

#[cfg(feature = "fast-blocks")]
pub const INITIAL_SUBNET_TEMPO: u16 = 10;
Expand Down
Loading