diff --git a/node/src/chain_spec.rs b/node/src/chain_spec.rs index 927bc99503..c809863efd 100644 --- a/node/src/chain_spec.rs +++ b/node/src/chain_spec.rs @@ -287,52 +287,8 @@ pub fn finney_testnet_config() -> Result { } pub fn localnet_config() -> Result { - let path: PathBuf = std::path::PathBuf::from("./snapshot.json"); let wasm_binary = WASM_BINARY.ok_or_else(|| "Development wasm not available".to_string())?; - // We mmap the file into memory first, as this is *a lot* faster than using - // `serde_json::from_reader`. See https://github.com/serde-rs/json/issues/160 - let file = File::open(&path) - .map_err(|e| format!("Error opening genesis file `{}`: {}", path.display(), e))?; - - // SAFETY: `mmap` is fundamentally unsafe since technically the file can change - // underneath us while it is mapped; in practice it's unlikely to be a problem - let bytes = unsafe { - memmap2::Mmap::map(&file) - .map_err(|e| format!("Error mmaping genesis file `{}`: {}", path.display(), e))? - }; - - let old_state: ColdkeyHotkeys = - json::from_slice(&bytes).map_err(|e| format!("Error parsing genesis file: {}", e))?; - - let mut processed_stakes: Vec<(sp_runtime::AccountId32, Vec<(sp_runtime::AccountId32, (u64, u16))>)> = Vec::new(); - for (coldkey_str, hotkeys) in old_state.stakes.iter() { - let coldkey = ::from_ss58check(&coldkey_str).unwrap(); - let coldkey_account = sp_runtime::AccountId32::from(coldkey); - - let mut processed_hotkeys: Vec<(sp_runtime::AccountId32, (u64, u16))> = Vec::new(); - - for (hotkey_str, amount_uid) in hotkeys.iter() { - let (amount, uid) = amount_uid; - let hotkey = ::from_ss58check(&hotkey_str).unwrap(); - let hotkey_account = sp_runtime::AccountId32::from(hotkey); - - processed_hotkeys.push((hotkey_account, (*amount, *uid))); - } - - processed_stakes.push((coldkey_account, processed_hotkeys)); - } - - let mut balances_issuance: u64 = 0; - let mut processed_balances: Vec<(sp_runtime::AccountId32, u64)> = Vec::new(); - for (key_str, amount) in old_state.balances.iter() { - let key = ::from_ss58check(&key_str).unwrap(); - let key_account = sp_runtime::AccountId32::from(key); - - processed_balances.push((key_account, *amount)); - balances_issuance += *amount; - } - // Give front-ends necessary data to present to users let mut properties = sc_service::Properties::new(); properties.insert("tokenSymbol".into(), "TAO".into()); @@ -433,7 +389,7 @@ fn localnet_genesis( fn testnet_genesis( wasm_binary: &[u8], initial_authorities: Vec<(AuraId, GrandpaId)>, - root_key: AccountId, + _root_key: AccountId, _endowed_accounts: Vec, _enable_println: bool, _stakes: Vec<(AccountId, Vec<(AccountId, (u64, u16))>)>, @@ -482,7 +438,7 @@ fn testnet_genesis( fn finney_genesis( wasm_binary: &[u8], initial_authorities: Vec<(AuraId, GrandpaId)>, - root_key: AccountId, + _root_key: AccountId, _endowed_accounts: Vec, _enable_println: bool, stakes: Vec<(AccountId, Vec<(AccountId, (u64, u16))>)>, diff --git a/pallets/collective/src/tests.rs b/pallets/collective/src/tests.rs index c13d02dde2..9cb0670d12 100644 --- a/pallets/collective/src/tests.rs +++ b/pallets/collective/src/tests.rs @@ -21,7 +21,7 @@ use frame_support::{ assert_noop, assert_ok, dispatch::Pays, parameter_types, - traits::{ConstU32, ConstU64, GenesisBuild, StorageVersion}, + traits::{ConstU32, ConstU64, GenesisBuild}, Hashable, }; use frame_system::{EnsureRoot, EventRecord, Phase}; diff --git a/pallets/subtensor/src/lib.rs b/pallets/subtensor/src/lib.rs index 38c9a0ac6a..f0a6d0ce0c 100644 --- a/pallets/subtensor/src/lib.rs +++ b/pallets/subtensor/src/lib.rs @@ -21,9 +21,7 @@ use frame_support::{ traits::{ Currency, ExistenceRequirement, - tokens::{ - WithdrawReasons - }, + tokens::WithdrawReasons, IsSubType, } }; diff --git a/pallets/subtensor/src/networks.rs b/pallets/subtensor/src/networks.rs index 1e4f5315a8..d9937b051c 100644 --- a/pallets/subtensor/src/networks.rs +++ b/pallets/subtensor/src/networks.rs @@ -1,5 +1,5 @@ use super::*; -use frame_support::{sp_std::vec}; +use frame_support::sp_std::vec; use sp_std::vec::Vec; use frame_system::ensure_root; use crate::math::checked_sum; diff --git a/pallets/subtensor/src/senate.rs b/pallets/subtensor/src/senate.rs index 11b7217f79..9181fce5f6 100644 --- a/pallets/subtensor/src/senate.rs +++ b/pallets/subtensor/src/senate.rs @@ -69,7 +69,7 @@ impl Pallet { // Check all our leave requirements ensure!(T::SenateMembers::is_member(&hotkey), Error::::NotSenateMember); - T::TriumvirateInterface::remove_votes(&hotkey); + T::TriumvirateInterface::remove_votes(&hotkey)?; T::SenateMembers::remove_member(&hotkey) } @@ -107,7 +107,7 @@ impl Pallet { ensure_root(origin)?; ensure!(!T::SenateMembers::is_member(who), Error::::SenateMember); - T::TriumvirateInterface::remove_votes(who); + T::TriumvirateInterface::remove_votes(who)?; Ok(()) } diff --git a/pallets/subtensor/src/staking.rs b/pallets/subtensor/src/staking.rs index 9e9a1c87e8..ed954cb9d4 100644 --- a/pallets/subtensor/src/staking.rs +++ b/pallets/subtensor/src/staking.rs @@ -219,7 +219,7 @@ impl Pallet { } < SenateRequiredStakePercentage::::get() { // This might cause a panic, but there shouldn't be any reason this will fail with the checks above. - T::TriumvirateInterface::remove_votes(&hotkey); + T::TriumvirateInterface::remove_votes(&hotkey)?; T::SenateMembers::remove_member(&hotkey)?; } diff --git a/pallets/subtensor/src/utils.rs b/pallets/subtensor/src/utils.rs index 792a6bf3e5..4b39e7b01f 100644 --- a/pallets/subtensor/src/utils.rs +++ b/pallets/subtensor/src/utils.rs @@ -1,6 +1,6 @@ use super::*; -use frame_support::{inherent::Vec}; +use frame_support::inherent::Vec; use sp_core::U256; use frame_support::pallet_prelude::DispatchResult; use crate::system::ensure_root; diff --git a/pallets/subtensor/tests/mock.rs b/pallets/subtensor/tests/mock.rs index 5b9bd7cbc1..6375e2740e 100644 --- a/pallets/subtensor/tests/mock.rs +++ b/pallets/subtensor/tests/mock.rs @@ -51,6 +51,7 @@ parameter_types! { pub type AccountId = U256; // The address format for describing accounts. +#[allow(dead_code)] pub type Address = AccountId; // Balance of an account. diff --git a/pallets/subtensor/tests/networks.rs b/pallets/subtensor/tests/networks.rs index 4ca5c5be5b..32c8d3e8f2 100644 --- a/pallets/subtensor/tests/networks.rs +++ b/pallets/subtensor/tests/networks.rs @@ -1,10 +1,17 @@ mod mock; use mock::*; -use pallet_subtensor::{Error}; -use frame_support::weights::{GetDispatchInfo, DispatchInfo, DispatchClass, Pays}; +use pallet_subtensor::Error; use frame_system::Config; -use frame_support::{sp_std::vec}; -use frame_support::{assert_ok}; +use frame_support::{ + dispatch::{ + GetDispatchInfo, + DispatchInfo, + DispatchClass, + Pays + }, + assert_ok, + sp_std::vec +}; use sp_core::U256; /*TO DO SAM: write test for LatuUpdate after it is set */ @@ -12,185 +19,185 @@ use sp_core::U256; // --- add network tests ---- #[test] fn test_add_network_dispatch_info_ok() { - new_test_ext().execute_with(|| { - let netuid: u16 = 1; - let modality = 0; - let tempo: u16 = 13; - let call = RuntimeCall::SubtensorModule(SubtensorCall::sudo_add_network{netuid, tempo, modality}); - assert_eq!(call.get_dispatch_info(), - DispatchInfo { - weight: frame_support::weights::Weight::from_ref_time(50000000), - class: DispatchClass::Operational, - pays_fee: Pays::No - }); + new_test_ext().execute_with(|| { + let netuid: u16 = 1; + let modality = 0; + let tempo: u16 = 13; + let call = RuntimeCall::SubtensorModule(SubtensorCall::sudo_add_network{netuid, tempo, modality}); + assert_eq!(call.get_dispatch_info(), + DispatchInfo { + weight: frame_support::weights::Weight::from_ref_time(50000000), + class: DispatchClass::Operational, + pays_fee: Pays::No + }); });} #[test] fn test_add_network() { - new_test_ext().execute_with(|| { - let modality = 0; - let tempo: u16 = 13; - add_network(10, tempo, modality); - assert_eq!(SubtensorModule::get_number_of_subnets(), 1); - add_network( 20, tempo, modality); - assert_eq!(SubtensorModule::get_number_of_subnets(), 2); + new_test_ext().execute_with(|| { + let modality = 0; + let tempo: u16 = 13; + add_network(10, tempo, modality); + assert_eq!(SubtensorModule::get_number_of_subnets(), 1); + add_network( 20, tempo, modality); + assert_eq!(SubtensorModule::get_number_of_subnets(), 2); });} #[test] fn test_add_network_check_tempo() { - new_test_ext().execute_with(|| { - let modality = 0; - let tempo: u16 = 13; - assert_eq!(SubtensorModule::get_tempo(1), 0); - add_network(1, tempo, modality); - assert_eq!(SubtensorModule::get_tempo(1), 13); + new_test_ext().execute_with(|| { + let modality = 0; + let tempo: u16 = 13; + assert_eq!(SubtensorModule::get_tempo(1), 0); + add_network(1, tempo, modality); + assert_eq!(SubtensorModule::get_tempo(1), 13); });} #[test] fn test_clear_min_allowed_weight_for_network() { - new_test_ext().execute_with(|| { - let netuid: u16 = 1; - let min_allowed_weight = 2; - let tempo: u16 = 13; - add_network(netuid, tempo, 0); - register_ok_neuron( 1, U256::from(55), U256::from(66), 0); - SubtensorModule::set_min_allowed_weights(netuid, min_allowed_weight); - assert_eq!(SubtensorModule::get_min_allowed_weights(netuid), 2); - assert_ok!(SubtensorModule::do_remove_network(<::RuntimeOrigin>::root(), netuid)); - assert_eq!(SubtensorModule::get_min_allowed_weights(netuid), 0); + new_test_ext().execute_with(|| { + let netuid: u16 = 1; + let min_allowed_weight = 2; + let tempo: u16 = 13; + add_network(netuid, tempo, 0); + register_ok_neuron( 1, U256::from(55), U256::from(66), 0); + SubtensorModule::set_min_allowed_weights(netuid, min_allowed_weight); + assert_eq!(SubtensorModule::get_min_allowed_weights(netuid), 2); + assert_ok!(SubtensorModule::do_remove_network(<::RuntimeOrigin>::root(), netuid)); + assert_eq!(SubtensorModule::get_min_allowed_weights(netuid), 0); });} #[test] fn test_remove_uid_for_network() { new_test_ext().execute_with(|| { - let netuid: u16 = 1; - let tempo: u16 = 13; - add_network(netuid, tempo, 0); - register_ok_neuron( 1, U256::from(55), U256::from(66), 0); - let neuron_id ; - match SubtensorModule::get_uid_for_net_and_hotkey(netuid, &U256::from(55)) { - Ok(k) => neuron_id = k, - Err(e) => panic!("Error: {:?}", e), - } - assert!(SubtensorModule::get_uid_for_net_and_hotkey(netuid, &U256::from(55)).is_ok()); - assert_eq!(neuron_id, 0); - register_ok_neuron( 1, U256::from(56), U256::from(67), 300000); - let neuron_uid = SubtensorModule::get_uid_for_net_and_hotkey(netuid, &U256::from(56)).unwrap(); - assert_eq!(neuron_uid, 1); - assert_ok!(SubtensorModule::do_remove_network(<::RuntimeOrigin>::root(), netuid)); - assert!(SubtensorModule::get_uid_for_net_and_hotkey(netuid, &U256::from(55)).is_err()); + let netuid: u16 = 1; + let tempo: u16 = 13; + add_network(netuid, tempo, 0); + register_ok_neuron( 1, U256::from(55), U256::from(66), 0); + let neuron_id ; + match SubtensorModule::get_uid_for_net_and_hotkey(netuid, &U256::from(55)) { + Ok(k) => neuron_id = k, + Err(e) => panic!("Error: {:?}", e), + } + assert!(SubtensorModule::get_uid_for_net_and_hotkey(netuid, &U256::from(55)).is_ok()); + assert_eq!(neuron_id, 0); + register_ok_neuron( 1, U256::from(56), U256::from(67), 300000); + let neuron_uid = SubtensorModule::get_uid_for_net_and_hotkey(netuid, &U256::from(56)).unwrap(); + assert_eq!(neuron_uid, 1); + assert_ok!(SubtensorModule::do_remove_network(<::RuntimeOrigin>::root(), netuid)); + assert!(SubtensorModule::get_uid_for_net_and_hotkey(netuid, &U256::from(55)).is_err()); });} #[test] fn test_remove_difficulty_for_network() { new_test_ext().execute_with(|| { - let netuid: u16 = 1; - let difficulty: u64 = 10; - let tempo: u16 = 13; - add_network(netuid, tempo, 0); - register_ok_neuron( 1, U256::from(55), U256::from(66), 0); - assert_ok!(SubtensorModule::sudo_set_difficulty(<::RuntimeOrigin>::root(), netuid, difficulty)); - assert_eq!(SubtensorModule::get_difficulty_as_u64(netuid), difficulty); - assert_ok!(SubtensorModule::do_remove_network(<::RuntimeOrigin>::root(), netuid)); - assert_eq!(SubtensorModule::get_difficulty_as_u64(netuid), 10000); + let netuid: u16 = 1; + let difficulty: u64 = 10; + let tempo: u16 = 13; + add_network(netuid, tempo, 0); + register_ok_neuron( 1, U256::from(55), U256::from(66), 0); + assert_ok!(SubtensorModule::sudo_set_difficulty(<::RuntimeOrigin>::root(), netuid, difficulty)); + assert_eq!(SubtensorModule::get_difficulty_as_u64(netuid), difficulty); + assert_ok!(SubtensorModule::do_remove_network(<::RuntimeOrigin>::root(), netuid)); + assert_eq!(SubtensorModule::get_difficulty_as_u64(netuid), 10000); });} #[test] fn test_remove_network_for_all_hotkeys() { new_test_ext().execute_with(|| { - let netuid: u16 = 1; - let tempo: u16 = 13; - add_network(netuid, tempo, 0); - register_ok_neuron( 1, U256::from(55), U256::from(66), 0); - register_ok_neuron( 1, U256::from(77), U256::from(88), 65536); - assert_eq!(SubtensorModule::get_subnetwork_n(netuid), 2); - assert_ok!(SubtensorModule::do_remove_network(<::RuntimeOrigin>::root(), netuid)); - assert_eq!(SubtensorModule::get_subnetwork_n(netuid), 0); + let netuid: u16 = 1; + let tempo: u16 = 13; + add_network(netuid, tempo, 0); + register_ok_neuron( 1, U256::from(55), U256::from(66), 0); + register_ok_neuron( 1, U256::from(77), U256::from(88), 65536); + assert_eq!(SubtensorModule::get_subnetwork_n(netuid), 2); + assert_ok!(SubtensorModule::do_remove_network(<::RuntimeOrigin>::root(), netuid)); + assert_eq!(SubtensorModule::get_subnetwork_n(netuid), 0); });} #[test] fn test_network_set_default_value_for_other_parameters() { new_test_ext().execute_with(|| { - let netuid: u16 = 1; - let tempo: u16 = 13; - add_network(netuid, tempo, 0); - assert_eq!(SubtensorModule::get_min_allowed_weights(netuid), 0); - assert_eq!(SubtensorModule::get_emission_value(netuid), 0); - assert_eq!(SubtensorModule::get_max_weight_limit(netuid), u16::MAX); - assert_eq!(SubtensorModule::get_difficulty_as_u64(netuid), 10000); - assert_eq!(SubtensorModule::get_immunity_period(netuid), 2); - + let netuid: u16 = 1; + let tempo: u16 = 13; + add_network(netuid, tempo, 0); + assert_eq!(SubtensorModule::get_min_allowed_weights(netuid), 0); + assert_eq!(SubtensorModule::get_emission_value(netuid), 0); + assert_eq!(SubtensorModule::get_max_weight_limit(netuid), u16::MAX); + assert_eq!(SubtensorModule::get_difficulty_as_u64(netuid), 10000); + assert_eq!(SubtensorModule::get_immunity_period(netuid), 2); + });} // --- Set Emission Ratios Tests #[test] fn test_network_set_emission_ratios_dispatch_info_ok() { new_test_ext().execute_with(|| { - let netuids: Vec = vec![ 1,2 ]; - let emission: Vec = vec![ 100000000, 900000000 ]; - let call = RuntimeCall::SubtensorModule(SubtensorCall::sudo_set_emission_values{ netuids, emission }); - assert_eq!(call.get_dispatch_info(), DispatchInfo { - weight: frame_support::weights::Weight::from_ref_time(28000000), - class: DispatchClass::Operational, - pays_fee: Pays::No - }); + let netuids: Vec = vec![ 1,2 ]; + let emission: Vec = vec![ 100000000, 900000000 ]; + let call = RuntimeCall::SubtensorModule(SubtensorCall::sudo_set_emission_values{ netuids, emission }); + assert_eq!(call.get_dispatch_info(), DispatchInfo { + weight: frame_support::weights::Weight::from_ref_time(28000000), + class: DispatchClass::Operational, + pays_fee: Pays::No + }); });} #[test] fn test_network_set_emission_ratios_ok() { new_test_ext().execute_with(|| { - let netuids: Vec = vec![ 1,2 ]; - let emission: Vec = vec![ 100000000, 900000000 ]; - add_network(1, 0, 0); - add_network(2, 0, 0); - assert_ok!( SubtensorModule::sudo_set_emission_values(<::RuntimeOrigin>::root(), netuids, emission ) ); + let netuids: Vec = vec![ 1,2 ]; + let emission: Vec = vec![ 100000000, 900000000 ]; + add_network(1, 0, 0); + add_network(2, 0, 0); + assert_ok!( SubtensorModule::sudo_set_emission_values(<::RuntimeOrigin>::root(), netuids, emission ) ); });} #[test] fn test_network_set_emission_ratios_fail_summation() { new_test_ext().execute_with(|| { - let netuids: Vec = vec![ 1, 2 ]; - let emission: Vec = vec![ 100000000, 910000000 ]; - add_network(1, 0, 0); - add_network(2, 0, 0); - assert_eq!( SubtensorModule::sudo_set_emission_values(<::RuntimeOrigin>::root(), netuids, emission ), Err(Error::::InvalidEmissionValues.into()) ); + let netuids: Vec = vec![ 1, 2 ]; + let emission: Vec = vec![ 100000000, 910000000 ]; + add_network(1, 0, 0); + add_network(2, 0, 0); + assert_eq!( SubtensorModule::sudo_set_emission_values(<::RuntimeOrigin>::root(), netuids, emission ), Err(Error::::InvalidEmissionValues.into()) ); });} #[test] fn test_network_set_emission_invalid_netuids() { new_test_ext().execute_with(|| { - let netuids: Vec = vec![ 1, 2 ]; - let emission: Vec = vec![ 100000000, 900000000 ]; - add_network(1, 0, 0); - assert_eq!( SubtensorModule::sudo_set_emission_values(<::RuntimeOrigin>::root(), netuids, emission ), Err(Error::::IncorrectNetuidsLength.into()) ); + let netuids: Vec = vec![ 1, 2 ]; + let emission: Vec = vec![ 100000000, 900000000 ]; + add_network(1, 0, 0); + assert_eq!( SubtensorModule::sudo_set_emission_values(<::RuntimeOrigin>::root(), netuids, emission ), Err(Error::::IncorrectNetuidsLength.into()) ); });} #[test] fn test_network_set_emission_ratios_fail_net() { new_test_ext().execute_with(|| { - let netuids: Vec = vec![ 1, 2 ]; - let emission: Vec = vec![ 100000000, 900000000 ]; - add_network(1, 0, 0); - add_network(3, 0, 0); - assert_eq!( SubtensorModule::sudo_set_emission_values(<::RuntimeOrigin>::root(), netuids, emission ), Err(Error::::InvalidUid.into()) ); + let netuids: Vec = vec![ 1, 2 ]; + let emission: Vec = vec![ 100000000, 900000000 ]; + add_network(1, 0, 0); + add_network(3, 0, 0); + assert_eq!( SubtensorModule::sudo_set_emission_values(<::RuntimeOrigin>::root(), netuids, emission ), Err(Error::::InvalidUid.into()) ); });} #[test] fn test_add_difficulty_fail(){ -new_test_ext().execute_with(|| { - let netuid: u16 = 1; - assert_eq!(SubtensorModule::sudo_set_difficulty(<::RuntimeOrigin>::root(), netuid, 120000) , Err(Error::::NetworkDoesNotExist.into()) ); + new_test_ext().execute_with(|| { + let netuid: u16 = 1; + assert_eq!(SubtensorModule::sudo_set_difficulty(<::RuntimeOrigin>::root(), netuid, 120000) , Err(Error::::NetworkDoesNotExist.into()) ); });} #[test] fn test_multi_tempo_with_emission(){ -new_test_ext().execute_with(|| { - let netuid: u16 = 1; - assert_eq!(SubtensorModule::sudo_set_difficulty(<::RuntimeOrigin>::root(), netuid, 120000) , Err(Error::::NetworkDoesNotExist.into()) ); + new_test_ext().execute_with(|| { + let netuid: u16 = 1; + assert_eq!(SubtensorModule::sudo_set_difficulty(<::RuntimeOrigin>::root(), netuid, 120000) , Err(Error::::NetworkDoesNotExist.into()) ); });} @@ -198,35 +205,35 @@ new_test_ext().execute_with(|| { // Required by the test otherwise it would panic if compiled in debug mode #[allow(arithmetic_overflow)] fn test_set_emission_values_errors_on_emission_sum_overflow() { - new_test_ext().execute_with(|| { - let netuids: Vec = vec![ 1,2 ]; - // u64(u64::MAX + 1..000..1) equals to 1_000_000_000 which is the same as - // the value of Self::get_block_emission() expected by the extrinsic - let emission: Vec = vec![ u64::MAX, 1_000_000_001 ]; - add_network(1, 0, 0); - add_network(2, 0, 0); - assert_eq!( - SubtensorModule::sudo_set_emission_values(< = vec![ 1,2 ]; + // u64(u64::MAX + 1..000..1) equals to 1_000_000_000 which is the same as + // the value of Self::get_block_emission() expected by the extrinsic + let emission: Vec = vec![ u64::MAX, 1_000_000_001 ]; + add_network(1, 0, 0); + add_network(2, 0, 0); + assert_eq!( + SubtensorModule::sudo_set_emission_values(<::RuntimeOrigin>::root(), netuids, emission ), - Err(Error::::InvalidEmissionValues.into()) - ); + Err(Error::::InvalidEmissionValues.into()) + ); }); } #[test] #[allow(arithmetic_overflow)] fn test_set_emission_values_no_errors() { - new_test_ext().execute_with(|| { - let netuids: Vec = vec![ 1,2 ]; - let emission: Vec = vec![ 600_000_000, 400_000_000 ]; - - add_network(1, 0, 0); - add_network(2, 0, 0); - assert_eq!( - SubtensorModule::sudo_set_emission_values(< = vec![ 1,2 ]; + let emission: Vec = vec![ 600_000_000, 400_000_000 ]; + + add_network(1, 0, 0); + add_network(2, 0, 0); + assert_eq!( + SubtensorModule::sudo_set_emission_values(<::RuntimeOrigin>::root(), netuids, emission ), - Ok(()) - ); + Ok(()) + ); }); } @@ -234,18 +241,17 @@ Config>::RuntimeOrigin>::root(), netuids, emission ), // Required by the test otherwise it would panic if compiled in debug mode #[allow(arithmetic_overflow)] fn test_set_emission_values_sum_too_large() { - new_test_ext().execute_with(|| { - let netuids: Vec = vec![ 1,2 ]; - // u64(1_000_000_000 + 1) equals to 1_000_000_001 which is more than - // the value of Self::get_block_emission() expected by the extrinsic - let emission: Vec = vec![ 1_000_000_000, 1 ]; - add_network(1, 0, 0); - add_network(2, 0, 0); - assert_eq!( - SubtensorModule::sudo_set_emission_values(<::RuntimeOrigin>::root(), netuids, emission ), - Err(Error::::InvalidEmissionValues.into()) - ); + new_test_ext().execute_with(|| { + let netuids: Vec = vec![ 1,2 ]; + // u64(1_000_000_000 + 1) equals to 1_000_000_001 which is more than + // the value of Self::get_block_emission() expected by the extrinsic + let emission: Vec = vec![ 1_000_000_000, 1 ]; + add_network(1, 0, 0); + add_network(2, 0, 0); + assert_eq!( + SubtensorModule::sudo_set_emission_values(<::RuntimeOrigin>::root(), netuids, emission ), + Err(Error::::InvalidEmissionValues.into()) + ); }); } @@ -253,63 +259,61 @@ Config>::RuntimeOrigin>::root(), netuids, emission ), // Required by the test otherwise it would panic if compiled in debug mode #[allow(arithmetic_overflow)] fn test_set_emission_values_sum_too_small() { - new_test_ext().execute_with(|| { - let netuids: Vec = vec![ 1,2 ]; - // u64(1 + 2_000) equals to 2_001 which is LESS than - // the value of Self::get_block_emission() expected by the extrinsic - let emission: Vec = vec![ 1, 2_000 ]; - add_network(1, 0, 0); - add_network(2, 0, 0); - assert_eq!( - SubtensorModule::sudo_set_emission_values(< = vec![ 1,2 ]; + // u64(1 + 2_000) equals to 2_001 which is LESS than + // the value of Self::get_block_emission() expected by the extrinsic + let emission: Vec = vec![ 1, 2_000 ]; + add_network(1, 0, 0); + add_network(2, 0, 0); + assert_eq!( + SubtensorModule::sudo_set_emission_values(<::RuntimeOrigin>::root(), netuids, emission ), - Err(Error::::InvalidEmissionValues.into()) - ); + Err(Error::::InvalidEmissionValues.into()) + ); }); } #[test] fn test_set_emission_values_too_many_netuids() { - new_test_ext().execute_with(|| { - let netuids: Vec = vec![ 1, 2, 3, 4, 5, 6, 7, 8, 9, 10 ]; + new_test_ext().execute_with(|| { + let netuids: Vec = vec![ 1, 2, 3, 4, 5, 6, 7, 8, 9, 10 ]; - // Sums to 1_000_000_000 and has 10 elements - let emission: Vec = vec![ 1_000_000_000, 0, 0, 0, 0, 0, 0, 0, 0, 0 ]; - add_network(1, 0, 0); - add_network(2, 0, 0); - // We only add 2 networks, so this should fail - assert_eq!( - SubtensorModule::sudo_set_emission_values(<::RuntimeOrigin>::root(), netuids, emission ), - Err(Error::::IncorrectNetuidsLength.into()) - ); + // Sums to 1_000_000_000 and has 10 elements + let emission: Vec = vec![ 1_000_000_000, 0, 0, 0, 0, 0, 0, 0, 0, 0 ]; + add_network(1, 0, 0); + add_network(2, 0, 0); + // We only add 2 networks, so this should fail + assert_eq!( + SubtensorModule::sudo_set_emission_values(<::RuntimeOrigin>::root(), netuids, emission ), + Err(Error::::IncorrectNetuidsLength.into()) + ); }); } #[test] fn test_set_emission_values_over_u16_max_values() { - new_test_ext().execute_with(|| { - // Make vec of u16 with length 2^16 + 2 - let netuids: Vec = vec![0; 0x10002]; - // This is greater than u16::MAX - assert!(netuids.len() > u16::MAX as usize); - // On cast to u16, this will be 2 - assert!(netuids.len() as u16 == 2); + new_test_ext().execute_with(|| { + // Make vec of u16 with length 2^16 + 2 + let netuids: Vec = vec![0; 0x10002]; + // This is greater than u16::MAX + assert!(netuids.len() > u16::MAX as usize); + // On cast to u16, this will be 2 + assert!(netuids.len() as u16 == 2); - // Sums to 1_000_000_000 and the length is 65536 - let mut emission: Vec = vec![ 0; netuids.len() ]; - emission[0] = 1_000_000_000; - - add_network(1, 0, 0); - add_network(2, 0, 0); - // We only add 2 networks, so this should fail - // but if we cast to u16 during length comparison, - // the length will be 2 and the check will pass - assert_eq!( - SubtensorModule::sudo_set_emission_values(<::RuntimeOrigin>::root(), netuids, emission ), - Err(Error::::IncorrectNetuidsLength.into()) - ); + // Sums to 1_000_000_000 and the length is 65536 + let mut emission: Vec = vec![ 0; netuids.len() ]; + emission[0] = 1_000_000_000; + + add_network(1, 0, 0); + add_network(2, 0, 0); + // We only add 2 networks, so this should fail + // but if we cast to u16 during length comparison, + // the length will be 2 and the check will pass + assert_eq!( + SubtensorModule::sudo_set_emission_values(<::RuntimeOrigin>::root(), netuids, emission ), + Err(Error::::IncorrectNetuidsLength.into()) + ); }); } \ No newline at end of file diff --git a/pallets/subtensor/tests/neuron_info.rs b/pallets/subtensor/tests/neuron_info.rs index de78703aab..143355386d 100644 --- a/pallets/subtensor/tests/neuron_info.rs +++ b/pallets/subtensor/tests/neuron_info.rs @@ -1,10 +1,10 @@ mod mock; use mock::*; -use pallet_subtensor::Error; -use frame_support::weights::{GetDispatchInfo, DispatchInfo, DispatchClass, Pays}; -use frame_system::Config; -use frame_support::sp_std::vec; -use frame_support::assert_ok; + + + + + use sp_core::U256; #[test] @@ -50,7 +50,7 @@ fn test_get_neurons_list() { add_network( netuid, tempo, modality ); - let uid: u16 = 42; + let _uid: u16 = 42; let neuron_count = 1; for index in 0..neuron_count { diff --git a/pallets/subtensor/tests/registration.rs b/pallets/subtensor/tests/registration.rs index f3561817fa..3314901793 100644 --- a/pallets/subtensor/tests/registration.rs +++ b/pallets/subtensor/tests/registration.rs @@ -1,14 +1,13 @@ use frame_support::traits::Currency; -use ndarray::stack_new_axis; + use pallet_subtensor::{Error, AxonInfoOf}; -use frame_support::{assert_ok}; +use frame_support::assert_ok; use frame_system::Config; use sp_core::U256; -use crate::{mock::*}; +use crate::mock::*; use frame_support::sp_runtime::DispatchError; -use frame_support::dispatch::{GetDispatchInfo, DispatchInfo}; -use frame_support::weights::{DispatchClass, Pays}; +use frame_support::dispatch::{GetDispatchInfo, DispatchInfo, DispatchClass, Pays}; mod mock; diff --git a/pallets/subtensor/tests/serving.rs b/pallets/subtensor/tests/serving.rs index 6a0a4bfa03..ce19e7babe 100644 --- a/pallets/subtensor/tests/serving.rs +++ b/pallets/subtensor/tests/serving.rs @@ -1,9 +1,15 @@ -use crate::{mock::*}; +use crate::mock::*; mod mock; -use frame_support::assert_ok; -use frame_support::dispatch::{GetDispatchInfo, DispatchInfo}; +use frame_support::{ + assert_ok, + dispatch::{ + GetDispatchInfo, + DispatchInfo, + DispatchClass, + Pays + } +}; use pallet_subtensor::Error; -use frame_support::weights::{DispatchClass, Pays}; use frame_system::Config; use sp_core::U256; diff --git a/pallets/subtensor/tests/staking.rs b/pallets/subtensor/tests/staking.rs index 5bab5fa684..c6eace9c94 100644 --- a/pallets/subtensor/tests/staking.rs +++ b/pallets/subtensor/tests/staking.rs @@ -1,9 +1,9 @@ use frame_support::{assert_ok, assert_noop, traits::Currency}; -use frame_system::{Config}; +use frame_system::Config; mod mock; use mock::*; use frame_support::sp_runtime::DispatchError; -use pallet_subtensor::{Error}; +use pallet_subtensor::Error; use frame_support::dispatch::{GetDispatchInfo, DispatchInfo, DispatchClass, Pays}; use sp_core::U256; @@ -1293,9 +1293,8 @@ fn test_unstake_all_coldkeys_from_hotkey_account() { // Register delegate register_ok_neuron( netuid, hotkey_id, coldkey0_id, start_nonce); - let neuron_uid ; match SubtensorModule::get_uid_for_net_and_hotkey(netuid, &hotkey_id) { - Ok(k) => neuron_uid = k, + Ok(_k) => (), Err(e) => panic!("Error: {:?}", e), } @@ -1351,9 +1350,8 @@ fn test_unstake_all_coldkeys_from_hotkey_account_single_staker() { // Register delegate register_ok_neuron( netuid, hotkey_id, coldkey0_id, start_nonce); - let neuron_uid ; match SubtensorModule::get_uid_for_net_and_hotkey(netuid, &hotkey_id) { - Ok(k) => neuron_uid = k, + Ok(_) => (), Err(e) => panic!("Error: {:?}", e), } diff --git a/pallets/subtensor/tests/weights.rs b/pallets/subtensor/tests/weights.rs index 49eb5adc24..d3d9b8ce61 100644 --- a/pallets/subtensor/tests/weights.rs +++ b/pallets/subtensor/tests/weights.rs @@ -1,9 +1,15 @@ mod mock; use mock::*; -use pallet_subtensor::{Error}; +use pallet_subtensor::Error; use frame_system::Config; -use frame_support::dispatch::{GetDispatchInfo, DispatchInfo, DispatchClass, Pays}; -use frame_support::{assert_ok}; +use frame_support::{ + assert_ok, + dispatch::{ + GetDispatchInfo, + DispatchClass, + Pays + } +}; use sp_runtime::DispatchError; use substrate_fixed::types::I32F32; use sp_core::U256; diff --git a/runtime/src/lib.rs b/runtime/src/lib.rs index 82ec9575ec..b06cf7823c 100644 --- a/runtime/src/lib.rs +++ b/runtime/src/lib.rs @@ -6,14 +6,14 @@ #[cfg(feature = "std")] include!(concat!(env!("OUT_DIR"), "/wasm_binary.rs")); -use codec::{Encode, Decode}; -use pallet_collective::EnsureMember; +use codec::Encode; + use pallet_grandpa::{ fg_primitives, AuthorityId as GrandpaId, AuthorityList as GrandpaAuthorityList, }; -use frame_support::{pallet_prelude::{Get, TypeInfo, MaxEncodedLen, PhantomData, EnsureOrigin, DispatchResult}, traits::{EitherOfDiverse}, RuntimeDebug}; -use frame_system::{EnsureRoot, Config, EnsureNever, RawOrigin}; +use frame_support::pallet_prelude::{Get, DispatchResult}; +use frame_system::{EnsureRoot, EnsureNever, RawOrigin}; use smallvec::smallvec; use sp_api::impl_runtime_apis;