@@ -2269,3 +2269,64 @@ fn test_sudo_set_subsubnet_count() {
22692269 ) ) ;
22702270 } ) ;
22712271}
2272+
2273+ // cargo test --package pallet-admin-utils --lib -- tests::test_sudo_set_subsubnet_count_and_emissions --exact --show-output
2274+ #[ test]
2275+ fn test_sudo_set_subsubnet_count_and_emissions ( ) {
2276+ new_test_ext ( ) . execute_with ( || {
2277+ let netuid = NetUid :: from ( 1 ) ;
2278+ let ss_count_ok = SubId :: from ( 2 ) ;
2279+
2280+ let sn_owner = U256 :: from ( 1324 ) ;
2281+ add_network ( netuid, 10 ) ;
2282+ // Set the Subnet Owner
2283+ SubnetOwner :: < Test > :: insert ( netuid, sn_owner) ;
2284+
2285+ assert_ok ! ( AdminUtils :: sudo_set_subsubnet_count(
2286+ <<Test as Config >:: RuntimeOrigin >:: signed( sn_owner) ,
2287+ netuid,
2288+ ss_count_ok
2289+ ) ) ;
2290+
2291+ // Cannot set emission split with wrong number of entries
2292+ // With two subsubnets the size of the split vector should be 2, not 3
2293+ assert_noop ! (
2294+ AdminUtils :: sudo_set_subsubnet_emission_split(
2295+ <<Test as Config >:: RuntimeOrigin >:: signed( sn_owner) ,
2296+ netuid,
2297+ Some ( vec![ 0xFFFF / 5 * 2 , 0xFFFF / 5 * 2 , 0xFFFF / 5 ] )
2298+ ) ,
2299+ pallet_subtensor:: Error :: <Test >:: InvalidValue
2300+ ) ;
2301+
2302+ // Cannot set emission split with wrong total of entries
2303+ // Split vector entries should sum up to exactly 0xFFFF
2304+ assert_noop ! (
2305+ AdminUtils :: sudo_set_subsubnet_emission_split(
2306+ <<Test as Config >:: RuntimeOrigin >:: signed( sn_owner) ,
2307+ netuid,
2308+ Some ( vec![ 0xFFFF / 5 * 4 , 0xFFFF / 5 - 1 ] )
2309+ ) ,
2310+ pallet_subtensor:: Error :: <Test >:: InvalidValue
2311+ ) ;
2312+
2313+ // Can set good split ok
2314+ // We also verify here that it can happen in the same block as setting subsubnet counts
2315+ // or soon, without rate limiting
2316+ assert_ok ! ( AdminUtils :: sudo_set_subsubnet_emission_split(
2317+ <<Test as Config >:: RuntimeOrigin >:: signed( sn_owner) ,
2318+ netuid,
2319+ Some ( vec![ 0xFFFF / 5 , 0xFFFF / 5 * 4 ] )
2320+ ) ) ;
2321+
2322+ // Cannot set it again due to rate limits
2323+ assert_noop ! (
2324+ AdminUtils :: sudo_set_subsubnet_emission_split(
2325+ <<Test as Config >:: RuntimeOrigin >:: signed( sn_owner) ,
2326+ netuid,
2327+ Some ( vec![ 0xFFFF / 5 * 4 , 0xFFFF / 5 ] )
2328+ ) ,
2329+ pallet_subtensor:: Error :: <Test >:: TxRateLimitExceeded
2330+ ) ;
2331+ } ) ;
2332+ }
0 commit comments