@@ -2822,3 +2822,101 @@ fn test_drain_alpha_childkey_parentkey_with_burn() {
28222822 ) ;
28232823 } ) ;
28242824}
2825+
2826+ #[ test]
2827+ fn test_incentive_is_autostaked_to_owner_destination ( ) {
2828+ new_test_ext ( 1 ) . execute_with ( || {
2829+ let subnet_owner_ck = U256 :: from ( 0 ) ;
2830+ let subnet_owner_hk = U256 :: from ( 1 ) ;
2831+
2832+ let miner_ck = U256 :: from ( 10 ) ;
2833+ let miner_hk = U256 :: from ( 11 ) ;
2834+ let dest_hk = U256 :: from ( 12 ) ;
2835+
2836+ Owner :: < Test > :: insert ( miner_hk, miner_ck) ;
2837+ Owner :: < Test > :: insert ( dest_hk, miner_ck) ;
2838+ OwnedHotkeys :: < Test > :: insert ( miner_ck, vec ! [ miner_hk, dest_hk] ) ;
2839+
2840+ let netuid = add_dynamic_network ( & subnet_owner_hk, & subnet_owner_ck) ;
2841+
2842+ Uids :: < Test > :: insert ( netuid, miner_hk, 1 ) ;
2843+ Uids :: < Test > :: insert ( netuid, dest_hk, 2 ) ;
2844+
2845+ // Set autostake destination for the miner's coldkey
2846+ AutoStakeDestination :: < Test > :: insert ( miner_ck, dest_hk) ;
2847+
2848+ assert_eq ! (
2849+ SubtensorModule :: get_stake_for_hotkey_on_subnet( & miner_hk, netuid) ,
2850+ 0 . into( )
2851+ ) ;
2852+ assert_eq ! (
2853+ SubtensorModule :: get_stake_for_hotkey_on_subnet( & dest_hk, netuid) ,
2854+ 0 . into( )
2855+ ) ;
2856+
2857+ // Distribute an incentive to the miner hotkey
2858+ let mut incentives: BTreeMap < U256 , AlphaCurrency > = BTreeMap :: new ( ) ;
2859+ let incentive: AlphaCurrency = 10_000_000u64 . into ( ) ;
2860+ incentives. insert ( miner_hk, incentive) ;
2861+
2862+ SubtensorModule :: distribute_dividends_and_incentives (
2863+ netuid,
2864+ AlphaCurrency :: ZERO , // owner_cut
2865+ incentives,
2866+ BTreeMap :: new ( ) , // alpha_dividends
2867+ BTreeMap :: new ( ) , // tao_dividends
2868+ ) ;
2869+
2870+ // Expect the stake to land on the destination hotkey (not the original miner hotkey)
2871+ assert_eq ! (
2872+ SubtensorModule :: get_stake_for_hotkey_on_subnet( & miner_hk, netuid) ,
2873+ 0 . into( )
2874+ ) ;
2875+ assert_eq ! (
2876+ SubtensorModule :: get_stake_for_hotkey_on_subnet( & dest_hk, netuid) ,
2877+ incentive
2878+ ) ;
2879+ } ) ;
2880+ }
2881+
2882+ #[ test]
2883+ fn test_incentive_goes_to_hotkey_when_no_autostake_destination ( ) {
2884+ new_test_ext ( 1 ) . execute_with ( || {
2885+ let subnet_owner_ck = U256 :: from ( 0 ) ;
2886+ let subnet_owner_hk = U256 :: from ( 1 ) ;
2887+
2888+ let miner_ck = U256 :: from ( 20 ) ;
2889+ let miner_hk = U256 :: from ( 21 ) ;
2890+
2891+ Owner :: < Test > :: insert ( miner_hk, miner_ck) ;
2892+ OwnedHotkeys :: < Test > :: insert ( miner_ck, vec ! [ miner_hk] ) ;
2893+
2894+ let netuid = add_dynamic_network ( & subnet_owner_hk, & subnet_owner_ck) ;
2895+
2896+ Uids :: < Test > :: insert ( netuid, miner_hk, 1 ) ;
2897+
2898+ assert_eq ! (
2899+ SubtensorModule :: get_stake_for_hotkey_on_subnet( & miner_hk, netuid) ,
2900+ 0 . into( )
2901+ ) ;
2902+
2903+ // Distribute an incentive to the miner hotkey
2904+ let mut incentives: BTreeMap < U256 , AlphaCurrency > = BTreeMap :: new ( ) ;
2905+ let incentive: AlphaCurrency = 5_000_000u64 . into ( ) ;
2906+ incentives. insert ( miner_hk, incentive) ;
2907+
2908+ SubtensorModule :: distribute_dividends_and_incentives (
2909+ netuid,
2910+ AlphaCurrency :: ZERO , // owner_cut
2911+ incentives,
2912+ BTreeMap :: new ( ) , // alpha_dividends
2913+ BTreeMap :: new ( ) , // tao_dividends
2914+ ) ;
2915+
2916+ // With no autostake destination, the incentive should be staked to the original hotkey
2917+ assert_eq ! (
2918+ SubtensorModule :: get_stake_for_hotkey_on_subnet( & miner_hk, netuid) ,
2919+ incentive
2920+ ) ;
2921+ } ) ;
2922+ }
0 commit comments