@@ -110,3 +110,64 @@ fn test_set_coldkey_auto_stake_hotkey_same_hotkey_again() {
110110 ) ;
111111 } ) ;
112112}
113+
114+ #[ test]
115+ fn test_set_coldkey_auto_stake_hotkey_change_hotkey ( ) {
116+ new_test_ext ( 1 ) . execute_with ( || {
117+ let subnet_owner_ck = U256 :: from ( 0 ) ;
118+ let subnet_owner_hk = U256 :: from ( 1 ) ;
119+
120+ let coldkey = U256 :: from ( 10 ) ;
121+ let hotkey = U256 :: from ( 11 ) ;
122+ let new_hotkey = U256 :: from ( 12 ) ;
123+
124+ Owner :: < Test > :: insert ( hotkey, coldkey) ;
125+ OwnedHotkeys :: < Test > :: insert ( coldkey, vec ! [ hotkey] ) ;
126+
127+ let netuid = add_dynamic_network ( & subnet_owner_hk, & subnet_owner_ck) ;
128+ Uids :: < Test > :: insert ( netuid, hotkey, 1 ) ;
129+ Uids :: < Test > :: insert ( netuid, new_hotkey, 2 ) ;
130+
131+ // First call should succeed
132+ assert_ok ! ( SubtensorModule :: set_coldkey_auto_stake_hotkey(
133+ RuntimeOrigin :: signed( coldkey) ,
134+ netuid,
135+ hotkey,
136+ ) ) ;
137+
138+ // Check maps
139+ assert_eq ! (
140+ AutoStakeDestination :: <Test >:: get( coldkey, netuid) ,
141+ Some ( hotkey)
142+ ) ;
143+ assert_eq ! (
144+ AutoStakeDestinationColdkeys :: <Test >:: get( hotkey, netuid) ,
145+ vec![ coldkey]
146+ ) ;
147+ assert_eq ! (
148+ AutoStakeDestinationColdkeys :: <Test >:: get( new_hotkey, netuid) ,
149+ vec![ ]
150+ ) ;
151+
152+ // Second call with new hotkey should succeed
153+ assert_ok ! ( SubtensorModule :: set_coldkey_auto_stake_hotkey(
154+ RuntimeOrigin :: signed( coldkey) ,
155+ netuid,
156+ new_hotkey,
157+ ) ) ;
158+
159+ // Check maps again
160+ assert_eq ! (
161+ AutoStakeDestination :: <Test >:: get( coldkey, netuid) ,
162+ Some ( new_hotkey)
163+ ) ;
164+ assert_eq ! (
165+ AutoStakeDestinationColdkeys :: <Test >:: get( hotkey, netuid) ,
166+ vec![ ]
167+ ) ;
168+ assert_eq ! (
169+ AutoStakeDestinationColdkeys :: <Test >:: get( new_hotkey, netuid) ,
170+ vec![ coldkey]
171+ ) ;
172+ } ) ;
173+ }
0 commit comments