@@ -724,3 +724,44 @@ fn test_drain_base_with_subnet_with_two_stakers_registered_and_root_different_am
724
724
close ( expected_root2. to_num :: < u64 > ( ) , root_after2, 10 ) ;
725
725
} ) ;
726
726
}
727
+
728
+ // SKIP_WASM_BUILD=1 RUST_LOG=debug cargo test --package pallet-subtensor --lib -- tests::coinbase::test_drain_alpha_childkey_parentkey --exact --show-output --nocapture
729
+ #[ test]
730
+ fn test_drain_alpha_childkey_parentkey ( ) {
731
+ new_test_ext ( 1 ) . execute_with ( || {
732
+ let netuid: u16 = 1 ;
733
+ add_network ( netuid, 1 , 0 ) ;
734
+ let parent = U256 :: from ( 1 ) ;
735
+ let child = U256 :: from ( 2 ) ;
736
+ let coldkey = U256 :: from ( 3 ) ;
737
+ let stake_before: u64 = 1_000_000_000 ;
738
+ register_ok_neuron ( netuid, child, coldkey, 0 ) ;
739
+ SubtensorModule :: increase_stake_for_hotkey_and_coldkey_on_subnet (
740
+ & parent,
741
+ & coldkey,
742
+ netuid,
743
+ stake_before,
744
+ ) ;
745
+ mock_set_children_no_epochs ( netuid, & parent, & [ ( u64:: MAX , child) ] ) ;
746
+
747
+ // Childkey take is 10%
748
+ ChildkeyTake :: < Test > :: insert ( child, netuid, u16:: MAX / 10 ) ;
749
+
750
+ let pending_alpha: u64 = 1_000_000_000 ;
751
+ SubtensorModule :: drain_pending_emission ( netuid, pending_alpha, 0 , 0 , 0 ) ;
752
+ let parent_stake_after = SubtensorModule :: get_stake_for_hotkey_on_subnet ( & parent, netuid) ;
753
+ let child_stake_after = SubtensorModule :: get_stake_for_hotkey_on_subnet ( & child, netuid) ;
754
+
755
+ // Child gets 10%, parent gets 90%
756
+ let expected = I96F32 :: from_num ( stake_before)
757
+ + I96F32 :: from_num ( pending_alpha) * I96F32 :: from_num ( 9.0 / 10.0 ) ;
758
+ log:: info!(
759
+ "expected: {:?}, parent_stake_after: {:?}" ,
760
+ expected. to_num:: <u64 >( ) ,
761
+ parent_stake_after
762
+ ) ;
763
+ close ( expected. to_num :: < u64 > ( ) , parent_stake_after, 10_000 ) ;
764
+ let expected = I96F32 :: from_num ( pending_alpha) / I96F32 :: from_num ( 10 ) ;
765
+ close ( expected. to_num :: < u64 > ( ) , child_stake_after, 10_000 ) ;
766
+ } ) ;
767
+ }
0 commit comments