@@ -48,22 +48,45 @@ fn test_replace_neuron() {
48
48
// Get UID
49
49
let neuron_uid = SubtensorModule :: get_uid_for_net_and_hotkey ( netuid, & hotkey_account_id) ;
50
50
assert_ok ! ( neuron_uid) ;
51
+ let neuron_uid = neuron_uid. unwrap ( ) ;
52
+
53
+ // set non-default values
54
+ Emission :: < T > :: mutate ( netuid, |v| v[ neuron_uid as usize ] = 5u16 ) ;
55
+ Trust :: < T > :: mutate ( netuid, |v| v[ neuron_uid as usize ] = 5u16 ) ;
56
+ Consensus :: < T > :: mutate ( netuid, |v| v[ neuron_uid as usize ] = 5u16 ) ;
57
+ Incentive :: < T > :: mutate ( netuid, |v| v[ neuron_uid as usize ] = 5u16 ) ;
58
+ Dividends :: < T > :: mutate ( netuid, |v| v[ neuron_uid as usize ] = 5u16 ) ;
59
+
60
+ // serve axon mock address
61
+ let ip: u128 = 1676056785 ;
62
+ let port: u16 = 9999 ;
63
+ let ip_type: u8 = 4 ;
64
+ let hotkey = SubtensorModule :: get_hotkey_for_net_and_uid ( netuid, neuron_uid) . unwrap ( ) ;
65
+ assert ! ( SubtensorModule :: serve_axon(
66
+ <<Test as Config >:: RuntimeOrigin >:: signed( hotkey_account_id) ,
67
+ netuid,
68
+ 0 ,
69
+ ip,
70
+ port,
71
+ ip_type,
72
+ 0 ,
73
+ 0 ,
74
+ 0
75
+ )
76
+ . is_ok( ) ) ;
51
77
52
78
// Replace the neuron.
53
- SubtensorModule :: replace_neuron (
54
- netuid,
55
- neuron_uid. unwrap ( ) ,
56
- & new_hotkey_account_id,
57
- block_number,
58
- ) ;
79
+ SubtensorModule :: replace_neuron ( netuid, neuron_uid, & new_hotkey_account_id, block_number) ;
80
+
81
+ assert ! ( !SubtensorModule :: has_axon_info( netuid, & hotkey) ) ;
59
82
60
83
// Check old hotkey is not registered on any network.
61
84
assert ! ( SubtensorModule :: get_uid_for_net_and_hotkey( netuid, & hotkey_account_id) . is_err( ) ) ;
62
85
assert ! ( !SubtensorModule :: is_hotkey_registered_on_any_network(
63
86
& hotkey_account_id
64
87
) ) ;
65
88
66
- let curr_hotkey = SubtensorModule :: get_hotkey_for_net_and_uid ( netuid, neuron_uid. unwrap ( ) ) ;
89
+ let curr_hotkey = SubtensorModule :: get_hotkey_for_net_and_uid ( netuid, neuron_uid) ;
67
90
assert_ok ! ( curr_hotkey) ;
68
91
assert_ne ! ( curr_hotkey. unwrap( ) , hotkey_account_id) ;
69
92
@@ -75,6 +98,33 @@ fn test_replace_neuron() {
75
98
& new_hotkey_account_id
76
99
) ) ;
77
100
assert_eq ! ( curr_hotkey. unwrap( ) , new_hotkey_account_id) ;
101
+
102
+ // Check trust, emission, consensus, incentive, dividends have been reset to 0.
103
+ assert_eq ! ( SubtensorModule :: get_trust_for_uid( netuid, neuron_uid) , 0 ) ;
104
+ assert_eq ! ( SubtensorModule :: get_emission_for_uid( netuid, neuron_uid) , 0 ) ;
105
+ assert_eq ! (
106
+ SubtensorModule :: get_consensus_for_uid( netuid, neuron_uid) ,
107
+ 0
108
+ ) ;
109
+ assert_eq ! (
110
+ SubtensorModule :: get_incentive_for_uid( netuid, neuron_uid) ,
111
+ 0
112
+ ) ;
113
+ assert_eq ! (
114
+ SubtensorModule :: get_dividends_for_uid( netuid, neuron_uid) ,
115
+ 0
116
+ ) ;
117
+
118
+ assert ! ( !SubtensorModule :: has_axon_info(
119
+ netuid,
120
+ & new_hotkey_account_id
121
+ ) ) ;
122
+
123
+ // Check axon info is reset.
124
+ let axon_info = SubtensorModule :: get_axon_info ( netuid, & curr_hotkey. unwrap ( ) ) ;
125
+ assert_eq ! ( axon_info. ip, 0 ) ;
126
+ assert_eq ! ( axon_info. port, 0 ) ;
127
+ assert_eq ! ( axon_info. ip_type, 0 ) ;
78
128
} ) ;
79
129
}
80
130
0 commit comments