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