@@ -2498,6 +2498,28 @@ fn test_trim_to_max_allowed_uids() {
24982498 Keys :: < Test > :: insert ( netuid, 14 , sn_owner_hotkey2) ;
24992499 Uids :: < Test > :: insert ( netuid, sn_owner_hotkey2, 14 ) ;
25002500
2501+ // Set some evm addresses
2502+ AssociatedEvmAddress :: < Test > :: insert (
2503+ netuid,
2504+ 6 ,
2505+ ( sp_core:: H160 :: from_slice ( b"12345678901234567891" ) , now) ,
2506+ ) ;
2507+ AssociatedEvmAddress :: < Test > :: insert (
2508+ netuid,
2509+ 10 ,
2510+ ( sp_core:: H160 :: from_slice ( b"12345678901234567892" ) , now) ,
2511+ ) ;
2512+ AssociatedEvmAddress :: < Test > :: insert (
2513+ netuid,
2514+ 12 ,
2515+ ( sp_core:: H160 :: from_slice ( b"12345678901234567893" ) , now) ,
2516+ ) ;
2517+ AssociatedEvmAddress :: < Test > :: insert (
2518+ netuid,
2519+ 14 ,
2520+ ( sp_core:: H160 :: from_slice ( b"12345678901234567894" ) , now) ,
2521+ ) ;
2522+
25012523 // Populate Weights and Bonds storage items to test trimming
25022524 // Create weights and bonds that span across the range that will be trimmed
25032525 for uid in 0 ..max_n {
@@ -2574,6 +2596,7 @@ fn test_trim_to_max_allowed_uids() {
25742596 for uid in new_max_n..max_n {
25752597 assert ! ( !Keys :: <Test >:: contains_key( netuid, uid) ) ;
25762598 assert ! ( !BlockAtRegistration :: <Test >:: contains_key( netuid, uid) ) ;
2599+ assert ! ( !AssociatedEvmAddress :: <Test >:: contains_key( netuid, uid) ) ;
25772600 for mecid in 0 ..mechanism_count. into ( ) {
25782601 let netuid_index =
25792602 SubtensorModule :: get_mechanism_storage_index ( netuid, MechId :: from ( mecid) ) ;
@@ -2631,6 +2654,23 @@ fn test_trim_to_max_allowed_uids() {
26312654 // Actual number of neurons on the network updated after trimming
26322655 assert_eq ! ( SubnetworkN :: <Test >:: get( netuid) , new_max_n) ;
26332656
2657+ // Uids match enumeration order
2658+ for i in 0 ..new_max_n. into ( ) {
2659+ let hotkey = Keys :: < Test > :: get ( netuid, i) ;
2660+ let uid = Uids :: < Test > :: get ( netuid, hotkey) ;
2661+ assert_eq ! ( uid, Some ( i) ) ;
2662+ }
2663+
2664+ // EVM association have been remapped correctly (uids: 7 -> 2, 14 -> 7)
2665+ assert_eq ! (
2666+ AssociatedEvmAddress :: <Test >:: get( netuid, 2 ) ,
2667+ Some ( ( sp_core:: H160 :: from_slice( b"12345678901234567891" ) , now) )
2668+ ) ;
2669+ assert_eq ! (
2670+ AssociatedEvmAddress :: <Test >:: get( netuid, 7 ) ,
2671+ Some ( ( sp_core:: H160 :: from_slice( b"12345678901234567894" ) , now) )
2672+ ) ;
2673+
26342674 // Non existent subnet
26352675 assert_err ! (
26362676 AdminUtils :: sudo_trim_to_max_allowed_uids(
@@ -2673,7 +2713,7 @@ fn test_trim_to_max_allowed_uids_too_many_immune() {
26732713 MaxRegistrationsPerBlock :: < Test > :: insert ( netuid, 256 ) ;
26742714 TargetRegistrationsPerInterval :: < Test > :: insert ( netuid, 256 ) ;
26752715 ImmuneOwnerUidsLimit :: < Test > :: insert ( netuid, 2 ) ;
2676- MinAllowedUids :: < Test > :: set ( netuid, 4 ) ;
2716+ MinAllowedUids :: < Test > :: set ( netuid, 2 ) ;
26772717
26782718 // Add 5 neurons
26792719 let max_n = 5 ;
@@ -2711,7 +2751,7 @@ fn test_trim_to_max_allowed_uids_too_many_immune() {
27112751 netuid,
27122752 4
27132753 ) ,
2714- pallet_subtensor:: Error :: <Test >:: InvalidValue
2754+ pallet_subtensor:: Error :: <Test >:: TrimmingWouldExceedMaxImmunePercentage
27152755 ) ;
27162756
27172757 // Try to trim to 3 UIDs - this should also fail because 4/3 > 80% immune (>= 80%)
@@ -2721,7 +2761,7 @@ fn test_trim_to_max_allowed_uids_too_many_immune() {
27212761 netuid,
27222762 3
27232763 ) ,
2724- pallet_subtensor:: Error :: <Test >:: InvalidValue
2764+ pallet_subtensor:: Error :: <Test >:: TrimmingWouldExceedMaxImmunePercentage
27252765 ) ;
27262766
27272767 // Now test a scenario where trimming should succeed
@@ -2733,10 +2773,6 @@ fn test_trim_to_max_allowed_uids_too_many_immune() {
27332773 Uids :: < Test > :: remove ( netuid, hotkey_to_remove) ;
27342774 BlockAtRegistration :: < Test > :: remove ( netuid, uid_to_remove) ;
27352775
2736- // Now we have 3 immune out of 4 total UIDs
2737- // Try to trim to 3 UIDs - this should succeed because 3/3 = 100% immune, but that's exactly 80%
2738- // Wait, 100% is > 80%, so this should fail. Let me test with a scenario where we have fewer immune UIDs
2739-
27402776 // Remove another immune UID to make it 2 immune out of 3 total
27412777 let uid_to_remove2 = 2 ;
27422778 let hotkey_to_remove2 = U256 :: from ( uid_to_remove2 * 1000 + 1000 ) ;
0 commit comments