@@ -513,69 +513,107 @@ fn test_sudo_set_min_allowed_weights() {
513513fn test_sudo_set_max_allowed_uids ( ) {
514514 new_test_ext ( ) . execute_with ( || {
515515 let netuid = NetUid :: from ( 1 ) ;
516- let to_be_set: u16 = 10 ;
516+ let to_be_set: u16 = 12 ;
517517 add_network ( netuid, 10 ) ;
518- let init_value: u16 = SubtensorModule :: get_max_allowed_uids ( netuid) ;
519- assert_eq ! (
518+ MaxRegistrationsPerBlock :: < Test > :: insert ( netuid, 256 ) ;
519+ TargetRegistrationsPerInterval :: < Test > :: insert ( netuid, 256 ) ;
520+
521+ // Register some neurons
522+ for i in 0 ..=8 {
523+ register_ok_neuron ( netuid, U256 :: from ( i * 1000 ) , U256 :: from ( i * 1000 + i) , 0 ) ;
524+ }
525+
526+ // Bad origin that is not root or subnet owner
527+ assert_noop ! (
520528 AdminUtils :: sudo_set_max_allowed_uids(
521- <<Test as Config >:: RuntimeOrigin >:: signed( U256 :: from( 0 ) ) ,
529+ <<Test as Config >:: RuntimeOrigin >:: signed( U256 :: from( 42 ) ) ,
522530 netuid,
523531 to_be_set
524532 ) ,
525- Err ( DispatchError :: BadOrigin )
533+ DispatchError :: BadOrigin
526534 ) ;
527- assert_eq ! (
535+
536+ // Random netuid that doesn't exist
537+ assert_noop ! (
528538 AdminUtils :: sudo_set_max_allowed_uids(
529539 <<Test as Config >:: RuntimeOrigin >:: root( ) ,
530- netuid . next ( ) ,
540+ NetUid :: from ( 42 ) ,
531541 to_be_set
532542 ) ,
533- Err ( Error :: <Test >:: SubnetDoesNotExist . into ( ) )
543+ Error :: <Test >:: SubnetDoesNotExist
534544 ) ;
535- assert_eq ! ( SubtensorModule :: get_max_allowed_uids( netuid) , init_value) ;
536- assert_ok ! ( AdminUtils :: sudo_set_max_allowed_uids(
537- <<Test as Config >:: RuntimeOrigin >:: root( ) ,
538- netuid,
539- to_be_set
540- ) ) ;
541- assert_eq ! ( SubtensorModule :: get_max_allowed_uids( netuid) , to_be_set) ;
542- } ) ;
543- }
544545
545- #[ test]
546- fn test_sudo_set_and_decrease_max_allowed_uids ( ) {
547- new_test_ext ( ) . execute_with ( || {
548- let netuid = NetUid :: from ( 1 ) ;
549- let to_be_set: u16 = 10 ;
550- add_network ( netuid, 10 ) ;
551- let init_value: u16 = SubtensorModule :: get_max_allowed_uids ( netuid) ;
552- assert_eq ! (
546+ // Trying to set max allowed uids less than min allowed uids
547+ assert_noop ! (
553548 AdminUtils :: sudo_set_max_allowed_uids(
554- <<Test as Config >:: RuntimeOrigin >:: signed ( U256 :: from ( 0 ) ) ,
549+ <<Test as Config >:: RuntimeOrigin >:: root ( ) ,
555550 netuid,
556- to_be_set
551+ SubtensorModule :: get_min_allowed_uids ( netuid ) - 1
557552 ) ,
558- Err ( DispatchError :: BadOrigin )
553+ Error :: < Test > :: MaxAllowedUidsLessThanMinAllowedUids
559554 ) ;
560- assert_eq ! (
555+
556+ // Trying to set max allowed uids less than current uids
557+ assert_noop ! (
561558 AdminUtils :: sudo_set_max_allowed_uids(
562559 <<Test as Config >:: RuntimeOrigin >:: root( ) ,
563- netuid. next ( ) ,
564- to_be_set
560+ netuid,
561+ SubtensorModule :: get_subnetwork_n ( netuid ) - 1
565562 ) ,
566- Err ( Error :: <Test >:: SubnetDoesNotExist . into ( ) )
563+ Error :: <Test >:: MaxAllowedUIdsLessThanCurrentUIds
567564 ) ;
568- assert_eq ! ( SubtensorModule :: get_max_allowed_uids( netuid) , init_value) ;
565+
566+ // Trying to set max allowed uids greater than default max allowed uids
567+ assert_noop ! (
568+ AdminUtils :: sudo_set_max_allowed_uids(
569+ <<Test as Config >:: RuntimeOrigin >:: root( ) ,
570+ netuid,
571+ DefaultMaxAllowedUids :: <Test >:: get( ) + 1
572+ ) ,
573+ Error :: <Test >:: MaxAllowedUidsGreaterThanDefaultMaxAllowedUids
574+ ) ;
575+
576+ // Normal case
569577 assert_ok ! ( AdminUtils :: sudo_set_max_allowed_uids(
570578 <<Test as Config >:: RuntimeOrigin >:: root( ) ,
571579 netuid,
572580 to_be_set
573581 ) ) ;
582+ assert_eq ! ( SubtensorModule :: get_max_allowed_uids( netuid) , to_be_set) ;
583+
584+ // Exact current case
585+ assert_ok ! ( AdminUtils :: sudo_set_max_allowed_uids(
586+ <<Test as Config >:: RuntimeOrigin >:: root( ) ,
587+ netuid,
588+ SubtensorModule :: get_subnetwork_n( netuid)
589+ ) ) ;
590+ assert_eq ! (
591+ SubtensorModule :: get_max_allowed_uids( netuid) ,
592+ SubtensorModule :: get_subnetwork_n( netuid)
593+ ) ;
594+
595+ // Lower bound case
596+ SubtensorModule :: set_min_allowed_uids ( netuid, SubtensorModule :: get_subnetwork_n ( netuid) ) ;
574597 assert_ok ! ( AdminUtils :: sudo_set_max_allowed_uids(
575598 <<Test as Config >:: RuntimeOrigin >:: root( ) ,
576599 netuid,
577- to_be_set - 1
600+ SubtensorModule :: get_min_allowed_uids ( netuid )
578601 ) ) ;
602+ assert_eq ! (
603+ SubtensorModule :: get_max_allowed_uids( netuid) ,
604+ SubtensorModule :: get_min_allowed_uids( netuid)
605+ ) ;
606+
607+ // Upper bound case
608+ assert_ok ! ( AdminUtils :: sudo_set_max_allowed_uids(
609+ <<Test as Config >:: RuntimeOrigin >:: root( ) ,
610+ netuid,
611+ DefaultMaxAllowedUids :: <Test >:: get( ) ,
612+ ) ) ;
613+ assert_eq ! (
614+ SubtensorModule :: get_max_allowed_uids( netuid) ,
615+ DefaultMaxAllowedUids :: <Test >:: get( )
616+ ) ;
579617 } ) ;
580618}
581619
0 commit comments