@@ -2288,6 +2288,9 @@ fn test_trim_to_max_allowed_uids() {
22882288 ImmuneOwnerUidsLimit :: < Test > :: insert ( netuid, 2 ) ;
22892289 // We set a low value here to make testing easier
22902290 MinAllowedUids :: < Test > :: set ( netuid, 4 ) ;
2291+ // We define 4 subsubnets
2292+ let subsubnet_count = SubId :: from ( 4 ) ;
2293+ SubsubnetCountCurrent :: < Test > :: insert ( netuid, subsubnet_count) ;
22912294
22922295 // Add some neurons
22932296 let max_n = 16 ;
@@ -2322,15 +2325,20 @@ fn test_trim_to_max_allowed_uids() {
23222325 Rank :: < Test > :: insert ( netuid, values. clone ( ) ) ;
23232326 Trust :: < Test > :: insert ( netuid, values. clone ( ) ) ;
23242327 Consensus :: < Test > :: insert ( netuid, values. clone ( ) ) ;
2325- Incentive :: < Test > :: insert ( netuid, values. clone ( ) ) ;
23262328 Dividends :: < Test > :: insert ( netuid, values. clone ( ) ) ;
2327- LastUpdate :: < Test > :: insert ( netuid, u64_values) ;
23282329 PruningScores :: < Test > :: insert ( netuid, values. clone ( ) ) ;
23292330 ValidatorTrust :: < Test > :: insert ( netuid, values. clone ( ) ) ;
2330- StakeWeight :: < Test > :: insert ( netuid, values) ;
2331+ StakeWeight :: < Test > :: insert ( netuid, values. clone ( ) ) ;
23312332 ValidatorPermit :: < Test > :: insert ( netuid, bool_values. clone ( ) ) ;
23322333 Active :: < Test > :: insert ( netuid, bool_values) ;
23332334
2335+ for subid in 0 ..subsubnet_count. into ( ) {
2336+ let netuid_index =
2337+ SubtensorModule :: get_subsubnet_storage_index ( netuid, SubId :: from ( subid) ) ;
2338+ Incentive :: < Test > :: insert ( netuid_index, values. clone ( ) ) ;
2339+ LastUpdate :: < Test > :: insert ( netuid_index, u64_values. clone ( ) ) ;
2340+ }
2341+
23342342 // We set some owner immune uids
23352343 let now = frame_system:: Pallet :: < Test > :: block_number ( ) ;
23362344 BlockAtRegistration :: < Test > :: set ( netuid, 6 , now) ;
@@ -2359,8 +2367,12 @@ fn test_trim_to_max_allowed_uids() {
23592367 }
23602368 }
23612369
2362- Weights :: < Test > :: insert ( netuid, uid, weights) ;
2363- Bonds :: < Test > :: insert ( netuid, uid, bonds) ;
2370+ for subid in 0 ..subsubnet_count. into ( ) {
2371+ let netuid_index =
2372+ SubtensorModule :: get_subsubnet_storage_index ( netuid, SubId :: from ( subid) ) ;
2373+ Weights :: < Test > :: insert ( netuid_index, uid, weights. clone ( ) ) ;
2374+ Bonds :: < Test > :: insert ( netuid_index, uid, bonds. clone ( ) ) ;
2375+ }
23642376 }
23652377
23662378 // Normal case
@@ -2397,20 +2409,29 @@ fn test_trim_to_max_allowed_uids() {
23972409 assert_eq ! ( Trust :: <Test >:: get( netuid) , expected_values) ;
23982410 assert_eq ! ( Active :: <Test >:: get( netuid) , expected_bools) ;
23992411 assert_eq ! ( Consensus :: <Test >:: get( netuid) , expected_values) ;
2400- assert_eq ! ( Incentive :: <Test >:: get( netuid) , expected_values) ;
24012412 assert_eq ! ( Dividends :: <Test >:: get( netuid) , expected_values) ;
2402- assert_eq ! ( LastUpdate :: <Test >:: get( netuid) , expected_u64_values) ;
24032413 assert_eq ! ( PruningScores :: <Test >:: get( netuid) , expected_values) ;
24042414 assert_eq ! ( ValidatorTrust :: <Test >:: get( netuid) , expected_values) ;
24052415 assert_eq ! ( ValidatorPermit :: <Test >:: get( netuid) , expected_bools) ;
24062416 assert_eq ! ( StakeWeight :: <Test >:: get( netuid) , expected_values) ;
24072417
2418+ for subid in 0 ..subsubnet_count. into ( ) {
2419+ let netuid_index =
2420+ SubtensorModule :: get_subsubnet_storage_index ( netuid, SubId :: from ( subid) ) ;
2421+ assert_eq ! ( Incentive :: <Test >:: get( netuid_index) , expected_values) ;
2422+ assert_eq ! ( LastUpdate :: <Test >:: get( netuid_index) , expected_u64_values) ;
2423+ }
2424+
24082425 // Ensure trimmed uids related storage has been cleared
24092426 for uid in new_max_n..max_n {
24102427 assert ! ( !Keys :: <Test >:: contains_key( netuid, uid) ) ;
24112428 assert ! ( !BlockAtRegistration :: <Test >:: contains_key( netuid, uid) ) ;
2412- assert ! ( !Weights :: <Test >:: contains_key( netuid, uid) ) ;
2413- assert ! ( !Bonds :: <Test >:: contains_key( netuid, uid) ) ;
2429+ for subid in 0 ..subsubnet_count. into ( ) {
2430+ let netuid_index =
2431+ SubtensorModule :: get_subsubnet_storage_index ( netuid, SubId :: from ( subid) ) ;
2432+ assert ! ( !Weights :: <Test >:: contains_key( netuid_index, uid) ) ;
2433+ assert ! ( !Bonds :: <Test >:: contains_key( netuid_index, uid) ) ;
2434+ }
24142435 }
24152436
24162437 // Ensure trimmed uids hotkey related storage has been cleared
@@ -2439,26 +2460,24 @@ fn test_trim_to_max_allowed_uids() {
24392460 assert ! ( !Prometheus :: <Test >:: contains_key( netuid, hotkey) ) ;
24402461 }
24412462
2442- // Ensure trimmed uids weights and bonds have been cleared
2443- for uid in new_max_n..max_n {
2444- assert ! ( !Weights :: <Test >:: contains_key( netuid, uid) ) ;
2445- assert ! ( !Bonds :: <Test >:: contains_key( netuid, uid) ) ;
2446- }
2447-
24482463 // Ensure trimmed uids weights and bonds connections have been trimmed correctly
24492464 for uid in 0 ..new_max_n {
2450- assert ! (
2451- Weights :: <Test >:: get( netuid, uid)
2452- . iter( )
2453- . all( |( target_uid, _) | * target_uid < new_max_n) ,
2454- "Found a weight with target_uid >= new_max_n"
2455- ) ;
2456- assert ! (
2457- Bonds :: <Test >:: get( netuid, uid)
2458- . iter( )
2459- . all( |( target_uid, _) | * target_uid < new_max_n) ,
2460- "Found a bond with target_uid >= new_max_n"
2461- ) ;
2465+ for subid in 0 ..subsubnet_count. into ( ) {
2466+ let netuid_index =
2467+ SubtensorModule :: get_subsubnet_storage_index ( netuid, SubId :: from ( subid) ) ;
2468+ assert ! (
2469+ Weights :: <Test >:: get( netuid_index, uid)
2470+ . iter( )
2471+ . all( |( target_uid, _) | * target_uid < new_max_n) ,
2472+ "Found a weight with target_uid >= new_max_n"
2473+ ) ;
2474+ assert ! (
2475+ Bonds :: <Test >:: get( netuid_index, uid)
2476+ . iter( )
2477+ . all( |( target_uid, _) | * target_uid < new_max_n) ,
2478+ "Found a bond with target_uid >= new_max_n"
2479+ ) ;
2480+ }
24622481 }
24632482
24642483 // Actual number of neurons on the network updated after trimming
0 commit comments