@@ -2502,6 +2502,28 @@ fn test_trim_to_max_allowed_uids() {
25022502 Keys :: < Test > :: insert ( netuid, 14 , sn_owner_hotkey2) ;
25032503 Uids :: < Test > :: insert ( netuid, sn_owner_hotkey2, 14 ) ;
25042504
2505+ // Set some evm addresses
2506+ AssociatedEvmAddress :: < Test > :: insert (
2507+ netuid,
2508+ 6 ,
2509+ ( sp_core:: H160 :: from_slice ( b"12345678901234567891" ) , now) ,
2510+ ) ;
2511+ AssociatedEvmAddress :: < Test > :: insert (
2512+ netuid,
2513+ 10 ,
2514+ ( sp_core:: H160 :: from_slice ( b"12345678901234567892" ) , now) ,
2515+ ) ;
2516+ AssociatedEvmAddress :: < Test > :: insert (
2517+ netuid,
2518+ 12 ,
2519+ ( sp_core:: H160 :: from_slice ( b"12345678901234567893" ) , now) ,
2520+ ) ;
2521+ AssociatedEvmAddress :: < Test > :: insert (
2522+ netuid,
2523+ 14 ,
2524+ ( sp_core:: H160 :: from_slice ( b"12345678901234567894" ) , now) ,
2525+ ) ;
2526+
25052527 // Populate Weights and Bonds storage items to test trimming
25062528 // Create weights and bonds that span across the range that will be trimmed
25072529 for uid in 0 ..max_n {
@@ -2578,6 +2600,7 @@ fn test_trim_to_max_allowed_uids() {
25782600 for uid in new_max_n..max_n {
25792601 assert ! ( !Keys :: <Test >:: contains_key( netuid, uid) ) ;
25802602 assert ! ( !BlockAtRegistration :: <Test >:: contains_key( netuid, uid) ) ;
2603+ assert ! ( !AssociatedEvmAddress :: <Test >:: contains_key( netuid, uid) ) ;
25812604 for mecid in 0 ..mechanism_count. into ( ) {
25822605 let netuid_index =
25832606 SubtensorModule :: get_mechanism_storage_index ( netuid, MechId :: from ( mecid) ) ;
@@ -2635,6 +2658,23 @@ fn test_trim_to_max_allowed_uids() {
26352658 // Actual number of neurons on the network updated after trimming
26362659 assert_eq ! ( SubnetworkN :: <Test >:: get( netuid) , new_max_n) ;
26372660
2661+ // Uids match enumeration order
2662+ for i in 0 ..new_max_n. into ( ) {
2663+ let hotkey = Keys :: < Test > :: get ( netuid, i) ;
2664+ let uid = Uids :: < Test > :: get ( netuid, hotkey) ;
2665+ assert_eq ! ( uid, Some ( i) ) ;
2666+ }
2667+
2668+ // EVM association have been remapped correctly (uids: 7 -> 2, 14 -> 7)
2669+ assert_eq ! (
2670+ AssociatedEvmAddress :: <Test >:: get( netuid, 2 ) ,
2671+ Some ( ( sp_core:: H160 :: from_slice( b"12345678901234567891" ) , now) )
2672+ ) ;
2673+ assert_eq ! (
2674+ AssociatedEvmAddress :: <Test >:: get( netuid, 7 ) ,
2675+ Some ( ( sp_core:: H160 :: from_slice( b"12345678901234567894" ) , now) )
2676+ ) ;
2677+
26382678 // Non existent subnet
26392679 assert_err ! (
26402680 AdminUtils :: sudo_trim_to_max_allowed_uids(
@@ -2677,7 +2717,7 @@ fn test_trim_to_max_allowed_uids_too_many_immune() {
26772717 MaxRegistrationsPerBlock :: < Test > :: insert ( netuid, 256 ) ;
26782718 TargetRegistrationsPerInterval :: < Test > :: insert ( netuid, 256 ) ;
26792719 ImmuneOwnerUidsLimit :: < Test > :: insert ( netuid, 2 ) ;
2680- MinAllowedUids :: < Test > :: set ( netuid, 4 ) ;
2720+ MinAllowedUids :: < Test > :: set ( netuid, 2 ) ;
26812721
26822722 // Add 5 neurons
26832723 let max_n = 5 ;
@@ -2715,7 +2755,7 @@ fn test_trim_to_max_allowed_uids_too_many_immune() {
27152755 netuid,
27162756 4
27172757 ) ,
2718- pallet_subtensor:: Error :: <Test >:: InvalidValue
2758+ pallet_subtensor:: Error :: <Test >:: TrimmingWouldExceedMaxImmunePercentage
27192759 ) ;
27202760
27212761 // Try to trim to 3 UIDs - this should also fail because 4/3 > 80% immune (>= 80%)
@@ -2725,7 +2765,7 @@ fn test_trim_to_max_allowed_uids_too_many_immune() {
27252765 netuid,
27262766 3
27272767 ) ,
2728- pallet_subtensor:: Error :: <Test >:: InvalidValue
2768+ pallet_subtensor:: Error :: <Test >:: TrimmingWouldExceedMaxImmunePercentage
27292769 ) ;
27302770
27312771 // Now test a scenario where trimming should succeed
@@ -2737,10 +2777,6 @@ fn test_trim_to_max_allowed_uids_too_many_immune() {
27372777 Uids :: < Test > :: remove ( netuid, hotkey_to_remove) ;
27382778 BlockAtRegistration :: < Test > :: remove ( netuid, uid_to_remove) ;
27392779
2740- // Now we have 3 immune out of 4 total UIDs
2741- // Try to trim to 3 UIDs - this should succeed because 3/3 = 100% immune, but that's exactly 80%
2742- // Wait, 100% is > 80%, so this should fail. Let me test with a scenario where we have fewer immune UIDs
2743-
27442780 // Remove another immune UID to make it 2 immune out of 3 total
27452781 let uid_to_remove2 = 2 ;
27462782 let hotkey_to_remove2 = U256 :: from ( uid_to_remove2 * 1000 + 1000 ) ;
0 commit comments