4
4
use super :: mock:: * ;
5
5
use approx:: assert_abs_diff_eq;
6
6
use frame_support:: { assert_err, assert_noop, assert_ok} ;
7
- use substrate_fixed:: types:: I96F32 ;
7
+ use substrate_fixed:: types:: { I64F64 , I96F32 } ;
8
8
9
9
use crate :: { utils:: rate_limiting:: TransactionType , * } ;
10
10
use sp_core:: U256 ;
@@ -2852,13 +2852,23 @@ fn test_set_weights_no_parent() {
2852
2852
let values: Vec < u16 > = vec ! [ u16 :: MAX ] ; // Use maximum value for u16
2853
2853
let version_key = SubtensorModule :: get_weights_version_key ( netuid) ;
2854
2854
2855
- // Set the min stake very high
2856
- SubtensorModule :: set_stake_threshold ( stake_to_give_child * 5 ) ;
2855
+ // Check the stake weight
2856
+ let curr_stake_weight =
2857
+ SubtensorModule :: get_stake_weights_for_hotkey_on_subnet ( & hotkey, netuid) . 0 ;
2858
+
2859
+ // Set the min stake very high, above the stake weight of the key
2860
+ SubtensorModule :: set_stake_threshold (
2861
+ curr_stake_weight
2862
+ . saturating_mul ( I64F64 :: saturating_from_num ( 5 ) )
2863
+ . saturating_to_num :: < u64 > ( ) ,
2864
+ ) ;
2857
2865
2858
- // Check the key has less stake than required
2866
+ let curr_stake_threshold = SubtensorModule :: get_stake_threshold ( ) ;
2859
2867
assert ! (
2860
- SubtensorModule :: get_stake_for_hotkey_on_subnet( & hotkey, netuid)
2861
- < SubtensorModule :: get_stake_threshold( )
2868
+ curr_stake_weight < curr_stake_threshold,
2869
+ "{:?} is not less than {:?} " ,
2870
+ curr_stake_weight,
2871
+ curr_stake_threshold
2862
2872
) ;
2863
2873
2864
2874
// Check the hotkey cannot set weights
@@ -2876,12 +2886,21 @@ fn test_set_weights_no_parent() {
2876
2886
assert ! ( !SubtensorModule :: check_weights_min_stake( & hotkey, netuid) ) ;
2877
2887
2878
2888
// Set a minimum stake to set weights
2879
- SubtensorModule :: set_stake_threshold ( stake_to_give_child - 5 ) ;
2889
+ SubtensorModule :: set_stake_threshold (
2890
+ curr_stake_weight
2891
+ . saturating_sub ( I64F64 :: saturating_from_num ( 5 ) )
2892
+ . saturating_to_num :: < u64 > ( ) ,
2893
+ ) ;
2880
2894
2881
2895
// Check if the stake for the hotkey is above
2896
+ let new_stake_weight =
2897
+ SubtensorModule :: get_stake_weights_for_hotkey_on_subnet ( & hotkey, netuid) . 0 ;
2898
+ let new_stake_threshold = SubtensorModule :: get_stake_threshold ( ) ;
2882
2899
assert ! (
2883
- SubtensorModule :: get_stake_for_hotkey_on_subnet( & hotkey, netuid)
2884
- >= SubtensorModule :: get_stake_threshold( )
2900
+ new_stake_weight >= new_stake_threshold,
2901
+ "{:?} is not greater than or equal to {:?} " ,
2902
+ new_stake_weight,
2903
+ new_stake_threshold
2885
2904
) ;
2886
2905
2887
2906
// Check the hotkey can set weights
0 commit comments