Skip to content

Commit

Permalink
Merge pull request opentensor#693 from opentensor/fix-identity-migrat…
Browse files Browse the repository at this point in the history
…ion-test

devnet fix clippy & unit test
  • Loading branch information
JohnReedV authored Jul 29, 2024
2 parents 6dca681 + 2ab7d27 commit 5b5f500
Show file tree
Hide file tree
Showing 13 changed files with 17 additions and 26 deletions.
6 changes: 3 additions & 3 deletions pallets/collective/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -951,9 +951,9 @@ impl<T: Config<I>, I: 'static> Pallet<T, I> {
///
/// If not `approved`:
/// - one event deposited.
/// Two removals, one mutation.
/// Computation and i/o `O(P)` where:
/// - `P` is number of active proposals
/// - two removals, one mutation.
/// - computation and i/o `O(P)` where:
/// - `P` is number of active proposals
fn do_approve_proposal(
seats: MemberCount,
yes_votes: MemberCount,
Expand Down
1 change: 1 addition & 0 deletions pallets/subtensor/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -84,6 +84,7 @@ std = [
"serde_with/std",
"substrate-fixed/std",
"num-traits/std",
"serde_json/std"
]
runtime-benchmarks = [
"frame-benchmarking/runtime-benchmarks",
Expand Down
1 change: 0 additions & 1 deletion pallets/subtensor/tests/children.rs
Original file line number Diff line number Diff line change
Expand Up @@ -297,7 +297,6 @@ fn test_do_set_child_singular_multiple_children() {

// SKIP_WASM_BUILD=1 RUST_LOG=info cargo test --test children -- test_add_singular_child --exact --nocapture
#[test]
#[cfg(not(tarpaulin))]
fn test_add_singular_child() {
new_test_ext(1).execute_with(|| {
let netuid: u16 = 1;
Expand Down
4 changes: 0 additions & 4 deletions pallets/subtensor/tests/coinbase.rs
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,6 @@ use sp_core::U256;

// Test the ability to hash all sorts of hotkeys.
#[test]
#[cfg(not(tarpaulin))]
fn test_hotkey_hashing() {
new_test_ext(1).execute_with(|| {
for i in 0..10000 {
Expand All @@ -18,7 +17,6 @@ fn test_hotkey_hashing() {
// Test drain tempo on hotkeys.
// SKIP_WASM_BUILD=1 RUST_LOG=debug cargo test --test coinbase test_hotkey_drain_time -- --nocapture
#[test]
#[cfg(not(tarpaulin))]
fn test_hotkey_drain_time() {
new_test_ext(1).execute_with(|| {
// Block 0
Expand Down Expand Up @@ -46,7 +44,6 @@ fn test_hotkey_drain_time() {
// To run this test specifically, use the following command:
// SKIP_WASM_BUILD=1 RUST_LOG=debug cargo test --test coinbase test_coinbase_basic -- --nocapture
#[test]
#[cfg(not(tarpaulin))]
fn test_coinbase_basic() {
new_test_ext(1).execute_with(|| {
// Define network ID
Expand Down Expand Up @@ -138,7 +135,6 @@ fn test_coinbase_basic() {
// Test getting and setting hotkey emission tempo
// SKIP_WASM_BUILD=1 RUST_LOG=debug cargo test --test coinbase test_set_and_get_hotkey_emission_tempo -- --nocapture
#[test]
#[cfg(not(tarpaulin))]
fn test_set_and_get_hotkey_emission_tempo() {
new_test_ext(1).execute_with(|| {
// Get the default hotkey emission tempo
Expand Down
1 change: 0 additions & 1 deletion pallets/subtensor/tests/difficulty.rs
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,6 @@ mod mock;
use sp_core::U256;

#[test]
#[cfg(not(tarpaulin))]
fn test_registration_difficulty_adjustment() {
new_test_ext(1).execute_with(|| {
// Create Net 1
Expand Down
1 change: 0 additions & 1 deletion pallets/subtensor/tests/epoch.rs
Original file line number Diff line number Diff line change
Expand Up @@ -2107,7 +2107,6 @@ fn test_zero_weights() {

// Test that epoch assigns validator permits to highest stake uids, varies uid interleaving and stake values.
#[test]
#[cfg(not(tarpaulin))]
fn test_validator_permits() {
let netuid: u16 = 1;
let tempo: u16 = u16::MAX - 1; // high tempo to skip automatic epochs in on_initialize, use manual epochs instead
Expand Down
4 changes: 4 additions & 0 deletions pallets/subtensor/tests/mock.rs
Original file line number Diff line number Diff line change
Expand Up @@ -264,6 +264,7 @@ impl CollectiveInterface<AccountId, H256, u32> for TriumvirateVotes {
}

// We call pallet_collective TriumvirateCollective
#[allow(dead_code)]
type TriumvirateCollective = pallet_collective::Instance1;
impl pallet_collective::Config<TriumvirateCollective> for Test {
type RuntimeOrigin = RuntimeOrigin;
Expand All @@ -281,6 +282,7 @@ impl pallet_collective::Config<TriumvirateCollective> for Test {
}

// We call council members Triumvirate
#[allow(dead_code)]
type TriumvirateMembership = pallet_membership::Instance1;
impl pallet_membership::Config<TriumvirateMembership> for Test {
type RuntimeEvent = RuntimeEvent;
Expand All @@ -297,6 +299,7 @@ impl pallet_membership::Config<TriumvirateMembership> for Test {

// This is a dummy collective instance for managing senate members
// Probably not the best solution, but fastest implementation
#[allow(dead_code)]
type SenateCollective = pallet_collective::Instance2;
impl pallet_collective::Config<SenateCollective> for Test {
type RuntimeOrigin = RuntimeOrigin;
Expand All @@ -314,6 +317,7 @@ impl pallet_collective::Config<SenateCollective> for Test {
}

// We call our top K delegates membership Senate
#[allow(dead_code)]
type SenateMembership = pallet_membership::Instance2;
impl pallet_membership::Config<SenateMembership> for Test {
type RuntimeEvent = RuntimeEvent;
Expand Down
1 change: 0 additions & 1 deletion pallets/subtensor/tests/neuron_info.rs
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,6 @@ fn test_get_neuron_none() {
}

#[test]
#[cfg(not(tarpaulin))]
fn test_get_neuron_some() {
new_test_ext(1).execute_with(|| {
let netuid: u16 = 1;
Expand Down
1 change: 0 additions & 1 deletion pallets/subtensor/tests/registration.rs
Original file line number Diff line number Diff line change
Expand Up @@ -539,7 +539,6 @@ fn test_burn_adjustment() {
}

#[test]
#[cfg(not(tarpaulin))]
fn test_registration_too_many_registrations_per_block() {
new_test_ext(1).execute_with(|| {
let netuid: u16 = 1;
Expand Down
16 changes: 7 additions & 9 deletions pallets/subtensor/tests/serving.rs
Original file line number Diff line number Diff line change
Expand Up @@ -164,7 +164,6 @@ fn test_serving_set_metadata_update() {
}

#[test]
#[cfg(not(tarpaulin))]
fn test_axon_serving_rate_limit_exceeded() {
new_test_ext(1).execute_with(|| {
let hotkey_account_id = U256::from(1);
Expand Down Expand Up @@ -382,7 +381,6 @@ fn test_prometheus_serving_set_metadata_update() {
}

#[test]
#[cfg(not(tarpaulin))]
fn test_prometheus_serving_rate_limit_exceeded() {
new_test_ext(1).execute_with(|| {
let hotkey_account_id = U256::from(1);
Expand Down Expand Up @@ -586,7 +584,7 @@ fn test_do_set_identity() {
));

// Check if identity is set correctly
let stored_identity = Identities::<Test>::get(coldkey).unwrap();
let stored_identity = Identities::<Test>::get(coldkey).expect("Identity should be set");
assert_eq!(stored_identity.name, name);
assert_eq!(stored_identity.url, url);
assert_eq!(stored_identity.image, image);
Expand Down Expand Up @@ -622,7 +620,8 @@ fn test_do_set_identity() {
additional.clone()
));

let updated_identity = Identities::<Test>::get(coldkey).unwrap();
let updated_identity =
Identities::<Test>::get(coldkey).expect("Updated identity should be set");
assert_eq!(updated_identity.name, new_name);
assert_eq!(updated_identity.url, new_url);

Expand Down Expand Up @@ -760,7 +759,7 @@ fn test_set_and_get_identity() {
));

// Get and verify identity
let stored_identity = Identities::<Test>::get(coldkey).unwrap();
let stored_identity = Identities::<Test>::get(coldkey).expect("Identity should be set");
assert_eq!(stored_identity.name, name);
assert_eq!(stored_identity.url, url);
assert_eq!(stored_identity.image, image);
Expand All @@ -782,7 +781,8 @@ fn test_set_and_get_identity() {
));

// Get and verify updated identity
let updated_identity = Identities::<Test>::get(coldkey).unwrap();
let updated_identity =
Identities::<Test>::get(coldkey).expect("Updated identity should be set");
assert_eq!(updated_identity.name, new_name);
assert_eq!(updated_identity.url, new_url);
assert_eq!(updated_identity.image, image);
Expand All @@ -807,9 +807,7 @@ fn test_migrate_set_hotkey_identities() {
>();

// Assert that the migration has run
assert!(HasMigrationRun::<Test>::get(
b"fix_total_coldkey_stake_v7".to_vec()
));
assert!(HasMigrationRun::<Test>::get(b"migrate_identities".to_vec()));

// Verify that some identities were set
// Note: This assumes that at least one valid identity was in the JSON file
Expand Down
2 changes: 0 additions & 2 deletions pallets/subtensor/tests/staking.rs
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,6 @@ use sp_core::{H256, U256};
************************************************************/

#[test]
#[cfg(not(tarpaulin))]
fn test_add_stake_dispatch_info_ok() {
new_test_ext(1).execute_with(|| {
let hotkey = U256::from(0);
Expand Down Expand Up @@ -521,7 +520,6 @@ fn test_remove_stake_rate_limit_exceeded() {
}

#[test]
#[cfg(not(tarpaulin))]
fn test_remove_stake_dispatch_info_ok() {
new_test_ext(1).execute_with(|| {
let hotkey = U256::from(0);
Expand Down
3 changes: 0 additions & 3 deletions pallets/subtensor/tests/weights.rs
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,6 @@ use substrate_fixed::types::I32F32;

// Test the call passes through the subtensor module.
#[test]
#[cfg(not(tarpaulin))]
fn test_set_weights_dispatch_info_ok() {
new_test_ext(0).execute_with(|| {
let dests = vec![1, 1];
Expand All @@ -41,7 +40,6 @@ fn test_set_weights_dispatch_info_ok() {
});
}
#[test]
#[cfg(not(tarpaulin))]
fn test_set_rootweights_dispatch_info_ok() {
new_test_ext(0).execute_with(|| {
let dests = vec![1, 1];
Expand Down Expand Up @@ -404,7 +402,6 @@ fn test_weights_err_no_validator_permit() {

// To execute this test: cargo test --package pallet-subtensor --test weights test_set_weights_min_stake_failed -- --nocapture`
#[test]
#[cfg(not(tarpaulin))]
fn test_set_weights_min_stake_failed() {
new_test_ext(0).execute_with(|| {
let dests = vec![0];
Expand Down
2 changes: 2 additions & 0 deletions runtime/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -529,6 +529,7 @@ impl pallet_collective::Config<TriumvirateCollective> for Runtime {
}

// We call council members Triumvirate
#[allow(dead_code)]
type TriumvirateMembership = pallet_membership::Instance1;
impl pallet_membership::Config<TriumvirateMembership> for Runtime {
type RuntimeEvent = RuntimeEvent;
Expand All @@ -544,6 +545,7 @@ impl pallet_membership::Config<TriumvirateMembership> for Runtime {
}

// We call our top K delegates membership Senate
#[allow(dead_code)]
type SenateMembership = pallet_membership::Instance2;
impl pallet_membership::Config<SenateMembership> for Runtime {
type RuntimeEvent = RuntimeEvent;
Expand Down

0 comments on commit 5b5f500

Please sign in to comment.