@@ -68,6 +68,7 @@ fn test_replace_neuron() {
68
68
Dividends :: < Test > :: mutate ( netuid, |v| {
69
69
SubtensorModule :: set_element_at ( v, neuron_uid as usize , 5u16 )
70
70
} ) ;
71
+ Bonds :: < Test > :: insert ( netuid, neuron_uid, vec ! [ ( 0 , 1 ) ] ) ;
71
72
72
73
// serve axon mock address
73
74
let ip: u128 = 1676056785 ;
@@ -138,6 +139,76 @@ fn test_replace_neuron() {
138
139
assert_eq ! ( axon_info. ip, 0 ) ;
139
140
assert_eq ! ( axon_info. port, 0 ) ;
140
141
assert_eq ! ( axon_info. ip_type, 0 ) ;
142
+
143
+ // Check bonds are cleared.
144
+ assert_eq ! ( Bonds :: <Test >:: get( netuid, neuron_uid) , vec![ ] ) ;
145
+ } ) ;
146
+ }
147
+
148
+ #[ test]
149
+ fn test_bonds_cleared_on_replace ( ) {
150
+ new_test_ext ( 1 ) . execute_with ( || {
151
+ let block_number: u64 = 0 ;
152
+ let netuid: u16 = 1 ;
153
+ let tempo: u16 = 13 ;
154
+ let hotkey_account_id = U256 :: from ( 1 ) ;
155
+ let ( nonce, work) : ( u64 , Vec < u8 > ) = SubtensorModule :: create_work_for_block_number (
156
+ netuid,
157
+ block_number,
158
+ 111111 ,
159
+ & hotkey_account_id,
160
+ ) ;
161
+ let coldkey_account_id = U256 :: from ( 1234 ) ;
162
+
163
+ let new_hotkey_account_id = U256 :: from ( 2 ) ;
164
+ let _new_colkey_account_id = U256 :: from ( 12345 ) ;
165
+
166
+ //add network
167
+ add_network ( netuid, tempo, 0 ) ;
168
+
169
+ // Register a neuron.
170
+ assert_ok ! ( SubtensorModule :: register(
171
+ <<Test as Config >:: RuntimeOrigin >:: signed( hotkey_account_id) ,
172
+ netuid,
173
+ block_number,
174
+ nonce,
175
+ work,
176
+ hotkey_account_id,
177
+ coldkey_account_id
178
+ ) ) ;
179
+
180
+ // Get UID
181
+ let neuron_uid = SubtensorModule :: get_uid_for_net_and_hotkey ( netuid, & hotkey_account_id) ;
182
+ assert_ok ! ( neuron_uid) ;
183
+ let neuron_uid = neuron_uid. unwrap ( ) ;
184
+
185
+ // set non-default bonds
186
+ Bonds :: < Test > :: insert ( netuid, neuron_uid, vec ! [ ( 0 , 1 ) ] ) ;
187
+
188
+ // Replace the neuron.
189
+ SubtensorModule :: replace_neuron ( netuid, neuron_uid, & new_hotkey_account_id, block_number) ;
190
+
191
+ // Check old hotkey is not registered on any network.
192
+ assert ! ( SubtensorModule :: get_uid_for_net_and_hotkey( netuid, & hotkey_account_id) . is_err( ) ) ;
193
+ assert ! ( !SubtensorModule :: is_hotkey_registered_on_any_network(
194
+ & hotkey_account_id
195
+ ) ) ;
196
+
197
+ let curr_hotkey = SubtensorModule :: get_hotkey_for_net_and_uid ( netuid, neuron_uid) ;
198
+ assert_ok ! ( curr_hotkey) ;
199
+ assert_ne ! ( curr_hotkey. unwrap( ) , hotkey_account_id) ;
200
+
201
+ // Check new hotkey is registered on the network.
202
+ assert ! (
203
+ SubtensorModule :: get_uid_for_net_and_hotkey( netuid, & new_hotkey_account_id) . is_ok( )
204
+ ) ;
205
+ assert ! ( SubtensorModule :: is_hotkey_registered_on_any_network(
206
+ & new_hotkey_account_id
207
+ ) ) ;
208
+ assert_eq ! ( curr_hotkey. unwrap( ) , new_hotkey_account_id) ;
209
+
210
+ // Check bonds are cleared.
211
+ assert_eq ! ( Bonds :: <Test >:: get( netuid, neuron_uid) , vec![ ] ) ;
141
212
} ) ;
142
213
}
143
214
0 commit comments