@@ -10,7 +10,10 @@ use pallet_subtensor::{
1010 TargetRegistrationsPerInterval , Tempo , WeightsVersionKeyRateLimit , * ,
1111} ;
1212// use pallet_subtensor::{migrations, Event};
13- use pallet_subtensor:: { Event , utils:: rate_limiting:: TransactionType } ;
13+ use pallet_subtensor:: {
14+ Event , subnets:: mechanism:: MAX_MECHANISM_COUNT_PER_SUBNET ,
15+ utils:: rate_limiting:: TransactionType ,
16+ } ;
1417use sp_consensus_grandpa:: AuthorityId as GrandpaId ;
1518use sp_core:: { Get , Pair , U256 , ed25519} ;
1619use substrate_fixed:: types:: I96F32 ;
@@ -540,10 +543,10 @@ fn test_sudo_set_max_allowed_uids() {
540543 Error :: <Test >:: MaxAllowedUidsGreaterThanDefaultMaxAllowedUids
541544 ) ;
542545
543- // Chain bloat check against mechanism count
544- // Set MechanismCountCurrent to exceed 256 / DefaultMaxAllowedUids (16)
546+ // Trying to set max allowed uids that would cause max_allowed_uids * mechanism_count > 256
547+ MaxAllowedUids :: < Test > :: insert ( netuid , 8 ) ;
545548 MechanismCountCurrent :: < Test > :: insert ( netuid, MechId :: from ( 32 ) ) ;
546- let large_max_uids = 16_u16 ;
549+ let large_max_uids = 16 ;
547550 assert_noop ! (
548551 AdminUtils :: sudo_set_max_allowed_uids(
549552 <<Test as Config >:: RuntimeOrigin >:: root( ) ,
@@ -2888,3 +2891,32 @@ fn test_sudo_set_min_allowed_uids() {
28882891 ) ;
28892892 } ) ;
28902893}
2894+
2895+ #[ test]
2896+ fn test_sudo_set_max_mechanism_count ( ) {
2897+ new_test_ext ( ) . execute_with ( || {
2898+ // Normal case
2899+ assert_ok ! ( AdminUtils :: sudo_set_max_mechanism_count(
2900+ <<Test as Config >:: RuntimeOrigin >:: root( ) ,
2901+ MechId :: from( 10 )
2902+ ) ) ;
2903+
2904+ // Zero fails
2905+ assert_noop ! (
2906+ AdminUtils :: sudo_set_max_mechanism_count(
2907+ <<Test as Config >:: RuntimeOrigin >:: root( ) ,
2908+ MechId :: from( 0 )
2909+ ) ,
2910+ pallet_subtensor:: Error :: <Test >:: InvalidValue
2911+ ) ;
2912+
2913+ // Over max bound fails
2914+ assert_noop ! (
2915+ AdminUtils :: sudo_set_max_mechanism_count(
2916+ <<Test as Config >:: RuntimeOrigin >:: root( ) ,
2917+ MechId :: from( MAX_MECHANISM_COUNT_PER_SUBNET + 1 )
2918+ ) ,
2919+ pallet_subtensor:: Error :: <Test >:: InvalidValue
2920+ ) ;
2921+ } ) ;
2922+ }
0 commit comments