@@ -577,4 +577,140 @@ fn test_drain_base_with_subnet_with_two_stakers_registered() {
577
577
close ( stake_before + pending_alpha/2 , stake_after1, 10 ) ; // Registered gets 1/2 emission
578
578
close ( stake_before + pending_alpha/2 , stake_after2, 10 ) ; // Registered gets 1/2 emission.
579
579
} ) ;
580
+ }
581
+
582
+ // SKIP_WASM_BUILD=1 RUST_LOG=debug cargo test --package pallet-subtensor --lib -- tests::coinbase::test_drain_base_with_subnet_with_two_stakers_registered_and_root --exact --show-output --nocapture
583
+ #[ test]
584
+ fn test_drain_base_with_subnet_with_two_stakers_registered_and_root ( ) {
585
+ new_test_ext ( 1 ) . execute_with ( || {
586
+ let root: u16 = 0 ;
587
+ let netuid: u16 = 1 ;
588
+ add_network ( netuid, 1 , 0 ) ;
589
+ let hotkey1 = U256 :: from ( 1 ) ;
590
+ let hotkey2 = U256 :: from ( 2 ) ;
591
+ let coldkey = U256 :: from ( 3 ) ;
592
+ let stake_before: u64 = 1_000_000_000 ;
593
+ register_ok_neuron ( netuid, hotkey1, coldkey, 0 ) ;
594
+ register_ok_neuron ( netuid, hotkey2, coldkey, 0 ) ;
595
+ SubtensorModule :: set_tao_weight ( u64:: MAX ) ; // Set TAO weight to 1.0
596
+ SubtensorModule :: increase_stake_for_hotkey_and_coldkey_on_subnet (
597
+ & hotkey1,
598
+ & coldkey,
599
+ netuid,
600
+ stake_before,
601
+ ) ;
602
+ SubtensorModule :: increase_stake_for_hotkey_and_coldkey_on_subnet (
603
+ & hotkey1,
604
+ & coldkey,
605
+ root,
606
+ stake_before,
607
+ ) ;
608
+ SubtensorModule :: increase_stake_for_hotkey_and_coldkey_on_subnet (
609
+ & hotkey2,
610
+ & coldkey,
611
+ netuid,
612
+ stake_before,
613
+ ) ;
614
+ SubtensorModule :: increase_stake_for_hotkey_and_coldkey_on_subnet (
615
+ & hotkey2,
616
+ & coldkey,
617
+ root,
618
+ stake_before,
619
+ ) ;
620
+ let pending_tao: u64 = 1_000_000_000 ;
621
+ let pending_alpha: u64 = 1_000_000_000 ;
622
+ SubtensorModule :: drain_pending_emission (
623
+ netuid,
624
+ pending_alpha,
625
+ pending_tao,
626
+ 0 ,
627
+ 0 ,
628
+ ) ;
629
+ let stake_after1 = SubtensorModule :: get_stake_for_hotkey_and_coldkey_on_subnet (
630
+ & hotkey1, & coldkey, netuid,
631
+ ) ;
632
+ let root_after1 = SubtensorModule :: get_stake_for_hotkey_and_coldkey_on_subnet (
633
+ & hotkey1, & coldkey, root,
634
+ ) ;
635
+ let stake_after2 = SubtensorModule :: get_stake_for_hotkey_and_coldkey_on_subnet (
636
+ & hotkey2, & coldkey, netuid,
637
+ ) ;
638
+ let root_after2 = SubtensorModule :: get_stake_for_hotkey_and_coldkey_on_subnet (
639
+ & hotkey2, & coldkey, root,
640
+ ) ;
641
+ close ( stake_before + pending_alpha/2 , stake_after1, 10 ) ; // Registered gets 1/2 emission
642
+ close ( stake_before + pending_alpha/2 , stake_after2, 10 ) ; // Registered gets 1/2 emission.
643
+ close ( stake_before + pending_tao/2 , root_after1, 10 ) ; // Registered gets 1/2 tao emission
644
+ close ( stake_before + pending_tao/2 , root_after2, 10 ) ; // Registered gets 1/2 tao emission
645
+ } ) ;
646
+ }
647
+
648
+ // SKIP_WASM_BUILD=1 RUST_LOG=debug cargo test --package pallet-subtensor --lib -- tests::coinbase::test_drain_base_with_subnet_with_two_stakers_registered_and_root_different_amounts --exact --show-output --nocapture
649
+ #[ test]
650
+ fn test_drain_base_with_subnet_with_two_stakers_registered_and_root_different_amounts ( ) {
651
+ new_test_ext ( 1 ) . execute_with ( || {
652
+ let root: u16 = 0 ;
653
+ let netuid: u16 = 1 ;
654
+ add_network ( netuid, 1 , 0 ) ;
655
+ let hotkey1 = U256 :: from ( 1 ) ;
656
+ let hotkey2 = U256 :: from ( 2 ) ;
657
+ let coldkey = U256 :: from ( 3 ) ;
658
+ let stake_before: u64 = 1_000_000_000 ;
659
+ register_ok_neuron ( netuid, hotkey1, coldkey, 0 ) ;
660
+ register_ok_neuron ( netuid, hotkey2, coldkey, 0 ) ;
661
+ SubtensorModule :: set_tao_weight ( u64:: MAX ) ; // Set TAO weight to 1.0
662
+ SubtensorModule :: increase_stake_for_hotkey_and_coldkey_on_subnet (
663
+ & hotkey1,
664
+ & coldkey,
665
+ netuid,
666
+ stake_before,
667
+ ) ;
668
+ SubtensorModule :: increase_stake_for_hotkey_and_coldkey_on_subnet (
669
+ & hotkey1,
670
+ & coldkey,
671
+ root,
672
+ 2 * stake_before, // Hotkey 1 has twice as much root weight.
673
+ ) ;
674
+ SubtensorModule :: increase_stake_for_hotkey_and_coldkey_on_subnet (
675
+ & hotkey2,
676
+ & coldkey,
677
+ netuid,
678
+ stake_before,
679
+ ) ;
680
+ SubtensorModule :: increase_stake_for_hotkey_and_coldkey_on_subnet (
681
+ & hotkey2,
682
+ & coldkey,
683
+ root,
684
+ stake_before,
685
+ ) ;
686
+ let pending_tao: u64 = 1_000_000_000 ;
687
+ let pending_alpha: u64 = 1_000_000_000 ;
688
+ SubtensorModule :: drain_pending_emission (
689
+ netuid,
690
+ pending_alpha,
691
+ pending_tao,
692
+ 0 ,
693
+ 0 ,
694
+ ) ;
695
+ let stake_after1 = SubtensorModule :: get_stake_for_hotkey_and_coldkey_on_subnet (
696
+ & hotkey1, & coldkey, netuid,
697
+ ) ;
698
+ let root_after1 = SubtensorModule :: get_stake_for_hotkey_and_coldkey_on_subnet (
699
+ & hotkey1, & coldkey, root,
700
+ ) ;
701
+ let stake_after2 = SubtensorModule :: get_stake_for_hotkey_and_coldkey_on_subnet (
702
+ & hotkey2, & coldkey, netuid,
703
+ ) ;
704
+ let root_after2 = SubtensorModule :: get_stake_for_hotkey_and_coldkey_on_subnet (
705
+ & hotkey2, & coldkey, root,
706
+ ) ;
707
+ let expected_stake = I96F32 :: from_num ( stake_before) + I96F32 :: from_num ( pending_alpha) * I96F32 :: from_num ( 0.6 ) ;
708
+ close ( expected_stake. to_num :: < u64 > ( ) , stake_after1, 10 ) ; // Registered gets 60% of emission
709
+ let expected_stake2 = I96F32 :: from_num ( stake_before) + I96F32 :: from_num ( pending_alpha) * I96F32 :: from_num ( 0.4 ) ;
710
+ close ( expected_stake2. to_num :: < u64 > ( ) , stake_after2, 10 ) ; // Registered gets 40% emission
711
+ let expected_root1 = I96F32 :: from_num ( 2 * stake_before) + I96F32 :: from_num ( pending_tao) * I96F32 :: from_num ( 2.0 /3.0 ) ;
712
+ close ( expected_root1. to_num :: < u64 > ( ) , root_after1, 10 ) ; // Registered gets 2/3 tao emission
713
+ let expected_root2 = I96F32 :: from_num ( stake_before) + I96F32 :: from_num ( pending_tao) * I96F32 :: from_num ( 1.0 /3.0 ) ;
714
+ close ( expected_root2. to_num :: < u64 > ( ) , root_after2, 10 ) ; // Registered gets 1/3 tao emission
715
+ } ) ;
580
716
}
0 commit comments