Skip to content

Commit

Permalink
clippy tests
Browse files Browse the repository at this point in the history
  • Loading branch information
andreea-popescu-reef committed Aug 28, 2024
1 parent 3644dec commit 6bb6d24
Show file tree
Hide file tree
Showing 5 changed files with 56 additions and 9 deletions.
4 changes: 2 additions & 2 deletions pallets/subtensor/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -70,7 +70,7 @@ pub mod pallet {
use sp_runtime::traits::TrailingZeroInput;
use sp_std::vec;
use sp_std::vec::Vec;
use subtensor_macros::freeze_struct;
use subtensor_macros::freeze_struct;

#[cfg(not(feature = "std"))]
use alloc::boxed::Box;
Expand Down Expand Up @@ -1077,7 +1077,7 @@ pub mod pallet {
StorageDoubleMap<_, Identity, u16, Blake2_128Concat, T::AccountId, AxonInfoOf, OptionQuery>;
/// --- MAP ( netuid, hotkey ) --> certificate
#[pallet::storage]
pub(super) type NeuronCertificates<T: Config> = StorageDoubleMap<
pub type NeuronCertificates<T: Config> = StorageDoubleMap<
_,
Identity,
u16,
Expand Down
6 changes: 3 additions & 3 deletions pallets/subtensor/src/subnets/serving.rs
Original file line number Diff line number Diff line change
Expand Up @@ -31,8 +31,8 @@ impl<T: Config> Pallet<T> {
/// * 'placeholder2' (u8):
/// - Placeholder for further extra params.
///
/// * 'certificate' (Option<Vec<u8>>):
/// - Certificate for mutual Tls connection between neurons
/// * 'certificate' (Option<Vec<u8>>):
/// - Certificate for mutual Tls connection between neurons
///
/// # Event:
/// * AxonServed;
Expand Down Expand Up @@ -253,7 +253,7 @@ impl<T: Config> Pallet<T> {
}

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

pub fn has_prometheus_info(netuid: u16, hotkey: &T::AccountId) -> bool {
Expand Down
10 changes: 6 additions & 4 deletions pallets/subtensor/tests/serving.rs
Original file line number Diff line number Diff line change
Expand Up @@ -129,8 +129,9 @@ fn test_serving_tls_ok() {
placeholder2,
certificate.clone()
));
let stored_certificate = SubtensorModule::get_neuron_certificate(netuid, uid);
assert_eq!(stored_certificate.unwrap().certificate, certificate);
let stored_certificate =
SubtensorModule::get_neuron_certificate(netuid, uid).expect("Certificate should exist");
assert_eq!(stored_certificate.certificate, certificate);
let new_certificate = "UPDATED_CERT".as_bytes().to_vec();
assert_ok!(SubtensorModule::serve_axon_tls(
<<Test as Config>::RuntimeOrigin>::signed(hotkey_account_id),
Expand All @@ -144,8 +145,9 @@ fn test_serving_tls_ok() {
placeholder2,
new_certificate.clone()
));
let stored_certificate = SubtensorModule::get_neuron_certificate(netuid, uid);
assert_eq!(stored_certificate.unwrap().certificate, new_certificate)
let stored_certificate =
SubtensorModule::get_neuron_certificate(netuid, uid).expect("Certificate should exist");
assert_eq!(stored_certificate.certificate, new_certificate)
});
}

Expand Down
34 changes: 34 additions & 0 deletions pallets/subtensor/tests/swap_hotkey.rs
Original file line number Diff line number Diff line change
Expand Up @@ -311,6 +311,40 @@ fn test_swap_axons() {
});
}

// SKIP_WASM_BUILD=1 RUST_LOG=debug cargo test --test swap_hotkey -- test_swap_certificates --exact --nocapture
#[test]
fn test_swap_certificates() {
new_test_ext(1).execute_with(|| {
let old_hotkey = U256::from(1);
let new_hotkey = U256::from(2);
let coldkey = U256::from(3);
let netuid = 0u16;
let certificate = NeuronCertificate {
certificate: vec![1, 2, 3],
};
let mut weight = Weight::zero();

add_network(netuid, 0, 1);
IsNetworkMember::<Test>::insert(old_hotkey, netuid, true);
NeuronCertificates::<Test>::insert(netuid, old_hotkey, certificate.clone());

assert_ok!(SubtensorModule::perform_hotkey_swap(
&old_hotkey,
&new_hotkey,
&coldkey,
&mut weight
));

assert!(!NeuronCertificates::<Test>::contains_key(
netuid, old_hotkey
));
assert_eq!(
NeuronCertificates::<Test>::get(netuid, new_hotkey),
Some(certificate)
);
});
}

// SKIP_WASM_BUILD=1 RUST_LOG=debug cargo test --test swap_hotkey -- test_swap_weight_commits --exact --nocapture
#[test]
fn test_swap_weight_commits() {
Expand Down
11 changes: 11 additions & 0 deletions pallets/subtensor/tests/uids.rs
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@
use crate::mock::*;
use frame_support::assert_ok;
use frame_system::Config;
use pallet_subtensor::*;
use sp_core::U256;

mod mock;
Expand Down Expand Up @@ -32,6 +33,9 @@ fn test_replace_neuron() {

let new_hotkey_account_id = U256::from(2);
let _new_colkey_account_id = U256::from(12345);
let certificate = NeuronCertificate {
certificate: vec![1, 2, 3],
};

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

// Set a neuron certificate for it
NeuronCertificates::<Test>::insert(netuid, hotkey_account_id, certificate);

// Replace the neuron.
SubtensorModule::replace_neuron(
netuid,
Expand All @@ -77,6 +84,10 @@ fn test_replace_neuron() {
&new_hotkey_account_id
));
assert_eq!(curr_hotkey.unwrap(), new_hotkey_account_id);

// Check neuron certificate was reset
let certificate = SubtensorModule::get_neuron_certificate(netuid, neuron_uid.unwrap());
assert_eq!(certificate, None);
});
}

Expand Down

0 comments on commit 6bb6d24

Please sign in to comment.