@@ -1889,3 +1889,245 @@ fn test_drain_pending_emission_no_miners_all_drained() {
1889
1889
assert_abs_diff_eq ! ( new_stake, emission. saturating_add( init_stake) , epsilon = 1 ) ;
1890
1890
} ) ;
1891
1891
}
1892
+
1893
+ #[ test]
1894
+ fn test_drain_pending_emission_zero_emission ( ) {
1895
+ new_test_ext ( 1 ) . execute_with ( || {
1896
+ let netuid = add_dynamic_network ( & U256 :: from ( 1 ) , & U256 :: from ( 2 ) ) ;
1897
+ let hotkey = U256 :: from ( 3 ) ;
1898
+ let coldkey = U256 :: from ( 4 ) ;
1899
+ let miner_hk = U256 :: from ( 5 ) ;
1900
+ let miner_ck = U256 :: from ( 6 ) ;
1901
+ let init_stake: u64 = 100_000_000_000_000 ;
1902
+ let tempo = 2 ;
1903
+ SubtensorModule :: set_tempo ( netuid, tempo) ;
1904
+ // Set weight-set limit to 0.
1905
+ SubtensorModule :: set_weights_set_rate_limit ( netuid, 0 ) ;
1906
+
1907
+ register_ok_neuron ( netuid, hotkey, coldkey, 0 ) ;
1908
+ register_ok_neuron ( netuid, miner_hk, miner_ck, 0 ) ;
1909
+ // Give non-zero stake
1910
+ SubtensorModule :: increase_stake_for_hotkey_and_coldkey_on_subnet (
1911
+ & hotkey, & coldkey, netuid, init_stake,
1912
+ ) ;
1913
+ assert_eq ! (
1914
+ SubtensorModule :: get_total_stake_for_hotkey( & hotkey) ,
1915
+ init_stake
1916
+ ) ;
1917
+
1918
+ // Set the weight of root TAO to be 0%, so only alpha is effective.
1919
+ SubtensorModule :: set_tao_weight ( 0 ) ;
1920
+
1921
+ run_to_block_no_epoch ( netuid, 50 ) ;
1922
+
1923
+ // Run epoch for initial setup.
1924
+ SubtensorModule :: epoch ( netuid, 0 ) ;
1925
+
1926
+ // Set weights on miner
1927
+ assert_ok ! ( SubtensorModule :: set_weights(
1928
+ RuntimeOrigin :: signed( hotkey) ,
1929
+ netuid,
1930
+ vec![ 0 , 1 , 2 ] ,
1931
+ vec![ 0 , 0 , 1 ] ,
1932
+ 0 ,
1933
+ ) ) ;
1934
+
1935
+ run_to_block_no_epoch ( netuid, 50 ) ;
1936
+
1937
+ // Clear incentive and dividends.
1938
+ Incentive :: < Test > :: remove ( netuid) ;
1939
+ Dividends :: < Test > :: remove ( netuid) ;
1940
+
1941
+ // Set the emission to be ZERO.
1942
+ SubtensorModule :: drain_pending_emission ( netuid, 0 , 0 , 0 , 0 ) ;
1943
+
1944
+ // Get the new stake of the hotkey.
1945
+ let new_stake = SubtensorModule :: get_total_stake_for_hotkey ( & hotkey) ;
1946
+ // We expect the stake to remain unchanged.
1947
+ assert_eq ! ( new_stake, init_stake) ;
1948
+
1949
+ // Check that the incentive and dividends are set by epoch.
1950
+ assert ! ( Incentive :: <Test >:: get( netuid) . iter( ) . sum:: <u16 >( ) > 0 ) ;
1951
+ assert ! ( Dividends :: <Test >:: get( netuid) . iter( ) . sum:: <u16 >( ) > 0 ) ;
1952
+ } ) ;
1953
+ }
1954
+
1955
+ #[ test]
1956
+ fn test_run_coinbase_not_started ( ) {
1957
+ new_test_ext ( 1 ) . execute_with ( || {
1958
+ let netuid = 1 ;
1959
+ let tempo = 2 ;
1960
+
1961
+ let sn_owner_hk = U256 :: from ( 7 ) ;
1962
+ let sn_owner_ck = U256 :: from ( 8 ) ;
1963
+
1964
+ add_network_without_emission_block ( netuid, tempo, 0 ) ;
1965
+ assert_eq ! ( FirstEmissionBlockNumber :: <Test >:: get( netuid) , None ) ;
1966
+
1967
+ SubnetOwner :: < Test > :: insert ( netuid, sn_owner_ck) ;
1968
+ SubnetOwnerHotkey :: < Test > :: insert ( netuid, sn_owner_hk) ;
1969
+
1970
+ let hotkey = U256 :: from ( 3 ) ;
1971
+ let coldkey = U256 :: from ( 4 ) ;
1972
+ let miner_hk = U256 :: from ( 5 ) ;
1973
+ let miner_ck = U256 :: from ( 6 ) ;
1974
+ let init_stake: u64 = 100_000_000_000_000 ;
1975
+ let tempo = 2 ;
1976
+ SubtensorModule :: set_tempo ( netuid, tempo) ;
1977
+ // Set weight-set limit to 0.
1978
+ SubtensorModule :: set_weights_set_rate_limit ( netuid, 0 ) ;
1979
+
1980
+ register_ok_neuron ( netuid, hotkey, coldkey, 0 ) ;
1981
+ register_ok_neuron ( netuid, miner_hk, miner_ck, 0 ) ;
1982
+ register_ok_neuron ( netuid, sn_owner_hk, sn_owner_ck, 0 ) ;
1983
+ // Give non-zero stake
1984
+ SubtensorModule :: increase_stake_for_hotkey_and_coldkey_on_subnet (
1985
+ & hotkey, & coldkey, netuid, init_stake,
1986
+ ) ;
1987
+ assert_eq ! (
1988
+ SubtensorModule :: get_total_stake_for_hotkey( & hotkey) ,
1989
+ init_stake
1990
+ ) ;
1991
+
1992
+ // Set the weight of root TAO to be 0%, so only alpha is effective.
1993
+ SubtensorModule :: set_tao_weight ( 0 ) ;
1994
+
1995
+ run_to_block_no_epoch ( netuid, 30 ) ;
1996
+
1997
+ // Run epoch for initial setup.
1998
+ SubtensorModule :: epoch ( netuid, 0 ) ;
1999
+
2000
+ // Set weights on miner
2001
+ assert_ok ! ( SubtensorModule :: set_weights(
2002
+ RuntimeOrigin :: signed( hotkey) ,
2003
+ netuid,
2004
+ vec![ 0 , 1 , 2 ] ,
2005
+ vec![ 0 , 0 , 1 ] ,
2006
+ 0 ,
2007
+ ) ) ;
2008
+
2009
+ // Clear incentive and dividends.
2010
+ Incentive :: < Test > :: remove ( netuid) ;
2011
+ Dividends :: < Test > :: remove ( netuid) ;
2012
+
2013
+ // Step so tempo should run.
2014
+ next_block_no_epoch ( netuid) ;
2015
+ next_block_no_epoch ( netuid) ;
2016
+ next_block_no_epoch ( netuid) ;
2017
+ let current_block = System :: block_number ( ) ;
2018
+ assert ! ( SubtensorModule :: should_run_epoch( netuid, current_block) ) ;
2019
+
2020
+ // Run coinbase with emission.
2021
+ SubtensorModule :: run_coinbase ( I96F32 :: saturating_from_num ( 100_000_000 ) ) ;
2022
+
2023
+ // We expect that the epoch ran.
2024
+ assert_eq ! ( BlocksSinceLastStep :: <Test >:: get( netuid) , 0 ) ;
2025
+
2026
+ // Get the new stake of the hotkey. We expect no emissions.
2027
+ let new_stake = SubtensorModule :: get_total_stake_for_hotkey ( & hotkey) ;
2028
+ // We expect the stake to remain unchanged.
2029
+ assert_eq ! ( new_stake, init_stake) ;
2030
+
2031
+ // Check that the incentive and dividends are set.
2032
+ assert ! ( Incentive :: <Test >:: get( netuid) . iter( ) . sum:: <u16 >( ) > 0 ) ;
2033
+ assert ! ( Dividends :: <Test >:: get( netuid) . iter( ) . sum:: <u16 >( ) > 0 ) ;
2034
+ } ) ;
2035
+ }
2036
+
2037
+ #[ test]
2038
+ fn test_run_coinbase_not_started_start_after ( ) {
2039
+ new_test_ext ( 1 ) . execute_with ( || {
2040
+ let netuid = 1 ;
2041
+ let tempo = 2 ;
2042
+
2043
+ let sn_owner_hk = U256 :: from ( 7 ) ;
2044
+ let sn_owner_ck = U256 :: from ( 8 ) ;
2045
+
2046
+ add_network_without_emission_block ( netuid, tempo, 0 ) ;
2047
+ assert_eq ! ( FirstEmissionBlockNumber :: <Test >:: get( netuid) , None ) ;
2048
+
2049
+ SubnetOwner :: < Test > :: insert ( netuid, sn_owner_ck) ;
2050
+ SubnetOwnerHotkey :: < Test > :: insert ( netuid, sn_owner_hk) ;
2051
+
2052
+ let hotkey = U256 :: from ( 3 ) ;
2053
+ let coldkey = U256 :: from ( 4 ) ;
2054
+ let miner_hk = U256 :: from ( 5 ) ;
2055
+ let miner_ck = U256 :: from ( 6 ) ;
2056
+ let init_stake: u64 = 100_000_000_000_000 ;
2057
+ let tempo = 2 ;
2058
+ SubtensorModule :: set_tempo ( netuid, tempo) ;
2059
+ // Set weight-set limit to 0.
2060
+ SubtensorModule :: set_weights_set_rate_limit ( netuid, 0 ) ;
2061
+
2062
+ register_ok_neuron ( netuid, hotkey, coldkey, 0 ) ;
2063
+ register_ok_neuron ( netuid, miner_hk, miner_ck, 0 ) ;
2064
+ register_ok_neuron ( netuid, sn_owner_hk, sn_owner_ck, 0 ) ;
2065
+ // Give non-zero stake
2066
+ SubtensorModule :: increase_stake_for_hotkey_and_coldkey_on_subnet (
2067
+ & hotkey, & coldkey, netuid, init_stake,
2068
+ ) ;
2069
+ assert_eq ! (
2070
+ SubtensorModule :: get_total_stake_for_hotkey( & hotkey) ,
2071
+ init_stake
2072
+ ) ;
2073
+
2074
+ // Set the weight of root TAO to be 0%, so only alpha is effective.
2075
+ SubtensorModule :: set_tao_weight ( 0 ) ;
2076
+
2077
+ run_to_block_no_epoch ( netuid, 30 ) ;
2078
+
2079
+ // Run epoch for initial setup.
2080
+ SubtensorModule :: epoch ( netuid, 0 ) ;
2081
+
2082
+ // Set weights on miner
2083
+ assert_ok ! ( SubtensorModule :: set_weights(
2084
+ RuntimeOrigin :: signed( hotkey) ,
2085
+ netuid,
2086
+ vec![ 0 , 1 , 2 ] ,
2087
+ vec![ 0 , 0 , 1 ] ,
2088
+ 0 ,
2089
+ ) ) ;
2090
+
2091
+ // Clear incentive and dividends.
2092
+ Incentive :: < Test > :: remove ( netuid) ;
2093
+ Dividends :: < Test > :: remove ( netuid) ;
2094
+
2095
+ // Step so tempo should run.
2096
+ next_block_no_epoch ( netuid) ;
2097
+ next_block_no_epoch ( netuid) ;
2098
+ next_block_no_epoch ( netuid) ;
2099
+ let current_block = System :: block_number ( ) ;
2100
+ assert ! ( SubtensorModule :: should_run_epoch( netuid, current_block) ) ;
2101
+
2102
+ // Run coinbase with emission.
2103
+ SubtensorModule :: run_coinbase ( I96F32 :: saturating_from_num ( 100_000_000 ) ) ;
2104
+ // We expect that the epoch ran.
2105
+ assert_eq ! ( BlocksSinceLastStep :: <Test >:: get( netuid) , 0 ) ;
2106
+
2107
+ let block_number = DurationOfStartCall :: get ( ) ;
2108
+ run_to_block_no_epoch ( netuid, block_number) ;
2109
+
2110
+ let current_block = System :: block_number ( ) ;
2111
+
2112
+ // Run start call.
2113
+ assert_ok ! ( SubtensorModule :: start_call(
2114
+ RuntimeOrigin :: signed( sn_owner_ck) ,
2115
+ netuid
2116
+ ) ) ;
2117
+ assert_eq ! (
2118
+ FirstEmissionBlockNumber :: <Test >:: get( netuid) ,
2119
+ Some ( current_block + 1 )
2120
+ ) ;
2121
+
2122
+ // Run coinbase with emission.
2123
+ SubtensorModule :: run_coinbase ( I96F32 :: saturating_from_num ( 100_000_000 ) ) ;
2124
+ // We expect that the epoch ran.
2125
+ assert_eq ! ( BlocksSinceLastStep :: <Test >:: get( netuid) , 0 ) ;
2126
+
2127
+ // Get the new stake of the hotkey. We expect no emissions.
2128
+ let new_stake = SubtensorModule :: get_total_stake_for_hotkey ( & hotkey) ;
2129
+ // We expect the stake to remain unchanged.
2130
+ assert ! ( new_stake > init_stake) ;
2131
+ log:: info!( "new_stake: {}" , new_stake) ;
2132
+ } ) ;
2133
+ }
0 commit comments