@@ -613,56 +613,132 @@ fn test_swap_hotkey_with_no_stake() {
613
613
} ) ;
614
614
}
615
615
616
- // SKIP_WASM_BUILD=1 RUST_LOG=debug cargo test --test swap_hotkey -- test_swap_hotkey_with_multiple_coldkeys_and_subnets --exact --nocapture
616
+ // SKIP_WASM_BUILD=1 RUST_LOG=debug cargo test --package pallet-subtensor --lib -- tests::swap_hotkey:: test_swap_hotkey_with_multiple_coldkeys_and_subnets --exact --show-output
617
617
#[ test]
618
618
fn test_swap_hotkey_with_multiple_coldkeys_and_subnets ( ) {
619
619
new_test_ext ( 1 ) . execute_with ( || {
620
- assert ! ( false ) ;
621
-
622
- // let old_hotkey = U256::from(1);
623
- // let new_hotkey = U256::from(2);
624
- // let coldkey1 = U256::from(3);
625
- // let coldkey2 = U256::from(4);
626
- // let netuid1 = 0;
627
- // let netuid2 = 1;
628
- // let mut weight = Weight::zero();
629
-
630
- // // Set up initial state
631
- // add_network(netuid1, 0, 1);
632
- // add_network(netuid2, 0, 1);
633
- // Owner::<Test>::insert(old_hotkey, coldkey1);
634
- // Stake::<Test>::insert(old_hotkey, coldkey1, 100);
635
- // Stake::<Test>::insert(old_hotkey, coldkey2, 200);
636
- // IsNetworkMember::<Test>::insert(old_hotkey, netuid1, true);
637
- // IsNetworkMember::<Test>::insert(old_hotkey, netuid2, true);
638
- // TotalHotkeyStake::<Test>::insert(old_hotkey, 300);
639
-
640
- // assert_ok!(SubtensorModule::perform_hotkey_swap(
641
- // &old_hotkey,
642
- // &new_hotkey,
643
- // &coldkey1,
644
- // &mut weight
645
- // ));
646
-
647
- // // Check ownership transfer
648
- // assert!(!Owner::<Test>::contains_key(old_hotkey));
649
- // assert_eq!(Owner::<Test>::get(new_hotkey), coldkey1);
650
-
651
- // // Check stake transfer
652
- // assert_eq!(Stake::<Test>::get(new_hotkey, coldkey1), 100);
653
- // assert_eq!(Stake::<Test>::get(new_hotkey, coldkey2), 200);
654
- // assert!(!Stake::<Test>::contains_key(old_hotkey, coldkey1));
655
- // assert!(!Stake::<Test>::contains_key(old_hotkey, coldkey2));
656
-
657
- // // Check subnet membership transfer
658
- // assert!(IsNetworkMember::<Test>::get(new_hotkey, netuid1));
659
- // assert!(IsNetworkMember::<Test>::get(new_hotkey, netuid2));
660
- // assert!(!IsNetworkMember::<Test>::get(old_hotkey, netuid1));
661
- // assert!(!IsNetworkMember::<Test>::get(old_hotkey, netuid2));
662
-
663
- // // Check total stake transfer
664
- // assert_eq!(TotalHotkeyStake::<Test>::get(new_hotkey), 300);
665
- // assert!(!TotalHotkeyStake::<Test>::contains_key(old_hotkey));
620
+ let old_hotkey = U256 :: from ( 1 ) ;
621
+ let new_hotkey = U256 :: from ( 2 ) ;
622
+ let coldkey1 = U256 :: from ( 3 ) ;
623
+ let coldkey2 = U256 :: from ( 4 ) ;
624
+ let netuid1 = 1 ;
625
+ let netuid2 = 2 ;
626
+ let stake = 1_000_000_u64 ;
627
+ let mut weight = Weight :: zero ( ) ;
628
+
629
+ // Set up initial state
630
+ add_network ( netuid1, 0 , 1 ) ;
631
+ add_network ( netuid2, 0 , 1 ) ;
632
+ register_ok_neuron ( netuid1, old_hotkey, coldkey1, 1234 ) ;
633
+ register_ok_neuron ( netuid2, old_hotkey, coldkey1, 1234 ) ;
634
+
635
+ // Add balance to both coldkeys
636
+ SubtensorModule :: add_balance_to_coldkey_account ( & coldkey1, stake + 1_000 ) ;
637
+ SubtensorModule :: add_balance_to_coldkey_account ( & coldkey2, stake + 1_000 ) ;
638
+
639
+ // Stake with coldkey1
640
+ assert_ok ! ( SubtensorModule :: add_stake(
641
+ <<Test as Config >:: RuntimeOrigin >:: signed( coldkey1) ,
642
+ old_hotkey,
643
+ netuid1,
644
+ stake
645
+ ) ) ;
646
+
647
+ // Stake with coldkey2 also
648
+ assert_ok ! ( SubtensorModule :: add_stake(
649
+ <<Test as Config >:: RuntimeOrigin >:: signed( coldkey2) ,
650
+ old_hotkey,
651
+ netuid2,
652
+ stake
653
+ ) ) ;
654
+
655
+ let ck1_stake = SubtensorModule :: get_stake_for_hotkey_and_coldkey_on_subnet (
656
+ & old_hotkey,
657
+ & coldkey1,
658
+ netuid1,
659
+ ) ;
660
+ let ck2_stake = SubtensorModule :: get_stake_for_hotkey_and_coldkey_on_subnet (
661
+ & old_hotkey,
662
+ & coldkey2,
663
+ netuid2,
664
+ ) ;
665
+ assert ! ( ck1_stake > 0 ) ;
666
+ assert ! ( ck2_stake > 0 ) ;
667
+ let total_hk_stake = SubtensorModule :: get_total_stake_for_hotkey ( & old_hotkey) ;
668
+ assert ! ( total_hk_stake > 0 ) ;
669
+
670
+ assert_ok ! ( SubtensorModule :: perform_hotkey_swap(
671
+ & old_hotkey,
672
+ & new_hotkey,
673
+ & coldkey1,
674
+ & mut weight
675
+ ) ) ;
676
+
677
+ // Check ownership transfer
678
+ assert_eq ! (
679
+ SubtensorModule :: get_owning_coldkey_for_hotkey( & new_hotkey) ,
680
+ coldkey1
681
+ ) ;
682
+ assert ! ( !SubtensorModule :: get_owned_hotkeys( & coldkey2) . contains( & new_hotkey) ) ;
683
+
684
+ // Check stake transfer
685
+ assert_eq ! (
686
+ SubtensorModule :: get_stake_for_hotkey_and_coldkey_on_subnet(
687
+ & new_hotkey,
688
+ & coldkey1,
689
+ netuid1
690
+ ) ,
691
+ ck1_stake
692
+ ) ;
693
+ assert_eq ! (
694
+ SubtensorModule :: get_stake_for_hotkey_and_coldkey_on_subnet(
695
+ & new_hotkey,
696
+ & coldkey2,
697
+ netuid2
698
+ ) ,
699
+ ck2_stake
700
+ ) ;
701
+ assert_eq ! (
702
+ SubtensorModule :: get_stake_for_hotkey_and_coldkey_on_subnet(
703
+ & old_hotkey,
704
+ & coldkey1,
705
+ netuid1
706
+ ) ,
707
+ 0
708
+ ) ;
709
+ assert_eq ! (
710
+ SubtensorModule :: get_stake_for_hotkey_and_coldkey_on_subnet(
711
+ & old_hotkey,
712
+ & coldkey2,
713
+ netuid2
714
+ ) ,
715
+ 0
716
+ ) ;
717
+
718
+ // Check subnet membership transfer
719
+ assert ! ( SubtensorModule :: is_hotkey_registered_on_network(
720
+ netuid1,
721
+ & new_hotkey
722
+ ) ) ;
723
+ assert ! ( SubtensorModule :: is_hotkey_registered_on_network(
724
+ netuid2,
725
+ & new_hotkey
726
+ ) ) ;
727
+ assert ! ( !SubtensorModule :: is_hotkey_registered_on_network(
728
+ netuid1,
729
+ & old_hotkey
730
+ ) ) ;
731
+ assert ! ( !SubtensorModule :: is_hotkey_registered_on_network(
732
+ netuid2,
733
+ & old_hotkey
734
+ ) ) ;
735
+
736
+ // Check total stake transfer
737
+ assert_eq ! (
738
+ SubtensorModule :: get_total_stake_for_hotkey( & new_hotkey) ,
739
+ total_hk_stake
740
+ ) ;
741
+ assert_eq ! ( SubtensorModule :: get_total_stake_for_hotkey( & old_hotkey) , 0 ) ;
666
742
} ) ;
667
743
}
668
744
0 commit comments