@@ -1148,3 +1148,100 @@ fn test_swap_complex_parent_child_structure() {
11481148 ) ;
11491149 } ) ;
11501150}
1151+
1152+ #[ test]
1153+ fn test_swap_parent_hotkey_childkey_maps ( ) {
1154+ new_test_ext ( 1 ) . execute_with ( || {
1155+ let netuid: u16 = 1 ;
1156+ let parent_old = U256 :: from ( 1 ) ;
1157+ let coldkey = U256 :: from ( 2 ) ;
1158+ let child = U256 :: from ( 3 ) ;
1159+ let parent_new = U256 :: from ( 4 ) ;
1160+ add_network ( netuid, 0 , 0 ) ;
1161+ SubtensorModule :: create_account_if_non_existent ( & coldkey, & parent_old) ;
1162+
1163+ // Set child and verify state maps
1164+ assert_ok ! ( SubtensorModule :: do_set_children(
1165+ RuntimeOrigin :: signed( coldkey) ,
1166+ parent_old,
1167+ netuid,
1168+ vec![ ( u64 :: MAX , child) ]
1169+ ) ) ;
1170+ assert_eq ! (
1171+ ParentKeys :: <Test >:: get( child, netuid) ,
1172+ vec![ ( u64 :: MAX , parent_old) ]
1173+ ) ;
1174+ assert_eq ! (
1175+ ChildKeys :: <Test >:: get( parent_old, netuid) ,
1176+ vec![ ( u64 :: MAX , child) ]
1177+ ) ;
1178+
1179+ // Swap
1180+ let mut weight = Weight :: zero ( ) ;
1181+ assert_ok ! ( SubtensorModule :: perform_hotkey_swap(
1182+ & parent_old,
1183+ & parent_new,
1184+ & coldkey,
1185+ & mut weight
1186+ ) ) ;
1187+
1188+ // Verify parent and child keys updates
1189+ assert_eq ! (
1190+ ParentKeys :: <Test >:: get( child, netuid) ,
1191+ vec![ ( u64 :: MAX , parent_new) ]
1192+ ) ;
1193+ assert_eq ! (
1194+ ChildKeys :: <Test >:: get( parent_new, netuid) ,
1195+ vec![ ( u64 :: MAX , child) ]
1196+ ) ;
1197+ } )
1198+ }
1199+
1200+ #[ test]
1201+ fn test_swap_child_hotkey_childkey_maps ( ) {
1202+ new_test_ext ( 1 ) . execute_with ( || {
1203+ let netuid: u16 = 1 ;
1204+ let parent = U256 :: from ( 1 ) ;
1205+ let coldkey = U256 :: from ( 2 ) ;
1206+ let child_old = U256 :: from ( 3 ) ;
1207+ let child_new = U256 :: from ( 4 ) ;
1208+ add_network ( netuid, 0 , 0 ) ;
1209+ SubtensorModule :: create_account_if_non_existent ( & coldkey, & child_old) ;
1210+ SubtensorModule :: create_account_if_non_existent ( & coldkey, & parent) ;
1211+
1212+ // Set child and verify state maps
1213+ assert_ok ! ( SubtensorModule :: do_set_children(
1214+ RuntimeOrigin :: signed( coldkey) ,
1215+ parent,
1216+ netuid,
1217+ vec![ ( u64 :: MAX , child_old) ]
1218+ ) ) ;
1219+ assert_eq ! (
1220+ ParentKeys :: <Test >:: get( child_old, netuid) ,
1221+ vec![ ( u64 :: MAX , parent) ]
1222+ ) ;
1223+ assert_eq ! (
1224+ ChildKeys :: <Test >:: get( parent, netuid) ,
1225+ vec![ ( u64 :: MAX , child_old) ]
1226+ ) ;
1227+
1228+ // Swap
1229+ let mut weight = Weight :: zero ( ) ;
1230+ assert_ok ! ( SubtensorModule :: perform_hotkey_swap(
1231+ & child_old,
1232+ & child_new,
1233+ & coldkey,
1234+ & mut weight
1235+ ) ) ;
1236+
1237+ // Verify parent and child keys updates
1238+ assert_eq ! (
1239+ ParentKeys :: <Test >:: get( child_new, netuid) ,
1240+ vec![ ( u64 :: MAX , parent) ]
1241+ ) ;
1242+ assert_eq ! (
1243+ ChildKeys :: <Test >:: get( parent, netuid) ,
1244+ vec![ ( u64 :: MAX , child_new) ]
1245+ ) ;
1246+ } )
1247+ }
0 commit comments