diff --git a/pallets/subtensor/src/benchmarks.rs b/pallets/subtensor/src/benchmarks.rs index 223c086419..476be905e9 100644 --- a/pallets/subtensor/src/benchmarks.rs +++ b/pallets/subtensor/src/benchmarks.rs @@ -446,15 +446,16 @@ mod pallet_benchmarks { Subtensor::::add_balance_to_coldkey_account(&old_coldkey, free_balance_old.into()); let name: Vec = b"The fourth Coolest Identity".to_vec(); - let identity = ChainIdentity { + let identity = ChainIdentityV2 { name, url: vec![], + github_repo: vec![], image: vec![], discord: vec![], description: vec![], additional: vec![], }; - Identities::::insert(&old_coldkey, identity); + IdentitiesV2::::insert(&old_coldkey, identity); #[extrinsic_call] _( diff --git a/pallets/subtensor/src/coinbase/root.rs b/pallets/subtensor/src/coinbase/root.rs index 893f855f3e..d508a0162b 100644 --- a/pallets/subtensor/src/coinbase/root.rs +++ b/pallets/subtensor/src/coinbase/root.rs @@ -391,8 +391,6 @@ impl Pallet { let _ = LastHotkeySwapOnNetuid::::clear_prefix(netuid, u32::MAX, None); // --- 20. Identity maps across versions (netuid-scoped). - SubnetIdentities::::remove(netuid); - SubnetIdentitiesV2::::remove(netuid); if SubnetIdentitiesV3::::contains_key(netuid) { SubnetIdentitiesV3::::remove(netuid); Self::deposit_event(Event::SubnetIdentityRemoved(netuid)); diff --git a/pallets/subtensor/src/lib.rs b/pallets/subtensor/src/lib.rs index dd7645e8ff..6d61baadf3 100644 --- a/pallets/subtensor/src/lib.rs +++ b/pallets/subtensor/src/lib.rs @@ -2057,26 +2057,11 @@ pub mod pallet { OptionQuery, >; - /// --- MAP ( coldkey ) --> identity. (DEPRECATED for V2) - #[pallet::storage] - pub type Identities = - StorageMap<_, Blake2_128Concat, T::AccountId, ChainIdentityOf, OptionQuery>; - /// --- MAP ( coldkey ) --> identity #[pallet::storage] pub type IdentitiesV2 = StorageMap<_, Blake2_128Concat, T::AccountId, ChainIdentityOfV2, OptionQuery>; - /// --- MAP ( netuid ) --> identity. (DEPRECATED for V2) - #[pallet::storage] - pub type SubnetIdentities = - StorageMap<_, Blake2_128Concat, NetUid, SubnetIdentityOf, OptionQuery>; - - /// --- MAP ( netuid ) --> identityV2 (DEPRECATED for V3) - #[pallet::storage] - pub type SubnetIdentitiesV2 = - StorageMap<_, Blake2_128Concat, NetUid, SubnetIdentityOfV2, OptionQuery>; - /// --- MAP ( netuid ) --> SubnetIdentityOfV3 #[pallet::storage] pub type SubnetIdentitiesV3 = diff --git a/pallets/subtensor/src/macros/hooks.rs b/pallets/subtensor/src/macros/hooks.rs index 84d4f99e99..b62263e370 100644 --- a/pallets/subtensor/src/macros/hooks.rs +++ b/pallets/subtensor/src/macros/hooks.rs @@ -75,8 +75,6 @@ mod hooks { // Populate OwnedHotkeys map for coldkey swap. Doesn't update storage vesion. // Storage version v6 -> v7 .saturating_add(migrations::migrate_populate_owned_hotkeys::migrate_populate_owned::()) - // Migrate Delegate Ids on chain - .saturating_add(migrations::migrate_chain_identity::migrate_set_hotkey_identities::()) // Migrate Commit-Reval 2.0 .saturating_add(migrations::migrate_commit_reveal_v2::migrate_commit_reveal_2::()) // Migrate to RAO @@ -84,8 +82,6 @@ mod hooks { // Fix the IsNetworkMember map to be consistent with other storage maps .saturating_add(migrations::migrate_fix_is_network_member::migrate_fix_is_network_member::()) .saturating_add(migrations::migrate_subnet_volume::migrate_subnet_volume::()) - // Upgrade identities to V2 - .saturating_add(migrations::migrate_identities_v2::migrate_identities_to_v2::()) // Set the min burn across all subnets to a new minimum .saturating_add(migrations::migrate_set_min_burn::migrate_set_min_burn::()) // Set the min difficulty across all subnets to a new minimum @@ -121,8 +117,6 @@ mod hooks { .saturating_add(migrations::migrate_fix_root_subnet_tao::migrate_fix_root_subnet_tao::()) // Fix the owner disable the registration .saturating_add(migrations::migrate_set_registration_enable::migrate_set_registration_enable::()) - // Migrate Subnet Identities to V3 - .saturating_add(migrations::migrate_subnet_identities_to_v3::migrate_subnet_identities_to_v3::()) // Migrate subnet symbols to fix the shift after subnet 81 .saturating_add(migrations::migrate_subnet_symbols::migrate_subnet_symbols::()) // Migrate CRV3 add commit_block @@ -163,6 +157,8 @@ mod hooks { .saturating_add(migrations::migrate_pending_emissions::migrate_pending_emissions::()) // Reset unactive subnets .saturating_add(migrations::migrate_reset_unactive_sn::migrate_reset_unactive_sn::()) + // Remove old identity map entries(Identities, SubnetIdentities, SubnetIdentitiesV2) + .saturating_add(migrations::migrate_remove_old_identity_maps::migrate_remove_old_identity_maps::()) // Remove unknown neuron axon, certificate prom .saturating_add(migrations::migrate_remove_unknown_neuron_axon_cert_prom::migrate_remove_unknown_neuron_axon_cert_prom::()); weight diff --git a/pallets/subtensor/src/migrations/migrate_chain_identity.rs b/pallets/subtensor/src/migrations/migrate_chain_identity.rs deleted file mode 100644 index 735e63168c..0000000000 --- a/pallets/subtensor/src/migrations/migrate_chain_identity.rs +++ /dev/null @@ -1,171 +0,0 @@ -use crate::alloc::borrow::ToOwned; -use codec::Decode; -use scale_info::prelude::{string::String, vec::Vec}; -use serde::Deserialize; -use sp_core::{ConstU32, crypto::Ss58Codec}; -use sp_runtime::{AccountId32, BoundedVec}; - -use super::*; -use frame_support::{traits::Get, weights::Weight}; -use log; - -#[derive(Deserialize, Debug)] -struct RegistrationRecordJSON { - address: String, - name: String, - url: String, - description: String, -} - -fn string_to_bounded_vec(input: &str) -> Result>, &'static str> { - let vec_u8: Vec = input.to_owned().into_bytes(); - - // Check if the length is within bounds - if vec_u8.len() > 64 { - return Err("Input string is too long"); - } - - // Convert to BoundedVec - BoundedVec::>::try_from(vec_u8) - .map_err(|_| "Failed to convert to BoundedVec") -} - -pub fn migrate_set_hotkey_identities() -> Weight { - let migration_name = b"migrate_identities".to_vec(); - - // Initialize the weight with one read operation. - let mut weight = T::DbWeight::get().reads(1); - - // Check if the migration has already run - if HasMigrationRun::::get(&migration_name) { - log::info!( - "Migration '{:?}' has already run. Skipping.", - String::from_utf8_lossy(&migration_name) - ); - return weight; - } - log::info!( - "Running migration '{}'", - String::from_utf8_lossy(&migration_name) - ); - - // Include the JSON file with delegate info - let data = include_str!("../../../../docs/delegate-info.json"); - - // Iterate over all the delegate records - if let Ok(delegates) = serde_json::from_str::>(data) { - // Iterate through the delegates - for delegate in delegates.iter() { - // Convert fields to bounded vecs - let name_result = string_to_bounded_vec(&delegate.name); - let desc_result = string_to_bounded_vec(&delegate.description); - let url_result = string_to_bounded_vec(&delegate.url); - let hotkey: AccountId32 = match AccountId32::from_ss58check(&delegate.address) { - Ok(account) => account, - Err(_) => { - log::warn!( - "Invalid SS58 address: {:?}. Skipping this delegate.", - delegate.address - ); - continue; - } - }; - let decoded_hotkey: T::AccountId = match T::AccountId::decode(&mut hotkey.as_ref()) { - Ok(decoded) => decoded, - Err(e) => { - log::warn!("Failed to decode hotkey: {e:?}. Skipping this delegate."); - continue; - } - }; - log::info!("Hotkey unwrapped: {decoded_hotkey:?}"); - - // If we should continue with real values. - let mut name: BoundedVec> = BoundedVec::default(); - let mut description: BoundedVec> = BoundedVec::default(); - let mut url: BoundedVec> = BoundedVec::default(); - if let Ok(n) = name_result { - name = n; - } - if let Ok(d) = desc_result { - description = d; - } - if let Ok(u) = url_result { - url = u; - } - - // Unwrap the real values. - let image: BoundedVec> = BoundedVec::default(); - let discord: BoundedVec> = BoundedVec::default(); - let additional: BoundedVec> = BoundedVec::default(); - - // Create the chain identity. - let identity = ChainIdentityOf { - name: name.into(), - url: url.into(), - image: image.into(), - discord: discord.into(), - description: description.into(), - additional: additional.into(), - }; - - // Log the identity details - log::info!("Setting identity for hotkey: {hotkey:?}"); - log::info!("Name: {:?}", String::from_utf8_lossy(&identity.name)); - log::info!("URL: {:?}", String::from_utf8_lossy(&identity.url)); - log::info!("Image: {:?}", String::from_utf8_lossy(&identity.image)); - log::info!("Discord: {:?}", String::from_utf8_lossy(&identity.discord)); - log::info!( - "Description: {:?}", - String::from_utf8_lossy(&identity.description) - ); - log::info!( - "Additional: {:?}", - String::from_utf8_lossy(&identity.additional) - ); - - // Check validation. - let total_length = identity - .name - .len() - .saturating_add(identity.url.len()) - .saturating_add(identity.image.len()) - .saturating_add(identity.discord.len()) - .saturating_add(identity.description.len()) - .saturating_add(identity.additional.len()); - let is_valid: bool = total_length <= 256 + 256 + 1024 + 256 + 1024 + 1024 - && identity.name.len() <= 256 - && identity.url.len() <= 256 - && identity.image.len() <= 1024 - && identity.discord.len() <= 256 - && identity.description.len() <= 1024 - && identity.additional.len() <= 1024; - if !is_valid { - log::info!("Bytes not correct"); - continue; - } - - // Get the owning coldkey. - let coldkey = Owner::::get(decoded_hotkey.clone()); - log::info!("ColdKey: {decoded_hotkey:?}"); - - weight = weight.saturating_add(T::DbWeight::get().reads(1)); - - // Sink into the map. - Identities::::insert(coldkey.clone(), identity.clone()); - weight = weight.saturating_add(T::DbWeight::get().writes(1)); - } - } else { - log::info!("Failed to decode JSON"); - } - // Mark the migration as completed - HasMigrationRun::::insert(&migration_name, true); - weight = weight.saturating_add(T::DbWeight::get().writes(1)); - - log::info!( - "Migration '{:?}' completed. Storage version set to 7.", - String::from_utf8_lossy(&migration_name) - ); - - // Return the migration weight. - weight -} diff --git a/pallets/subtensor/src/migrations/migrate_identities_v2.rs b/pallets/subtensor/src/migrations/migrate_identities_v2.rs deleted file mode 100644 index 505b617b2f..0000000000 --- a/pallets/subtensor/src/migrations/migrate_identities_v2.rs +++ /dev/null @@ -1,91 +0,0 @@ -use super::*; -use frame_support::weights::Weight; -use log; -use scale_info::prelude::{string::String, vec::Vec}; - -pub fn migrate_identities_to_v2() -> Weight { - use frame_support::traits::Get; - let migration_name = b"migrate_identities_to_v2".to_vec(); - - // Start counting weight - let mut weight = T::DbWeight::get().reads(1); - - // Check if we already ran this migration - if HasMigrationRun::::get(&migration_name) { - log::info!( - target: "runtime", - "Migration '{:?}' has already run. Skipping.", - String::from_utf8_lossy(&migration_name) - ); - return weight; - } - - log::info!( - target: "runtime", - "Running migration '{}'", - String::from_utf8_lossy(&migration_name) - ); - - // ----------------------------- - // 1) Migrate Chain Identities - // ----------------------------- - let old_identities = Identities::::iter().collect::>(); - for (account_id, old_identity) in old_identities.clone() { - let new_identity = ChainIdentityV2 { - name: old_identity.name, - url: old_identity.url, - github_repo: Vec::new(), - image: old_identity.image, - discord: old_identity.discord, - description: old_identity.description, - additional: old_identity.additional, - }; - - // Insert into the new storage map - IdentitiesV2::::insert(&account_id, &new_identity); - weight = weight.saturating_add(T::DbWeight::get().writes(1)); - - Identities::::remove(&account_id); - weight = weight.saturating_add(T::DbWeight::get().writes(1)); - } - - weight = weight.saturating_add(T::DbWeight::get().reads(old_identities.len() as u64)); - - // ----------------------------- - // 2) Migrate Subnet Identities - // ----------------------------- - let old_subnet_identities = SubnetIdentities::::iter().collect::>(); - for (netuid, old_subnet_identity) in old_subnet_identities.clone() { - let new_subnet_identity = SubnetIdentityV2 { - subnet_name: old_subnet_identity.subnet_name, - github_repo: old_subnet_identity.github_repo, - subnet_contact: old_subnet_identity.subnet_contact, - subnet_url: Vec::new(), - discord: Vec::new(), - description: Vec::new(), - additional: Vec::new(), - }; - - // Insert into the new storage map - SubnetIdentitiesV2::::insert(netuid, &new_subnet_identity); - weight = weight.saturating_add(T::DbWeight::get().writes(1)); - - SubnetIdentities::::remove(netuid); - weight = weight.saturating_add(T::DbWeight::get().writes(1)); - } - weight = weight.saturating_add(T::DbWeight::get().reads(old_subnet_identities.len() as u64)); - - // ----------------------------- - // Mark the migration as done - // ----------------------------- - HasMigrationRun::::insert(&migration_name, true); - weight = weight.saturating_add(T::DbWeight::get().writes(1)); - - log::info!( - target: "runtime", - "Migration '{}' completed successfully.", - String::from_utf8_lossy(&migration_name) - ); - - weight -} diff --git a/pallets/subtensor/src/migrations/migrate_remove_old_identity_maps.rs b/pallets/subtensor/src/migrations/migrate_remove_old_identity_maps.rs new file mode 100644 index 0000000000..96dc4de2b4 --- /dev/null +++ b/pallets/subtensor/src/migrations/migrate_remove_old_identity_maps.rs @@ -0,0 +1,43 @@ +use super::*; +use crate::HasMigrationRun; +use frame_support::{traits::Get, weights::Weight}; +use scale_info::prelude::string::String; + +pub fn migrate_remove_old_identity_maps() -> Weight { + let migration_name = b"migrate_remove_old_identity_maps".to_vec(); + let mut weight = T::DbWeight::get().reads(1); + + if HasMigrationRun::::get(&migration_name) { + log::info!( + "Migration '{:?}' has already run. Skipping.", + String::from_utf8_lossy(&migration_name) + ); + return weight; + } + + log::info!( + "Running migration '{}'", + String::from_utf8_lossy(&migration_name), + ); + + // ------------------------------ + // Step 1: Remove Map entries + // ------------------------------ + remove_prefix::("SubtensorModule", "Identities", &mut weight); + remove_prefix::("SubtensorModule", "SubnetIdentities", &mut weight); + remove_prefix::("SubtensorModule", "SubnetIdentitiesV2", &mut weight); + + // ------------------------------ + // Step 2: Mark Migration as Completed + // ------------------------------ + + HasMigrationRun::::insert(&migration_name, true); + weight = weight.saturating_add(T::DbWeight::get().writes(1)); + + log::info!( + "Migration '{:?}' completed successfully.", + String::from_utf8_lossy(&migration_name) + ); + + weight +} diff --git a/pallets/subtensor/src/migrations/migrate_subnet_identities_to_v3.rs b/pallets/subtensor/src/migrations/migrate_subnet_identities_to_v3.rs deleted file mode 100644 index fb892645d5..0000000000 --- a/pallets/subtensor/src/migrations/migrate_subnet_identities_to_v3.rs +++ /dev/null @@ -1,70 +0,0 @@ -use super::*; -use frame_support::weights::Weight; -use log; -use scale_info::prelude::{string::String, vec::Vec}; - -pub fn migrate_subnet_identities_to_v3() -> Weight { - use frame_support::traits::Get; - let migration_name = b"migrate_subnet_identities_to_v3".to_vec(); - - // Start counting weight - let mut weight = T::DbWeight::get().reads(1); - - // Check if we already ran this migration - if HasMigrationRun::::get(&migration_name) { - log::info!( - target: "runtime", - "Migration '{:?}' has already run. Skipping.", - String::from_utf8_lossy(&migration_name) - ); - return weight; - } - - log::info!( - target: "runtime", - "Running migration '{}'", - String::from_utf8_lossy(&migration_name) - ); - // ----------------------------- - // 1) Migrate Subnet Identities - // ----------------------------- - let old_subnet_identities = SubnetIdentitiesV2::::iter().collect::>(); - for (netuid, old_subnet_identity) in old_subnet_identities.clone() { - // check for existing SubnetIdentitiesV3 entry, skip if found - if SubnetIdentitiesV3::::contains_key(netuid) { - continue; - } - let new_subnet_identity = SubnetIdentityV3 { - subnet_name: old_subnet_identity.subnet_name, - github_repo: old_subnet_identity.github_repo, - subnet_contact: old_subnet_identity.subnet_contact, - subnet_url: Vec::new(), - discord: Vec::new(), - description: Vec::new(), - logo_url: Vec::new(), - additional: Vec::new(), - }; - - // Insert into the new storage map - SubnetIdentitiesV3::::insert(netuid, &new_subnet_identity); - weight = weight.saturating_add(T::DbWeight::get().writes(1)); - - SubnetIdentitiesV2::::remove(netuid); - weight = weight.saturating_add(T::DbWeight::get().writes(1)); - } - weight = weight.saturating_add(T::DbWeight::get().reads(old_subnet_identities.len() as u64)); - - // ----------------------------- - // Mark the migration as done - // ----------------------------- - HasMigrationRun::::insert(&migration_name, true); - weight = weight.saturating_add(T::DbWeight::get().writes(1)); - - log::info!( - target: "runtime", - "Migration '{}' completed successfully.", - String::from_utf8_lossy(&migration_name) - ); - - weight -} diff --git a/pallets/subtensor/src/migrations/mod.rs b/pallets/subtensor/src/migrations/mod.rs index 2715be2787..6e654cd2ee 100644 --- a/pallets/subtensor/src/migrations/mod.rs +++ b/pallets/subtensor/src/migrations/mod.rs @@ -5,7 +5,6 @@ use sp_io::KillStorageResult; use sp_io::hashing::twox_128; use sp_io::storage::clear_prefix; pub mod migrate_auto_stake_destination; -pub mod migrate_chain_identity; pub mod migrate_coldkey_swap_scheduled; pub mod migrate_commit_reveal_settings; pub mod migrate_commit_reveal_v2; @@ -19,7 +18,6 @@ pub mod migrate_fix_childkeys; pub mod migrate_fix_is_network_member; pub mod migrate_fix_root_subnet_tao; pub mod migrate_fix_root_tao_and_alpha_in; -pub mod migrate_identities_v2; pub mod migrate_init_tao_flow; pub mod migrate_init_total_issuance; pub mod migrate_kappa_map_to_default; @@ -34,6 +32,7 @@ pub mod migrate_rate_limit_keys; pub mod migrate_rate_limiting_last_blocks; pub mod migrate_remove_commitments_rate_limit; pub mod migrate_remove_network_modality; +pub mod migrate_remove_old_identity_maps; pub mod migrate_remove_stake_map; pub mod migrate_remove_tao_dividends; pub mod migrate_remove_total_hotkey_coldkey_stakes_this_interval; @@ -50,7 +49,6 @@ pub mod migrate_set_nominator_min_stake; pub mod migrate_set_registration_enable; pub mod migrate_set_subtoken_enabled; pub mod migrate_stake_threshold; -pub mod migrate_subnet_identities_to_v3; pub mod migrate_subnet_limit_to_default; pub mod migrate_subnet_locked; pub mod migrate_subnet_symbols; diff --git a/pallets/subtensor/src/tests/migration.rs b/pallets/subtensor/src/tests/migration.rs index 7e266487ef..8d439e4e8f 100644 --- a/pallets/subtensor/src/tests/migration.rs +++ b/pallets/subtensor/src/tests/migration.rs @@ -2725,6 +2725,34 @@ fn test_migrate_reset_unactive_sn_idempotence() { }); } +#[test] +fn test_migrate_remove_old_identity_maps() { + let migration = + crate::migrations::migrate_remove_old_identity_maps::migrate_remove_old_identity_maps::; + + const MIGRATION_NAME: &str = "migrate_remove_old_identity_maps"; + + let pallet_name = "SubtensorModule"; + + test_remove_storage_item(MIGRATION_NAME, pallet_name, "Identities", migration, 100); + + test_remove_storage_item( + MIGRATION_NAME, + pallet_name, + "SubnetIdentities", + migration, + 100, + ); + + test_remove_storage_item( + MIGRATION_NAME, + pallet_name, + "SubnetIdentitiesV2", + migration, + 100, + ); +} + #[test] fn test_migrate_remove_unknown_neuron_axon_cert_prom() { use crate::migrations::migrate_remove_unknown_neuron_axon_cert_prom::*; diff --git a/pallets/subtensor/src/tests/serving.rs b/pallets/subtensor/src/tests/serving.rs index d8a9b866d9..b52666bf26 100644 --- a/pallets/subtensor/src/tests/serving.rs +++ b/pallets/subtensor/src/tests/serving.rs @@ -5,7 +5,6 @@ use crate::Error; use crate::transaction_extension::SubtensorTransactionExtension; use crate::*; use frame_support::assert_noop; -use frame_support::pallet_prelude::Weight; use frame_support::{ assert_ok, dispatch::{DispatchClass, DispatchInfo, GetDispatchInfo, Pays}, @@ -908,208 +907,6 @@ fn test_set_and_get_identity() { }); } -// SKIP_WASM_BUILD=1 RUST_LOG=debug cargo test --test serving -- test_migrate_set_hotkey_identities --exact --nocapture -#[test] -fn test_migrate_set_hotkey_identities() { - new_test_ext(1).execute_with(|| { - // Run the migration - let weight = - crate::migrations::migrate_chain_identity::migrate_set_hotkey_identities::(); - - // Assert that the migration has run - assert!(HasMigrationRun::::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 - let mut identity_count = 0; - for (_, _) in Identities::::iter() { - identity_count += 1; - } - assert!( - identity_count > 0, - "No identities were set during migration" - ); - - // Verify that the weight is non-zero - assert!( - weight != Weight::zero(), - "Migration weight should be non-zero" - ); - }); -} - -#[test] -fn test_migrate_identities_to_v2() { - new_test_ext(1).execute_with(|| { - let account_id_1 = U256::from(1); - let account_id_2 = U256::from(2); - - let chainone_name = b"ChainOne".to_vec(); - let chainone_url = b"https://chainone.example".to_vec(); - let chainone_image = b"some_image_data".to_vec(); - let chainone_discord = b"discord#1".to_vec(); - let chainone_description = b"Old chain identity".to_vec(); - let chainone_additional = b"extra-info".to_vec(); - - let chaintwo_name = b"ChainTwo".to_vec(); - let chaintwo_url = b"https://chaintwo.example".to_vec(); - let chaintwo_description = b"Another chain identity".to_vec(); - - Identities::::insert( - account_id_1, - ChainIdentity { - name: chainone_name.clone(), - url: chainone_url.clone(), - image: chainone_image.clone(), - discord: chainone_discord.clone(), - description: chainone_description.clone(), - additional: chainone_additional.clone(), - }, - ); - - Identities::::insert( - account_id_2, - ChainIdentity { - name: chaintwo_name.clone(), - url: chaintwo_url.clone(), - image: b"".to_vec(), - discord: b"".to_vec(), - description: chaintwo_description.clone(), - additional: b"".to_vec(), - }, - ); - - let old_subnet_name = b"SubnetExample".to_vec(); - let old_github_repo = b"https://github.com/org/repo".to_vec(); - let old_subnet_contact = b"subnet@example".to_vec(); - - SubnetIdentities::::insert( - NetUid::from(42), - SubnetIdentity { - subnet_name: old_subnet_name.clone(), - github_repo: old_github_repo.clone(), - subnet_contact: old_subnet_contact.clone(), - }, - ); - - assert!(Identities::::get(account_id_1).is_some()); - assert!(Identities::::get(account_id_2).is_some()); - assert!(SubnetIdentities::::get(NetUid::from(42)).is_some()); - assert!(!HasMigrationRun::::get( - b"migrate_identities_to_v2".to_vec() - )); - - let weight = crate::migrations::migrate_identities_v2::migrate_identities_to_v2::(); - - assert!( - HasMigrationRun::::get(b"migrate_identities_to_v2".to_vec()), - "Expected HasMigrationRun to be true after migration" - ); - assert!(Identities::::get(account_id_1).is_none()); - assert!(Identities::::get(account_id_2).is_none()); - assert!(SubnetIdentities::::get(NetUid::from(42)).is_none()); - - let new_identity_1 = IdentitiesV2::::get(account_id_1) - .expect("ChainOne should be migrated to IdentitiesV2"); - let expected_github_repo = b"".to_vec(); - - assert_eq!(new_identity_1.name, chainone_name); - assert_eq!(new_identity_1.url, chainone_url); - assert_eq!(new_identity_1.github_repo, expected_github_repo); - assert_eq!(new_identity_1.image, chainone_image); - assert_eq!(new_identity_1.discord, chainone_discord); - assert_eq!(new_identity_1.description, chainone_description); - assert_eq!(new_identity_1.additional, chainone_additional); - - let new_identity_2 = IdentitiesV2::::get(account_id_2) - .expect("ChainTwo should be migrated to IdentitiesV2"); - assert_eq!(new_identity_2.name, chaintwo_name); - assert_eq!(new_identity_2.url, chaintwo_url); - assert_eq!(new_identity_2.github_repo, b"".to_vec()); - - let new_subnet_identity = SubnetIdentitiesV2::::get(NetUid::from(42)) - .expect("SubnetExample should be migrated to SubnetIdentitiesV2"); - - let expected_subnet_url = b"".to_vec(); - let expected_discord = b"".to_vec(); - let expected_description = b"".to_vec(); - let expected_additional = b"".to_vec(); - - assert_eq!(new_subnet_identity.subnet_name, old_subnet_name); - assert_eq!(new_subnet_identity.github_repo, old_github_repo); - assert_eq!(new_subnet_identity.subnet_contact, old_subnet_contact); - assert_eq!(new_subnet_identity.subnet_url, expected_subnet_url); - assert_eq!(new_subnet_identity.discord, expected_discord); - assert_eq!(new_subnet_identity.description, expected_description); - assert_eq!(new_subnet_identity.additional, expected_additional); - - assert!( - weight != Weight::zero(), - "Migration weight should be non-zero" - ); - }); -} - -// SKIP_WASM_BUILD=1 RUST_LOG=DEBUG cargo test --release -p pallet-subtensor test_migrate_subnet_identities_to_v3 -- --nocapture -#[test] -fn test_migrate_subnet_identities_to_v3() { - new_test_ext(1).execute_with(|| { - let old_subnet_name = b"SubnetExample".to_vec(); - let old_github_repo = b"https://github.com/org/repo".to_vec(); - let old_subnet_contact = b"subnet@example".to_vec(); - - SubnetIdentitiesV2::::insert( - NetUid::from(16), - SubnetIdentityV2 { - subnet_name: old_subnet_name.clone(), - github_repo: old_github_repo.clone(), - subnet_contact: old_subnet_contact.clone(), - subnet_url: b"".to_vec(), - discord: b"".to_vec(), - description: b"".to_vec(), - additional: b"".to_vec(), - }, - ); - - assert!(SubnetIdentitiesV2::::get(NetUid::from(16)).is_some()); - assert!(!HasMigrationRun::::get( - b"migrate_subnet_identities_to_v3".to_vec() - )); - - let weight = - crate::migrations::migrate_subnet_identities_to_v3::migrate_subnet_identities_to_v3::< - Test, - >(); - - assert!( - HasMigrationRun::::get(b"migrate_subnet_identities_to_v3".to_vec()), - "Expected HasMigrationRun to be true after migration" - ); - assert!(SubnetIdentitiesV2::::get(NetUid::from(16)).is_none()); - - let new_subnet_identity = SubnetIdentitiesV3::::get(NetUid::from(16)) - .expect("SubnetExample should be migrated to SubnetIdentitiesV3"); - - let expected_subnet_url = b"".to_vec(); - let expected_discord = b"".to_vec(); - let expected_description = b"".to_vec(); - let expected_additional = b"".to_vec(); - - assert_eq!(new_subnet_identity.subnet_name, old_subnet_name); - assert_eq!(new_subnet_identity.github_repo, old_github_repo); - assert_eq!(new_subnet_identity.subnet_contact, old_subnet_contact); - assert_eq!(new_subnet_identity.subnet_url, expected_subnet_url); - assert_eq!(new_subnet_identity.discord, expected_discord); - assert_eq!(new_subnet_identity.description, expected_description); - assert_eq!(new_subnet_identity.additional, expected_additional); - - assert!( - weight != Weight::zero(), - "Migration weight should be non-zero" - ); - }); -} - // SKIP_WASM_BUILD=1 RUST_LOG=DEBUG cargo test --release -p pallet-subtensor test_do_set_subnet_identity -- --nocapture #[test] fn test_do_set_subnet_identity() {