@@ -1381,6 +1381,135 @@ fn test_coldkey_has_associated_hotkeys() {
13811381 } ) ;
13821382}
13831383
1384+
1385+
1386+ // SKIP_WASM_BUILD=1 RUST_LOG=info cargo test --test swap -- test_coldkey_swap_total --exact --nocapture
1387+ #[ test]
1388+ fn test_coldkey_swap_total ( ) {
1389+ new_test_ext ( 1 ) . execute_with ( || {
1390+ let coldkey = U256 :: from ( 1 ) ;
1391+ let nominator1 = U256 :: from ( 2 ) ;
1392+ let nominator2 = U256 :: from ( 3 ) ;
1393+ let nominator3 = U256 :: from ( 4 ) ;
1394+ let delegate1 = U256 :: from ( 5 ) ;
1395+ let delegate2 = U256 :: from ( 6 ) ;
1396+ let delegate3 = U256 :: from ( 7 ) ;
1397+ let hotkey1 = U256 :: from ( 2 ) ;
1398+ let hotkey2 = U256 :: from ( 3 ) ;
1399+ let hotkey3 = U256 :: from ( 4 ) ;
1400+ let netuid1 = 1u16 ;
1401+ let netuid2 = 2u16 ;
1402+ let netuid3 = 3u16 ;
1403+ SubtensorModule :: add_balance_to_coldkey_account ( & coldkey, 1000 ) ;
1404+ SubtensorModule :: add_balance_to_coldkey_account ( & delegate1, 1000 ) ;
1405+ SubtensorModule :: add_balance_to_coldkey_account ( & delegate2, 1000 ) ;
1406+ SubtensorModule :: add_balance_to_coldkey_account ( & delegate3, 1000 ) ;
1407+ SubtensorModule :: add_balance_to_coldkey_account ( & nominator1, 1000 ) ;
1408+ SubtensorModule :: add_balance_to_coldkey_account ( & nominator2, 1000 ) ;
1409+ SubtensorModule :: add_balance_to_coldkey_account ( & nominator3, 1000 ) ;
1410+
1411+ // Setup initial state
1412+ add_network ( netuid1, 13 , 0 ) ;
1413+ add_network ( netuid2, 14 , 0 ) ;
1414+ add_network ( netuid3, 15 , 0 ) ;
1415+ register_ok_neuron ( netuid1, hotkey1, coldkey, 0 ) ;
1416+ register_ok_neuron ( netuid2, hotkey2, coldkey, 0 ) ;
1417+ register_ok_neuron ( netuid3, hotkey3, coldkey, 0 ) ;
1418+ register_ok_neuron ( netuid1, delegate1, delegate1, 0 ) ;
1419+ register_ok_neuron ( netuid2, delegate2, delegate2, 0 ) ;
1420+ register_ok_neuron ( netuid3, delegate3, delegate3, 0 ) ;
1421+ assert_ok ! ( SubtensorModule :: do_become_delegate( <<Test as Config >:: RuntimeOrigin >:: signed( coldkey) , hotkey1, u16 :: MAX / 10 ) ) ;
1422+ assert_ok ! ( SubtensorModule :: do_become_delegate( <<Test as Config >:: RuntimeOrigin >:: signed( coldkey) , hotkey2, u16 :: MAX / 10 ) ) ;
1423+ assert_ok ! ( SubtensorModule :: do_become_delegate( <<Test as Config >:: RuntimeOrigin >:: signed( coldkey) , hotkey3, u16 :: MAX / 10 ) ) ;
1424+ assert_ok ! ( SubtensorModule :: do_become_delegate( <<Test as Config >:: RuntimeOrigin >:: signed( delegate1) , delegate1, u16 :: MAX / 10 ) ) ;
1425+ assert_ok ! ( SubtensorModule :: do_become_delegate( <<Test as Config >:: RuntimeOrigin >:: signed( delegate2) , delegate2, u16 :: MAX / 10 ) ) ;
1426+ assert_ok ! ( SubtensorModule :: do_become_delegate( <<Test as Config >:: RuntimeOrigin >:: signed( delegate3) , delegate3, u16 :: MAX / 10 ) ) ;
1427+
1428+ assert_ok ! ( SubtensorModule :: add_stake( <<Test as Config >:: RuntimeOrigin >:: signed( coldkey) , hotkey1, 100 ) ) ;
1429+ assert_ok ! ( SubtensorModule :: add_stake( <<Test as Config >:: RuntimeOrigin >:: signed( coldkey) , hotkey2, 100 ) ) ;
1430+ assert_ok ! ( SubtensorModule :: add_stake( <<Test as Config >:: RuntimeOrigin >:: signed( coldkey) , hotkey3, 100 ) ) ;
1431+ assert_ok ! ( SubtensorModule :: add_stake( <<Test as Config >:: RuntimeOrigin >:: signed( coldkey) , delegate1, 100 ) ) ;
1432+ assert_ok ! ( SubtensorModule :: add_stake( <<Test as Config >:: RuntimeOrigin >:: signed( coldkey) , delegate2, 100 ) ) ;
1433+ assert_ok ! ( SubtensorModule :: add_stake( <<Test as Config >:: RuntimeOrigin >:: signed( coldkey) , delegate3, 100 ) ) ;
1434+
1435+ assert_ok ! ( SubtensorModule :: add_stake( <<Test as Config >:: RuntimeOrigin >:: signed( delegate1) , hotkey1, 100 ) ) ;
1436+ assert_ok ! ( SubtensorModule :: add_stake( <<Test as Config >:: RuntimeOrigin >:: signed( delegate2) , hotkey2, 100 ) ) ;
1437+ assert_ok ! ( SubtensorModule :: add_stake( <<Test as Config >:: RuntimeOrigin >:: signed( delegate3) , hotkey3, 100 ) ) ;
1438+
1439+ assert_ok ! ( SubtensorModule :: add_stake( <<Test as Config >:: RuntimeOrigin >:: signed( delegate1) , delegate1, 100 ) ) ;
1440+ assert_ok ! ( SubtensorModule :: add_stake( <<Test as Config >:: RuntimeOrigin >:: signed( delegate2) , delegate2, 100 ) ) ;
1441+ assert_ok ! ( SubtensorModule :: add_stake( <<Test as Config >:: RuntimeOrigin >:: signed( delegate3) , delegate3, 100 ) ) ;
1442+
1443+ assert_ok ! ( SubtensorModule :: add_stake( <<Test as Config >:: RuntimeOrigin >:: signed( nominator1) , hotkey1, 100 ) ) ;
1444+ assert_ok ! ( SubtensorModule :: add_stake( <<Test as Config >:: RuntimeOrigin >:: signed( nominator2) , hotkey2, 100 ) ) ;
1445+ assert_ok ! ( SubtensorModule :: add_stake( <<Test as Config >:: RuntimeOrigin >:: signed( nominator3) , hotkey3, 100 ) ) ;
1446+
1447+ assert_ok ! ( SubtensorModule :: add_stake( <<Test as Config >:: RuntimeOrigin >:: signed( nominator1) , delegate1, 100 ) ) ;
1448+ assert_ok ! ( SubtensorModule :: add_stake( <<Test as Config >:: RuntimeOrigin >:: signed( nominator2) , delegate2, 100 ) ) ;
1449+ assert_ok ! ( SubtensorModule :: add_stake( <<Test as Config >:: RuntimeOrigin >:: signed( nominator3) , delegate3, 100 ) ) ;
1450+
1451+ assert_eq ! ( SubtensorModule :: get_owned_hotkeys( & coldkey) , vec![ hotkey1, hotkey2, hotkey3] ) ;
1452+ assert_eq ! ( SubtensorModule :: get_all_staked_hotkeys( & coldkey) , vec![ hotkey1, hotkey2, hotkey3, delegate1, delegate2, delegate3] ) ;
1453+ assert_eq ! ( SubtensorModule :: get_total_stake_for_coldkey( & coldkey) , 600 ) ;
1454+ assert_eq ! ( SubtensorModule :: get_total_stake_for_hotkey( & hotkey1) , 300 ) ;
1455+ assert_eq ! ( SubtensorModule :: get_total_stake_for_hotkey( & hotkey2) , 300 ) ;
1456+ assert_eq ! ( SubtensorModule :: get_total_stake_for_hotkey( & hotkey3) , 300 ) ;
1457+ assert_eq ! ( SubtensorModule :: get_total_stake_for_hotkey( & delegate1) , 300 ) ;
1458+ assert_eq ! ( SubtensorModule :: get_total_stake_for_hotkey( & delegate2) , 300 ) ;
1459+ assert_eq ! ( SubtensorModule :: get_total_stake_for_hotkey( & delegate3) , 300 ) ;
1460+
1461+
1462+ assert_eq ! ( SubtensorModule :: get_owned_hotkeys( & delegate1) , vec![ delegate1] ) ;
1463+ assert_eq ! ( SubtensorModule :: get_owned_hotkeys( & delegate2) , vec![ delegate2] ) ;
1464+ assert_eq ! ( SubtensorModule :: get_owned_hotkeys( & delegate3) , vec![ delegate3] ) ;
1465+ assert_eq ! ( SubtensorModule :: get_all_staked_hotkeys( & delegate1) , vec![ delegate1, hotkey1] ) ;
1466+ assert_eq ! ( SubtensorModule :: get_all_staked_hotkeys( & delegate2) , vec![ delegate2, hotkey2] ) ;
1467+ assert_eq ! ( SubtensorModule :: get_all_staked_hotkeys( & delegate3) , vec![ delegate3, hotkey3] ) ;
1468+
1469+ assert_eq ! ( SubtensorModule :: get_owned_hotkeys( & nominator1) , vec![ ] ) ;
1470+ assert_eq ! ( SubtensorModule :: get_owned_hotkeys( & nominator2) , vec![ ] ) ;
1471+ assert_eq ! ( SubtensorModule :: get_owned_hotkeys( & nominator3) , vec![ ] ) ;
1472+
1473+ assert_eq ! ( SubtensorModule :: get_all_staked_hotkeys( & nominator1) , vec![ hotkey1, delegate1] ) ;
1474+ assert_eq ! ( SubtensorModule :: get_all_staked_hotkeys( & nominator2) , vec![ hotkey2, delegate2] ) ;
1475+ assert_eq ! ( SubtensorModule :: get_all_staked_hotkeys( & nominator3) , vec![ hotkey3, delegate3] ) ;
1476+
1477+ // Perform the swap
1478+ let new_coldkey = U256 :: from ( 1100 ) ;
1479+ assert_eq ! ( SubtensorModule :: get_total_stake_for_coldkey( & coldkey) , 600 ) ;
1480+ assert_ok ! ( SubtensorModule :: perform_swap_coldkey( & coldkey, & new_coldkey ) ) ;
1481+ assert_eq ! ( SubtensorModule :: get_total_stake_for_coldkey( & new_coldkey) , 600 ) ;
1482+
1483+ // Check everything is swapped.
1484+ assert_eq ! ( SubtensorModule :: get_owned_hotkeys( & new_coldkey) , vec![ hotkey1, hotkey2, hotkey3] ) ;
1485+ assert_eq ! ( SubtensorModule :: get_all_staked_hotkeys( & new_coldkey) , vec![ hotkey1, hotkey2, hotkey3, delegate1, delegate2, delegate3] ) ;
1486+ assert_eq ! ( SubtensorModule :: get_total_stake_for_coldkey( & new_coldkey) , 600 ) ;
1487+ assert_eq ! ( SubtensorModule :: get_total_stake_for_hotkey( & hotkey1) , 300 ) ;
1488+ assert_eq ! ( SubtensorModule :: get_total_stake_for_hotkey( & hotkey2) , 300 ) ;
1489+ assert_eq ! ( SubtensorModule :: get_total_stake_for_hotkey( & hotkey3) , 300 ) ;
1490+ assert_eq ! ( SubtensorModule :: get_total_stake_for_hotkey( & delegate1) , 300 ) ;
1491+ assert_eq ! ( SubtensorModule :: get_total_stake_for_hotkey( & delegate2) , 300 ) ;
1492+ assert_eq ! ( SubtensorModule :: get_total_stake_for_hotkey( & delegate3) , 300 ) ;
1493+
1494+ assert_eq ! ( SubtensorModule :: get_owned_hotkeys( & delegate1) , vec![ delegate1] ) ;
1495+ assert_eq ! ( SubtensorModule :: get_owned_hotkeys( & delegate2) , vec![ delegate2] ) ;
1496+ assert_eq ! ( SubtensorModule :: get_owned_hotkeys( & delegate3) , vec![ delegate3] ) ;
1497+ assert_eq ! ( SubtensorModule :: get_all_staked_hotkeys( & delegate1) , vec![ delegate1, hotkey1] ) ;
1498+ assert_eq ! ( SubtensorModule :: get_all_staked_hotkeys( & delegate2) , vec![ delegate2, hotkey2] ) ;
1499+ assert_eq ! ( SubtensorModule :: get_all_staked_hotkeys( & delegate3) , vec![ delegate3, hotkey3] ) ;
1500+
1501+ assert_eq ! ( SubtensorModule :: get_owned_hotkeys( & nominator1) , vec![ ] ) ;
1502+ assert_eq ! ( SubtensorModule :: get_owned_hotkeys( & nominator2) , vec![ ] ) ;
1503+ assert_eq ! ( SubtensorModule :: get_owned_hotkeys( & nominator3) , vec![ ] ) ;
1504+
1505+ assert_eq ! ( SubtensorModule :: get_all_staked_hotkeys( & nominator1) , vec![ hotkey1, delegate1] ) ;
1506+ assert_eq ! ( SubtensorModule :: get_all_staked_hotkeys( & nominator2) , vec![ hotkey2, delegate2] ) ;
1507+ assert_eq ! ( SubtensorModule :: get_all_staked_hotkeys( & nominator3) , vec![ hotkey3, delegate3] ) ;
1508+
1509+
1510+ } ) ;
1511+ }
1512+
13841513// #[test]
13851514// fn test_coldkey_arbitrated_sw() {
13861515// new_test_ext(1).execute_with(|| {
0 commit comments