@@ -2749,3 +2749,101 @@ fn test_coinbase_v3_liquidity_update() {
27492749 assert ! ( liquidity_before < liquidity_after) ;
27502750 } ) ;
27512751}
2752+
2753+ #[ test]
2754+ fn test_incentive_is_autostaked_to_owner_destination ( ) {
2755+ new_test_ext ( 1 ) . execute_with ( || {
2756+ let subnet_owner_ck = U256 :: from ( 0 ) ;
2757+ let subnet_owner_hk = U256 :: from ( 1 ) ;
2758+
2759+ let miner_ck = U256 :: from ( 10 ) ;
2760+ let miner_hk = U256 :: from ( 11 ) ;
2761+ let dest_hk = U256 :: from ( 12 ) ;
2762+
2763+ Owner :: < Test > :: insert ( miner_hk, miner_ck) ;
2764+ Owner :: < Test > :: insert ( dest_hk, miner_ck) ;
2765+ OwnedHotkeys :: < Test > :: insert ( miner_ck, vec ! [ miner_hk, dest_hk] ) ;
2766+
2767+ let netuid = add_dynamic_network ( & subnet_owner_hk, & subnet_owner_ck) ;
2768+
2769+ Uids :: < Test > :: insert ( netuid, miner_hk, 1 ) ;
2770+ Uids :: < Test > :: insert ( netuid, dest_hk, 2 ) ;
2771+
2772+ // Set autostake destination for the miner's coldkey
2773+ AutoStakeDestination :: < Test > :: insert ( miner_ck, dest_hk) ;
2774+
2775+ assert_eq ! (
2776+ SubtensorModule :: get_stake_for_hotkey_on_subnet( & miner_hk, netuid) ,
2777+ 0 . into( )
2778+ ) ;
2779+ assert_eq ! (
2780+ SubtensorModule :: get_stake_for_hotkey_on_subnet( & dest_hk, netuid) ,
2781+ 0 . into( )
2782+ ) ;
2783+
2784+ // Distribute an incentive to the miner hotkey
2785+ let mut incentives: BTreeMap < U256 , AlphaCurrency > = BTreeMap :: new ( ) ;
2786+ let incentive: AlphaCurrency = 10_000_000u64 . into ( ) ;
2787+ incentives. insert ( miner_hk, incentive) ;
2788+
2789+ SubtensorModule :: distribute_dividends_and_incentives (
2790+ netuid,
2791+ AlphaCurrency :: ZERO , // owner_cut
2792+ incentives,
2793+ BTreeMap :: new ( ) , // alpha_dividends
2794+ BTreeMap :: new ( ) , // tao_dividends
2795+ ) ;
2796+
2797+ // Expect the stake to land on the destination hotkey (not the original miner hotkey)
2798+ assert_eq ! (
2799+ SubtensorModule :: get_stake_for_hotkey_on_subnet( & miner_hk, netuid) ,
2800+ 0 . into( )
2801+ ) ;
2802+ assert_eq ! (
2803+ SubtensorModule :: get_stake_for_hotkey_on_subnet( & dest_hk, netuid) ,
2804+ incentive
2805+ ) ;
2806+ } ) ;
2807+ }
2808+
2809+ #[ test]
2810+ fn test_incentive_goes_to_hotkey_when_no_autostake_destination ( ) {
2811+ new_test_ext ( 1 ) . execute_with ( || {
2812+ let subnet_owner_ck = U256 :: from ( 0 ) ;
2813+ let subnet_owner_hk = U256 :: from ( 1 ) ;
2814+
2815+ let miner_ck = U256 :: from ( 20 ) ;
2816+ let miner_hk = U256 :: from ( 21 ) ;
2817+
2818+ Owner :: < Test > :: insert ( miner_hk, miner_ck) ;
2819+ OwnedHotkeys :: < Test > :: insert ( miner_ck, vec ! [ miner_hk] ) ;
2820+
2821+ let netuid = add_dynamic_network ( & subnet_owner_hk, & subnet_owner_ck) ;
2822+
2823+ Uids :: < Test > :: insert ( netuid, miner_hk, 1 ) ;
2824+
2825+ assert_eq ! (
2826+ SubtensorModule :: get_stake_for_hotkey_on_subnet( & miner_hk, netuid) ,
2827+ 0 . into( )
2828+ ) ;
2829+
2830+ // Distribute an incentive to the miner hotkey
2831+ let mut incentives: BTreeMap < U256 , AlphaCurrency > = BTreeMap :: new ( ) ;
2832+ let incentive: AlphaCurrency = 5_000_000u64 . into ( ) ;
2833+ incentives. insert ( miner_hk, incentive) ;
2834+
2835+ SubtensorModule :: distribute_dividends_and_incentives (
2836+ netuid,
2837+ AlphaCurrency :: ZERO , // owner_cut
2838+ incentives,
2839+ BTreeMap :: new ( ) , // alpha_dividends
2840+ BTreeMap :: new ( ) , // tao_dividends
2841+ ) ;
2842+
2843+ // With no autostake destination, the incentive should be staked to the original hotkey
2844+ assert_eq ! (
2845+ SubtensorModule :: get_stake_for_hotkey_on_subnet( & miner_hk, netuid) ,
2846+ incentive
2847+ ) ;
2848+ } ) ;
2849+ }
0 commit comments