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