Skip to content

Commit b5d7c0e

Browse files
clippy tests
1 parent 1b7402d commit b5d7c0e

File tree

5 files changed

+56
-9
lines changed

5 files changed

+56
-9
lines changed

pallets/subtensor/src/lib.rs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -73,7 +73,7 @@ pub mod pallet {
7373
use sp_runtime::traits::{Dispatchable, TrailingZeroInput};
7474
use sp_std::vec;
7575
use sp_std::vec::Vec;
76-
use subtensor_macros::freeze_struct;
76+
use subtensor_macros::freeze_struct;
7777

7878
#[cfg(not(feature = "std"))]
7979
use alloc::boxed::Box;
@@ -1175,7 +1175,7 @@ pub mod pallet {
11751175
StorageDoubleMap<_, Identity, u16, Blake2_128Concat, T::AccountId, AxonInfoOf, OptionQuery>;
11761176
/// --- MAP ( netuid, hotkey ) --> certificate
11771177
#[pallet::storage]
1178-
pub(super) type NeuronCertificates<T: Config> = StorageDoubleMap<
1178+
pub type NeuronCertificates<T: Config> = StorageDoubleMap<
11791179
_,
11801180
Identity,
11811181
u16,

pallets/subtensor/src/subnets/serving.rs

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -31,8 +31,8 @@ impl<T: Config> Pallet<T> {
3131
/// * 'placeholder2' (u8):
3232
/// - Placeholder for further extra params.
3333
///
34-
/// * 'certificate' (Option<Vec<u8>>):
35-
/// - Certificate for mutual Tls connection between neurons
34+
/// * 'certificate' (Option<Vec<u8>>):
35+
/// - Certificate for mutual Tls connection between neurons
3636
///
3737
/// # Event:
3838
/// * AxonServed;
@@ -253,7 +253,7 @@ impl<T: Config> Pallet<T> {
253253
}
254254

255255
pub fn has_neuron_certificate(netuid: u16, hotkey: &T::AccountId) -> bool {
256-
return NeuronCertificates::<T>::contains_key(netuid, hotkey);
256+
NeuronCertificates::<T>::contains_key(netuid, hotkey)
257257
}
258258

259259
pub fn has_prometheus_info(netuid: u16, hotkey: &T::AccountId) -> bool {

pallets/subtensor/tests/serving.rs

Lines changed: 6 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -129,8 +129,9 @@ fn test_serving_tls_ok() {
129129
placeholder2,
130130
certificate.clone()
131131
));
132-
let stored_certificate = SubtensorModule::get_neuron_certificate(netuid, uid);
133-
assert_eq!(stored_certificate.unwrap().certificate, certificate);
132+
let stored_certificate =
133+
SubtensorModule::get_neuron_certificate(netuid, uid).expect("Certificate should exist");
134+
assert_eq!(stored_certificate.certificate, certificate);
134135
let new_certificate = "UPDATED_CERT".as_bytes().to_vec();
135136
assert_ok!(SubtensorModule::serve_axon_tls(
136137
<<Test as Config>::RuntimeOrigin>::signed(hotkey_account_id),
@@ -144,8 +145,9 @@ fn test_serving_tls_ok() {
144145
placeholder2,
145146
new_certificate.clone()
146147
));
147-
let stored_certificate = SubtensorModule::get_neuron_certificate(netuid, uid);
148-
assert_eq!(stored_certificate.unwrap().certificate, new_certificate)
148+
let stored_certificate =
149+
SubtensorModule::get_neuron_certificate(netuid, uid).expect("Certificate should exist");
150+
assert_eq!(stored_certificate.certificate, new_certificate)
149151
});
150152
}
151153

pallets/subtensor/tests/swap_hotkey.rs

Lines changed: 34 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -311,6 +311,40 @@ fn test_swap_axons() {
311311
});
312312
}
313313

314+
// SKIP_WASM_BUILD=1 RUST_LOG=debug cargo test --test swap_hotkey -- test_swap_certificates --exact --nocapture
315+
#[test]
316+
fn test_swap_certificates() {
317+
new_test_ext(1).execute_with(|| {
318+
let old_hotkey = U256::from(1);
319+
let new_hotkey = U256::from(2);
320+
let coldkey = U256::from(3);
321+
let netuid = 0u16;
322+
let certificate = NeuronCertificate {
323+
certificate: vec![1, 2, 3],
324+
};
325+
let mut weight = Weight::zero();
326+
327+
add_network(netuid, 0, 1);
328+
IsNetworkMember::<Test>::insert(old_hotkey, netuid, true);
329+
NeuronCertificates::<Test>::insert(netuid, old_hotkey, certificate.clone());
330+
331+
assert_ok!(SubtensorModule::perform_hotkey_swap(
332+
&old_hotkey,
333+
&new_hotkey,
334+
&coldkey,
335+
&mut weight
336+
));
337+
338+
assert!(!NeuronCertificates::<Test>::contains_key(
339+
netuid, old_hotkey
340+
));
341+
assert_eq!(
342+
NeuronCertificates::<Test>::get(netuid, new_hotkey),
343+
Some(certificate)
344+
);
345+
});
346+
}
347+
314348
// SKIP_WASM_BUILD=1 RUST_LOG=debug cargo test --test swap_hotkey -- test_swap_weight_commits --exact --nocapture
315349
#[test]
316350
fn test_swap_weight_commits() {

pallets/subtensor/tests/uids.rs

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,7 @@
33
use crate::mock::*;
44
use frame_support::assert_ok;
55
use frame_system::Config;
6+
use pallet_subtensor::*;
67
use sp_core::U256;
78

89
mod mock;
@@ -32,6 +33,9 @@ fn test_replace_neuron() {
3233

3334
let new_hotkey_account_id = U256::from(2);
3435
let _new_colkey_account_id = U256::from(12345);
36+
let certificate = NeuronCertificate {
37+
certificate: vec![1, 2, 3],
38+
};
3539

3640
//add network
3741
add_network(netuid, tempo, 0);
@@ -51,6 +55,9 @@ fn test_replace_neuron() {
5155
let neuron_uid = SubtensorModule::get_uid_for_net_and_hotkey(netuid, &hotkey_account_id);
5256
assert_ok!(neuron_uid);
5357

58+
// Set a neuron certificate for it
59+
NeuronCertificates::<Test>::insert(netuid, hotkey_account_id, certificate);
60+
5461
// Replace the neuron.
5562
SubtensorModule::replace_neuron(
5663
netuid,
@@ -77,6 +84,10 @@ fn test_replace_neuron() {
7784
&new_hotkey_account_id
7885
));
7986
assert_eq!(curr_hotkey.unwrap(), new_hotkey_account_id);
87+
88+
// Check neuron certificate was reset
89+
let certificate = SubtensorModule::get_neuron_certificate(netuid, neuron_uid.unwrap());
90+
assert_eq!(certificate, None);
8091
});
8192
}
8293

0 commit comments

Comments
 (0)