@@ -1063,6 +1063,7 @@ fn test_drain_alpha_childkey_parentkey() {
10631063 new_test_ext ( 1 ) . execute_with ( || {
10641064 let netuid = NetUid :: from ( 1 ) ;
10651065 add_network ( netuid, 1 , 0 ) ;
1066+ SubtensorModule :: set_ck_burn ( 0 ) ;
10661067 let parent = U256 :: from ( 1 ) ;
10671068 let child = U256 :: from ( 2 ) ;
10681069 let coldkey = U256 :: from ( 3 ) ;
@@ -1238,6 +1239,7 @@ fn test_get_root_children_drain() {
12381239 let alpha = NetUid :: from ( 1 ) ;
12391240 add_network ( NetUid :: ROOT , 1 , 0 ) ;
12401241 add_network ( alpha, 1 , 0 ) ;
1242+ SubtensorModule :: set_ck_burn ( 0 ) ;
12411243 // Set TAO weight to 1.
12421244 SubtensorModule :: set_tao_weight ( u64:: MAX ) ; // Set TAO weight to 1.
12431245 // Create keys.
@@ -1399,6 +1401,7 @@ fn test_get_root_children_drain_half_proportion() {
13991401 let alpha = NetUid :: from ( 1 ) ;
14001402 add_network ( NetUid :: ROOT , 1 , 0 ) ;
14011403 add_network ( alpha, 1 , 0 ) ;
1404+ SubtensorModule :: set_ck_burn ( 0 ) ;
14021405 // Set TAO weight to 1.
14031406 SubtensorModule :: set_tao_weight ( u64:: MAX ) ; // Set TAO weight to 1.
14041407 // Create keys.
@@ -1576,6 +1579,7 @@ fn test_get_root_children_drain_with_half_take() {
15761579 add_network ( alpha, 1 , 0 ) ;
15771580 // Set TAO weight to 1.
15781581 SubtensorModule :: set_tao_weight ( u64:: MAX ) ; // Set TAO weight to 1.
1582+ SubtensorModule :: set_ck_burn ( 0 ) ;
15791583 // Create keys.
15801584 let cold_alice = U256 :: from ( 0 ) ;
15811585 let cold_bob = U256 :: from ( 1 ) ;
@@ -2750,6 +2754,75 @@ fn test_coinbase_v3_liquidity_update() {
27502754 } ) ;
27512755}
27522756
2757+ // SKIP_WASM_BUILD=1 RUST_LOG=debug cargo test --package pallet-subtensor --lib -- tests::coinbase::test_drain_alpha_childkey_parentkey_with_burn --exact --show-output --nocapture
2758+ #[ test]
2759+ fn test_drain_alpha_childkey_parentkey_with_burn ( ) {
2760+ new_test_ext ( 1 ) . execute_with ( || {
2761+ let netuid = NetUid :: from ( 1 ) ;
2762+ add_network ( netuid, 1 , 0 ) ;
2763+ let parent = U256 :: from ( 1 ) ;
2764+ let child = U256 :: from ( 2 ) ;
2765+ let coldkey = U256 :: from ( 3 ) ;
2766+ let stake_before = AlphaCurrency :: from ( 1_000_000_000 ) ;
2767+ register_ok_neuron ( netuid, child, coldkey, 0 ) ;
2768+ SubtensorModule :: increase_stake_for_hotkey_and_coldkey_on_subnet (
2769+ & parent,
2770+ & coldkey,
2771+ netuid,
2772+ stake_before,
2773+ ) ;
2774+ mock_set_children_no_epochs ( netuid, & parent, & [ ( u64:: MAX , child) ] ) ;
2775+
2776+ // Childkey take is 10%
2777+ ChildkeyTake :: < Test > :: insert ( child, netuid, u16:: MAX / 10 ) ;
2778+
2779+ let burn_rate = SubtensorModule :: get_ck_burn ( ) ;
2780+ let parent_stake_before = SubtensorModule :: get_stake_for_hotkey_on_subnet ( & parent, netuid) ;
2781+ let child_stake_before = SubtensorModule :: get_stake_for_hotkey_on_subnet ( & child, netuid) ;
2782+
2783+ let pending_alpha = AlphaCurrency :: from ( 1_000_000_000 ) ;
2784+ SubtensorModule :: drain_pending_emission (
2785+ netuid,
2786+ pending_alpha,
2787+ TaoCurrency :: ZERO ,
2788+ AlphaCurrency :: ZERO ,
2789+ AlphaCurrency :: ZERO ,
2790+ ) ;
2791+ let parent_stake_after = SubtensorModule :: get_stake_for_hotkey_on_subnet ( & parent, netuid) ;
2792+ let child_stake_after = SubtensorModule :: get_stake_for_hotkey_on_subnet ( & child, netuid) ;
2793+
2794+ let expected_ck_burn = I96F32 :: from_num ( pending_alpha)
2795+ * I96F32 :: from_num ( 9.0 / 10.0 )
2796+ * I96F32 :: from_num ( burn_rate) ;
2797+
2798+ let expected_total = I96F32 :: from_num ( pending_alpha) - expected_ck_burn;
2799+ let parent_ratio = ( I96F32 :: from_num ( pending_alpha) * I96F32 :: from_num ( 9.0 / 10.0 )
2800+ - expected_ck_burn)
2801+ / expected_total;
2802+ let child_ratio = ( I96F32 :: from_num ( pending_alpha) / I96F32 :: from_num ( 10 ) ) / expected_total;
2803+
2804+ let expected =
2805+ I96F32 :: from_num ( stake_before) + I96F32 :: from_num ( pending_alpha) * parent_ratio;
2806+ log:: info!(
2807+ "expected: {:?}, parent_stake_after: {:?}" ,
2808+ expected. to_num:: <u64 >( ) ,
2809+ parent_stake_after
2810+ ) ;
2811+
2812+ close (
2813+ expected. to_num :: < u64 > ( ) ,
2814+ parent_stake_after. into ( ) ,
2815+ 3_000_000 ,
2816+ ) ;
2817+ let expected = I96F32 :: from_num ( u64:: from ( pending_alpha) ) * child_ratio;
2818+ close (
2819+ expected. to_num :: < u64 > ( ) ,
2820+ child_stake_after. into ( ) ,
2821+ 3_000_000 ,
2822+ ) ;
2823+ } ) ;
2824+ }
2825+
27532826#[ test]
27542827fn test_incentive_is_autostaked_to_owner_destination ( ) {
27552828 new_test_ext ( 1 ) . execute_with ( || {
0 commit comments