@@ -899,6 +899,118 @@ fn test_migrate_set_hotkey_identities() {
899
899
} ) ;
900
900
}
901
901
902
+ #[ test]
903
+ fn test_migrate_identities_to_v2 ( ) {
904
+ new_test_ext ( 1 ) . execute_with ( || {
905
+ let account_id_1 = U256 :: from ( 1 ) ;
906
+ let account_id_2 = U256 :: from ( 2 ) ;
907
+
908
+ let chainone_name = b"ChainOne" . to_vec ( ) ;
909
+ let chainone_url = b"https://chainone.example" . to_vec ( ) ;
910
+ let chainone_image = b"some_image_data" . to_vec ( ) ;
911
+ let chainone_discord = b"discord#1" . to_vec ( ) ;
912
+ let chainone_description = b"Old chain identity" . to_vec ( ) ;
913
+ let chainone_additional = b"extra-info" . to_vec ( ) ;
914
+
915
+ let chaintwo_name = b"ChainTwo" . to_vec ( ) ;
916
+ let chaintwo_url = b"https://chaintwo.example" . to_vec ( ) ;
917
+ let chaintwo_description = b"Another chain identity" . to_vec ( ) ;
918
+
919
+ Identities :: < Test > :: insert (
920
+ account_id_1,
921
+ ChainIdentity {
922
+ name : chainone_name. clone ( ) ,
923
+ url : chainone_url. clone ( ) ,
924
+ image : chainone_image. clone ( ) ,
925
+ discord : chainone_discord. clone ( ) ,
926
+ description : chainone_description. clone ( ) ,
927
+ additional : chainone_additional. clone ( ) ,
928
+ } ,
929
+ ) ;
930
+
931
+ Identities :: < Test > :: insert (
932
+ account_id_2,
933
+ ChainIdentity {
934
+ name : chaintwo_name. clone ( ) ,
935
+ url : chaintwo_url. clone ( ) ,
936
+ image : b"" . to_vec ( ) ,
937
+ discord : b"" . to_vec ( ) ,
938
+ description : chaintwo_description. clone ( ) ,
939
+ additional : b"" . to_vec ( ) ,
940
+ } ,
941
+ ) ;
942
+
943
+ let old_subnet_name = b"SubnetExample" . to_vec ( ) ;
944
+ let old_github_repo = b"https://github.com/org/repo" . to_vec ( ) ;
945
+ let old_subnet_contact = b"subnet@example" . to_vec ( ) ;
946
+
947
+ SubnetIdentities :: < Test > :: insert (
948
+ 42u16 ,
949
+ SubnetIdentity {
950
+ subnet_name : old_subnet_name. clone ( ) ,
951
+ github_repo : old_github_repo. clone ( ) ,
952
+ subnet_contact : old_subnet_contact. clone ( ) ,
953
+ } ,
954
+ ) ;
955
+
956
+ assert ! ( Identities :: <Test >:: get( account_id_1) . is_some( ) ) ;
957
+ assert ! ( Identities :: <Test >:: get( account_id_2) . is_some( ) ) ;
958
+ assert ! ( SubnetIdentities :: <Test >:: get( 42u16 ) . is_some( ) ) ;
959
+ assert ! ( !HasMigrationRun :: <Test >:: get(
960
+ b"migrate_identities_to_v2" . to_vec( )
961
+ ) ) ;
962
+
963
+ let weight = crate :: migrations:: migrate_identities_v2:: migrate_identities_to_v2 :: < Test > ( ) ;
964
+
965
+ assert ! (
966
+ HasMigrationRun :: <Test >:: get( b"migrate_identities_to_v2" . to_vec( ) ) ,
967
+ "Expected HasMigrationRun to be true after migration"
968
+ ) ;
969
+ assert ! ( Identities :: <Test >:: get( account_id_1) . is_none( ) ) ;
970
+ assert ! ( Identities :: <Test >:: get( account_id_2) . is_none( ) ) ;
971
+ assert ! ( SubnetIdentities :: <Test >:: get( 42u16 ) . is_none( ) ) ;
972
+
973
+ let new_identity_1 = IdentitiesV2 :: < Test > :: get ( account_id_1)
974
+ . expect ( "ChainOne should be migrated to IdentitiesV2" ) ;
975
+ let expected_github_repo = b"" . to_vec ( ) ;
976
+
977
+ assert_eq ! ( new_identity_1. name, chainone_name) ;
978
+ assert_eq ! ( new_identity_1. url, chainone_url) ;
979
+ assert_eq ! ( new_identity_1. github_repo, expected_github_repo) ;
980
+ assert_eq ! ( new_identity_1. image, chainone_image) ;
981
+ assert_eq ! ( new_identity_1. discord, chainone_discord) ;
982
+ assert_eq ! ( new_identity_1. description, chainone_description) ;
983
+ assert_eq ! ( new_identity_1. additional, chainone_additional) ;
984
+
985
+ let new_identity_2 = IdentitiesV2 :: < Test > :: get ( account_id_2)
986
+ . expect ( "ChainTwo should be migrated to IdentitiesV2" ) ;
987
+ assert_eq ! ( new_identity_2. name, chaintwo_name) ;
988
+ assert_eq ! ( new_identity_2. url, chaintwo_url) ;
989
+ assert_eq ! ( new_identity_2. github_repo, b"" . to_vec( ) ) ;
990
+
991
+ let new_subnet_identity = SubnetIdentitiesV2 :: < Test > :: get ( 42u16 )
992
+ . expect ( "SubnetExample should be migrated to SubnetIdentitiesV2" ) ;
993
+
994
+ let expected_subnet_url = b"" . to_vec ( ) ;
995
+ let expected_discord = b"" . to_vec ( ) ;
996
+ let expected_description = b"" . to_vec ( ) ;
997
+ let expected_additional = b"" . to_vec ( ) ;
998
+
999
+ assert_eq ! ( new_subnet_identity. subnet_name, old_subnet_name) ;
1000
+ assert_eq ! ( new_subnet_identity. github_repo, old_github_repo) ;
1001
+ assert_eq ! ( new_subnet_identity. subnet_contact, old_subnet_contact) ;
1002
+ assert_eq ! ( new_subnet_identity. subnet_url, expected_subnet_url) ;
1003
+ assert_eq ! ( new_subnet_identity. discord, expected_discord) ;
1004
+ assert_eq ! ( new_subnet_identity. description, expected_description) ;
1005
+ assert_eq ! ( new_subnet_identity. additional, expected_additional) ;
1006
+
1007
+ assert ! (
1008
+ weight != Weight :: zero( ) ,
1009
+ "Migration weight should be non-zero"
1010
+ ) ;
1011
+ } ) ;
1012
+ }
1013
+
902
1014
// SKIP_WASM_BUILD=1 RUST_LOG=debug cargo test --test serving -- test_do_set_subnet_identity --exact --nocapture
903
1015
#[ test]
904
1016
fn test_do_set_subnet_identity ( ) {
0 commit comments