@@ -52,25 +52,58 @@ fn test_replace_neuron() {
52
52
// Get UID
53
53
let neuron_uid = SubtensorModule :: get_uid_for_net_and_hotkey ( netuid, & hotkey_account_id) ;
54
54
assert_ok ! ( neuron_uid) ;
55
+ let neuron_uid = neuron_uid. unwrap ( ) ;
56
+
57
+ // set non-default values
58
+ Trust :: < Test > :: mutate ( netuid, |v| {
59
+ SubtensorModule :: set_element_at ( v, neuron_uid as usize , 5u16 )
60
+ } ) ;
61
+ Emission :: < Test > :: mutate ( netuid, |v| {
62
+ SubtensorModule :: set_element_at ( v, neuron_uid as usize , 5u64 )
63
+ } ) ;
64
+ Consensus :: < Test > :: mutate ( netuid, |v| {
65
+ SubtensorModule :: set_element_at ( v, neuron_uid as usize , 5u16 )
66
+ } ) ;
67
+ Incentive :: < Test > :: mutate ( netuid, |v| {
68
+ SubtensorModule :: set_element_at ( v, neuron_uid as usize , 5u16 )
69
+ } ) ;
70
+ Dividends :: < Test > :: mutate ( netuid, |v| {
71
+ SubtensorModule :: set_element_at ( v, neuron_uid as usize , 5u16 )
72
+ } ) ;
73
+
74
+ // serve axon mock address
75
+ let ip: u128 = 1676056785 ;
76
+ let port: u16 = 9999 ;
77
+ let ip_type: u8 = 4 ;
78
+ let hotkey = SubtensorModule :: get_hotkey_for_net_and_uid ( netuid, neuron_uid) . unwrap ( ) ;
79
+ assert ! ( SubtensorModule :: serve_axon(
80
+ <<Test as Config >:: RuntimeOrigin >:: signed( hotkey_account_id) ,
81
+ netuid,
82
+ 0 ,
83
+ ip,
84
+ port,
85
+ ip_type,
86
+ 0 ,
87
+ 0 ,
88
+ 0
89
+ )
90
+ . is_ok( ) ) ;
55
91
56
92
// Set a neuron certificate for it
57
93
NeuronCertificates :: < Test > :: insert ( netuid, hotkey_account_id, certificate) ;
58
94
59
95
// Replace the neuron.
60
- SubtensorModule :: replace_neuron (
61
- netuid,
62
- neuron_uid. unwrap ( ) ,
63
- & new_hotkey_account_id,
64
- block_number,
65
- ) ;
96
+ SubtensorModule :: replace_neuron ( netuid, neuron_uid, & new_hotkey_account_id, block_number) ;
97
+
98
+ assert ! ( !SubtensorModule :: has_axon_info( netuid, & hotkey) ) ;
66
99
67
100
// Check old hotkey is not registered on any network.
68
101
assert ! ( SubtensorModule :: get_uid_for_net_and_hotkey( netuid, & hotkey_account_id) . is_err( ) ) ;
69
102
assert ! ( !SubtensorModule :: is_hotkey_registered_on_any_network(
70
103
& hotkey_account_id
71
104
) ) ;
72
105
73
- let curr_hotkey = SubtensorModule :: get_hotkey_for_net_and_uid ( netuid, neuron_uid. unwrap ( ) ) ;
106
+ let curr_hotkey = SubtensorModule :: get_hotkey_for_net_and_uid ( netuid, neuron_uid) ;
74
107
assert_ok ! ( curr_hotkey) ;
75
108
assert_ne ! ( curr_hotkey. unwrap( ) , hotkey_account_id) ;
76
109
@@ -86,6 +119,33 @@ fn test_replace_neuron() {
86
119
// Check neuron certificate was reset
87
120
let certificate = NeuronCertificates :: < Test > :: get ( netuid, hotkey_account_id) ;
88
121
assert_eq ! ( certificate, None ) ;
122
+
123
+ // Check trust, emission, consensus, incentive, dividends have been reset to 0.
124
+ assert_eq ! ( SubtensorModule :: get_trust_for_uid( netuid, neuron_uid) , 0 ) ;
125
+ assert_eq ! ( SubtensorModule :: get_emission_for_uid( netuid, neuron_uid) , 0 ) ;
126
+ assert_eq ! (
127
+ SubtensorModule :: get_consensus_for_uid( netuid, neuron_uid) ,
128
+ 0
129
+ ) ;
130
+ assert_eq ! (
131
+ SubtensorModule :: get_incentive_for_uid( netuid, neuron_uid) ,
132
+ 0
133
+ ) ;
134
+ assert_eq ! (
135
+ SubtensorModule :: get_dividends_for_uid( netuid, neuron_uid) ,
136
+ 0
137
+ ) ;
138
+
139
+ assert ! ( !SubtensorModule :: has_axon_info(
140
+ netuid,
141
+ & new_hotkey_account_id
142
+ ) ) ;
143
+
144
+ // Check axon info is reset.
145
+ let axon_info = SubtensorModule :: get_axon_info ( netuid, & curr_hotkey. unwrap ( ) ) ;
146
+ assert_eq ! ( axon_info. ip, 0 ) ;
147
+ assert_eq ! ( axon_info. port, 0 ) ;
148
+ assert_eq ! ( axon_info. ip_type, 0 ) ;
89
149
} ) ;
90
150
}
91
151
0 commit comments