@@ -1554,18 +1554,20 @@ fn test_set_network_max_stake_update() {
1554
1554
#[ test]
1555
1555
fn test_children_stake_values ( ) {
1556
1556
new_test_ext ( 1 ) . execute_with ( || {
1557
+ let subnet_owner_coldkey = U256 :: from ( 1001 ) ;
1558
+ let subnet_owner_hotkey = U256 :: from ( 1002 ) ;
1559
+ let netuid: u16 = add_dynamic_network ( & subnet_owner_hotkey, & subnet_owner_coldkey) ;
1560
+
1557
1561
let coldkey = U256 :: from ( 1 ) ;
1558
1562
let hotkey = U256 :: from ( 2 ) ;
1559
1563
let child1 = U256 :: from ( 3 ) ;
1560
1564
let child2 = U256 :: from ( 4 ) ;
1561
1565
let child3 = U256 :: from ( 5 ) ;
1562
- let netuid: u16 = 1 ;
1563
1566
let proportion1: u64 = u64:: MAX / 4 ;
1564
1567
let proportion2: u64 = u64:: MAX / 4 ;
1565
1568
let proportion3: u64 = u64:: MAX / 4 ;
1566
1569
1567
1570
// Add network and register hotkey
1568
- add_network ( netuid, 13 , 0 ) ;
1569
1571
SubtensorModule :: set_max_registrations_per_block ( netuid, 4 ) ;
1570
1572
SubtensorModule :: set_target_registrations_per_interval ( netuid, 4 ) ;
1571
1573
register_ok_neuron ( netuid, hotkey, coldkey, 0 ) ;
@@ -1580,10 +1582,9 @@ fn test_children_stake_values() {
1580
1582
) ;
1581
1583
1582
1584
// Set multiple children with proportions.
1583
- mock_set_children (
1584
- & coldkey,
1585
- & hotkey,
1585
+ mock_set_children_no_epochs (
1586
1586
netuid,
1587
+ & hotkey,
1587
1588
& [
1588
1589
( proportion1, child1) ,
1589
1590
( proportion2, child2) ,
@@ -1830,28 +1831,28 @@ fn test_get_stake_for_hotkey_on_subnet_multiple_coldkeys() {
1830
1831
#[ test]
1831
1832
fn test_get_stake_for_hotkey_on_subnet_single_parent_child ( ) {
1832
1833
new_test_ext ( 1 ) . execute_with ( || {
1833
- let netuid: u16 = 1 ;
1834
+ let subnet_owner_coldkey = U256 :: from ( 1001 ) ;
1835
+ let subnet_owner_hotkey = U256 :: from ( 1002 ) ;
1834
1836
let parent = U256 :: from ( 1 ) ;
1835
1837
let child = U256 :: from ( 2 ) ;
1836
1838
let coldkey = U256 :: from ( 3 ) ;
1837
-
1838
- add_network ( netuid, 1 , 0 ) ;
1839
+ let netuid: u16 = add_dynamic_network ( & subnet_owner_hotkey, & subnet_owner_coldkey) ;
1839
1840
register_ok_neuron ( netuid, parent, coldkey, 0 ) ;
1840
1841
register_ok_neuron ( netuid, child, coldkey, 0 ) ;
1841
1842
1842
1843
SubtensorModule :: increase_stake_for_hotkey_and_coldkey_on_subnet (
1843
- & parent, & coldkey, netuid, 1000 ,
1844
+ & parent, & coldkey, netuid, 1_000_000_000 ,
1844
1845
) ;
1845
1846
1846
- mock_set_children ( & coldkey , & parent, netuid , & [ ( u64:: MAX , child) ] ) ;
1847
+ mock_set_children_no_epochs ( netuid , & parent, & [ ( u64:: MAX , child) ] ) ;
1847
1848
1848
1849
assert_eq ! (
1849
1850
SubtensorModule :: get_inherited_for_hotkey_on_subnet( & parent, netuid) ,
1850
1851
0
1851
1852
) ;
1852
1853
assert_eq ! (
1853
1854
SubtensorModule :: get_inherited_for_hotkey_on_subnet( & child, netuid) ,
1854
- 1000
1855
+ 1_000_000_000
1855
1856
) ;
1856
1857
} ) ;
1857
1858
}
@@ -1867,13 +1868,15 @@ fn test_get_stake_for_hotkey_on_subnet_single_parent_child() {
1867
1868
#[ test]
1868
1869
fn test_get_stake_for_hotkey_on_subnet_multiple_parents_single_child ( ) {
1869
1870
new_test_ext ( 1 ) . execute_with ( || {
1870
- let netuid: u16 = 1 ;
1871
+ let subnet_owner_coldkey = U256 :: from ( 1001 ) ;
1872
+ let subnet_owner_hotkey = U256 :: from ( 1002 ) ;
1873
+ let netuid: u16 = add_dynamic_network ( & subnet_owner_hotkey, & subnet_owner_coldkey) ;
1874
+
1871
1875
let parent1 = U256 :: from ( 1 ) ;
1872
1876
let parent2 = U256 :: from ( 2 ) ;
1873
1877
let child = U256 :: from ( 3 ) ;
1874
1878
let coldkey = U256 :: from ( 4 ) ;
1875
1879
1876
- add_network ( netuid, 1 , 0 ) ;
1877
1880
register_ok_neuron ( netuid, parent1, coldkey, 0 ) ;
1878
1881
register_ok_neuron ( netuid, parent2, coldkey, 0 ) ;
1879
1882
register_ok_neuron ( netuid, child, coldkey, 0 ) ;
@@ -1885,8 +1888,8 @@ fn test_get_stake_for_hotkey_on_subnet_multiple_parents_single_child() {
1885
1888
& parent2, & coldkey, netuid, 2000 ,
1886
1889
) ;
1887
1890
1888
- mock_set_children ( & coldkey , & parent1, netuid , & [ ( u64:: MAX / 2 , child) ] ) ;
1889
- mock_set_children ( & coldkey , & parent2, netuid , & [ ( u64:: MAX / 2 , child) ] ) ;
1891
+ mock_set_children_no_epochs ( netuid , & parent1, & [ ( u64:: MAX / 2 , child) ] ) ;
1892
+ mock_set_children_no_epochs ( netuid , & parent2, & [ ( u64:: MAX / 2 , child) ] ) ;
1890
1893
1891
1894
close (
1892
1895
SubtensorModule :: get_inherited_for_hotkey_on_subnet ( & parent1, netuid) ,
@@ -1920,13 +1923,15 @@ fn test_get_stake_for_hotkey_on_subnet_multiple_parents_single_child() {
1920
1923
#[ test]
1921
1924
fn test_get_stake_for_hotkey_on_subnet_single_parent_multiple_children ( ) {
1922
1925
new_test_ext ( 1 ) . execute_with ( || {
1923
- let netuid: u16 = 1 ;
1926
+ let subnet_owner_coldkey = U256 :: from ( 1001 ) ;
1927
+ let subnet_owner_hotkey = U256 :: from ( 1002 ) ;
1928
+ let netuid: u16 = add_dynamic_network ( & subnet_owner_hotkey, & subnet_owner_coldkey) ;
1929
+
1924
1930
let parent = U256 :: from ( 1 ) ;
1925
1931
let child1 = U256 :: from ( 2 ) ;
1926
1932
let child2 = U256 :: from ( 3 ) ;
1927
1933
let coldkey = U256 :: from ( 4 ) ;
1928
1934
1929
- add_network ( netuid, 1 , 0 ) ;
1930
1935
register_ok_neuron ( netuid, parent, coldkey, 0 ) ;
1931
1936
register_ok_neuron ( netuid, child1, coldkey, 0 ) ;
1932
1937
register_ok_neuron ( netuid, child2, coldkey, 0 ) ;
@@ -1939,10 +1944,9 @@ fn test_get_stake_for_hotkey_on_subnet_single_parent_multiple_children() {
1939
1944
total_stake,
1940
1945
) ;
1941
1946
1942
- mock_set_children (
1943
- & coldkey,
1944
- & parent,
1947
+ mock_set_children_no_epochs (
1945
1948
netuid,
1949
+ & parent,
1946
1950
& [ ( u64:: MAX / 3 , child1) , ( u64:: MAX / 3 , child2) ] ,
1947
1951
) ;
1948
1952
@@ -1983,13 +1987,15 @@ fn test_get_stake_for_hotkey_on_subnet_single_parent_multiple_children() {
1983
1987
#[ test]
1984
1988
fn test_get_stake_for_hotkey_on_subnet_edge_cases ( ) {
1985
1989
new_test_ext ( 1 ) . execute_with ( || {
1986
- let netuid: u16 = 1 ;
1990
+ let subnet_owner_coldkey = U256 :: from ( 1001 ) ;
1991
+ let subnet_owner_hotkey = U256 :: from ( 1002 ) ;
1992
+ let netuid: u16 = add_dynamic_network ( & subnet_owner_hotkey, & subnet_owner_coldkey) ;
1993
+
1987
1994
let parent = U256 :: from ( 1 ) ;
1988
1995
let child1 = U256 :: from ( 2 ) ;
1989
1996
let child2 = U256 :: from ( 3 ) ;
1990
1997
let coldkey = U256 :: from ( 4 ) ;
1991
1998
1992
- add_network ( netuid, 1 , 0 ) ;
1993
1999
register_ok_neuron ( netuid, parent, coldkey, 0 ) ;
1994
2000
register_ok_neuron ( netuid, child1, coldkey, 0 ) ;
1995
2001
register_ok_neuron ( netuid, child2, coldkey, 0 ) ;
@@ -2007,10 +2013,9 @@ fn test_get_stake_for_hotkey_on_subnet_edge_cases() {
2007
2013
) ;
2008
2014
2009
2015
// Test with 0% and 100% stake allocation
2010
- mock_set_children (
2011
- & coldkey,
2012
- & parent,
2016
+ mock_set_children_no_epochs (
2013
2017
netuid,
2018
+ & parent,
2014
2019
& [ ( 0 , child1) , ( u64:: MAX , child2) ] ,
2015
2020
) ;
2016
2021
@@ -2051,7 +2056,10 @@ fn test_get_stake_for_hotkey_on_subnet_edge_cases() {
2051
2056
#[ test]
2052
2057
fn test_get_stake_for_hotkey_on_subnet_complex_hierarchy ( ) {
2053
2058
new_test_ext ( 1 ) . execute_with ( || {
2054
- let netuid: u16 = 1 ;
2059
+ let subnet_owner_coldkey = U256 :: from ( 1001 ) ;
2060
+ let subnet_owner_hotkey = U256 :: from ( 1002 ) ;
2061
+ let netuid: u16 = add_dynamic_network ( & subnet_owner_hotkey, & subnet_owner_coldkey) ;
2062
+
2055
2063
let parent = U256 :: from ( 1 ) ;
2056
2064
let child1 = U256 :: from ( 2 ) ;
2057
2065
let child2 = U256 :: from ( 3 ) ;
@@ -2061,7 +2069,6 @@ fn test_get_stake_for_hotkey_on_subnet_complex_hierarchy() {
2061
2069
let coldkey_child2 = U256 :: from ( 7 ) ;
2062
2070
let coldkey_grandchild = U256 :: from ( 8 ) ;
2063
2071
2064
- add_network ( netuid, 1 , 0 ) ;
2065
2072
SubtensorModule :: set_max_registrations_per_block ( netuid, 1000 ) ;
2066
2073
SubtensorModule :: set_target_registrations_per_interval ( netuid, 1000 ) ;
2067
2074
register_ok_neuron ( netuid, parent, coldkey_parent, 0 ) ;
@@ -2096,10 +2103,9 @@ fn test_get_stake_for_hotkey_on_subnet_complex_hierarchy() {
2096
2103
) ;
2097
2104
2098
2105
// Step 1: Set children for parent
2099
- mock_set_children (
2100
- & coldkey_parent,
2101
- & parent,
2106
+ mock_set_children_no_epochs (
2102
2107
netuid,
2108
+ & parent,
2103
2109
& [ ( u64:: MAX / 2 , child1) , ( u64:: MAX / 2 , child2) ] ,
2104
2110
) ;
2105
2111
@@ -2133,7 +2139,7 @@ fn test_get_stake_for_hotkey_on_subnet_complex_hierarchy() {
2133
2139
close ( child2_stake_1, 499 , 10 , "Child2 should have 499 stake" ) ;
2134
2140
2135
2141
// Step 2: Set children for child1
2136
- mock_set_children ( & coldkey_child1 , & child1, netuid , & [ ( u64:: MAX , grandchild) ] ) ;
2142
+ mock_set_children_no_epochs ( netuid , & child1, & [ ( u64:: MAX , grandchild) ] ) ;
2137
2143
2138
2144
log:: info!( "After setting child1's children:" ) ;
2139
2145
log:: info!(
@@ -2810,8 +2816,9 @@ fn test_childkey_set_weights_single_parent() {
2810
2816
fn test_set_weights_no_parent ( ) {
2811
2817
// Verify that a regular key without a parent delegation is effected by the minimum stake requirements
2812
2818
new_test_ext ( 1 ) . execute_with ( || {
2813
- let netuid: u16 = 1 ;
2814
- add_network ( netuid, 1 , 0 ) ;
2819
+ let subnet_owner_coldkey = U256 :: from ( 1001 ) ;
2820
+ let subnet_owner_hotkey = U256 :: from ( 1002 ) ;
2821
+ let netuid: u16 = add_dynamic_network ( & subnet_owner_hotkey, & subnet_owner_coldkey) ;
2815
2822
2816
2823
let hotkey: U256 = U256 :: from ( 2 ) ;
2817
2824
let spare_hk: U256 = U256 :: from ( 3 ) ;
@@ -3108,8 +3115,15 @@ fn test_childkey_take_drain_validator_take() {
3108
3115
#[ test]
3109
3116
fn test_parent_child_chain_emission ( ) {
3110
3117
new_test_ext ( 1 ) . execute_with ( || {
3111
- let netuid: u16 = 1 ;
3112
- add_network ( netuid, 1 , 0 ) ;
3118
+ let subnet_owner_coldkey = U256 :: from ( 1001 ) ;
3119
+ let subnet_owner_hotkey = U256 :: from ( 1002 ) ;
3120
+ let netuid: u16 = add_dynamic_network ( & subnet_owner_hotkey, & subnet_owner_coldkey) ;
3121
+ Tempo :: < Test > :: insert ( netuid, 1 ) ;
3122
+
3123
+ // Setup large LPs to prevent slippage
3124
+ SubnetTAO :: < Test > :: insert ( netuid, 1_000_000_000_000_000 ) ;
3125
+ SubnetAlphaIn :: < Test > :: insert ( netuid, 1_000_000_000_000_000 ) ;
3126
+
3113
3127
// Set owner cut to 0
3114
3128
SubtensorModule :: set_subnet_owner_cut ( 0_u16 ) ;
3115
3129
@@ -3132,7 +3146,10 @@ fn test_parent_child_chain_emission() {
3132
3146
SubtensorModule :: add_balance_to_coldkey_account ( & coldkey_c, 1_000 ) ;
3133
3147
3134
3148
// Swap to alpha
3135
- let total_tao: I96F32 = I96F32 :: from_num ( 300_000 + 100_000 + 50_000 ) ;
3149
+ let stake_a = 300_000_000_000_u64 ;
3150
+ let stake_b = 100_000_000_000_u64 ;
3151
+ let stake_c = 50_000_000_000_u64 ;
3152
+ let total_tao: I96F32 = I96F32 :: from_num ( stake_a + stake_b + stake_c) ;
3136
3153
let total_alpha: I96F32 = I96F32 :: from_num ( SubtensorModule :: swap_tao_for_alpha (
3137
3154
netuid,
3138
3155
total_tao. to_num :: < u64 > ( ) ,
@@ -3144,19 +3161,19 @@ fn test_parent_child_chain_emission() {
3144
3161
& hotkey_a,
3145
3162
& coldkey_a,
3146
3163
netuid,
3147
- ( total_alpha * I96F32 :: from_num ( 300_000 ) / total_tao) . saturating_to_num :: < u64 > ( ) ,
3164
+ ( total_alpha * I96F32 :: from_num ( stake_a ) / total_tao) . saturating_to_num :: < u64 > ( ) ,
3148
3165
) ;
3149
3166
SubtensorModule :: increase_stake_for_hotkey_and_coldkey_on_subnet (
3150
3167
& hotkey_b,
3151
3168
& coldkey_b,
3152
3169
netuid,
3153
- ( total_alpha * I96F32 :: from_num ( 100_000 ) / total_tao) . saturating_to_num :: < u64 > ( ) ,
3170
+ ( total_alpha * I96F32 :: from_num ( stake_b ) / total_tao) . saturating_to_num :: < u64 > ( ) ,
3154
3171
) ;
3155
3172
SubtensorModule :: increase_stake_for_hotkey_and_coldkey_on_subnet (
3156
3173
& hotkey_c,
3157
3174
& coldkey_c,
3158
3175
netuid,
3159
- ( total_alpha * I96F32 :: from_num ( 50_000 ) / total_tao) . saturating_to_num :: < u64 > ( ) ,
3176
+ ( total_alpha * I96F32 :: from_num ( stake_c ) / total_tao) . saturating_to_num :: < u64 > ( ) ,
3160
3177
) ;
3161
3178
3162
3179
// Get old stakes
@@ -3174,24 +3191,33 @@ fn test_parent_child_chain_emission() {
3174
3191
log:: info!( "rel_stake_a: {:?}" , rel_stake_a) ; // 0.6666 -> 2/3
3175
3192
log:: info!( "rel_stake_b: {:?}" , rel_stake_b) ; // 0.2222 -> 2/9
3176
3193
log:: info!( "rel_stake_c: {:?}" , rel_stake_c) ; // 0.1111 -> 1/9
3177
- assert_eq ! ( rel_stake_a, I96F32 :: from_num( 300_000 ) / total_tao) ;
3178
- assert_eq ! ( rel_stake_b, I96F32 :: from_num( 100_000 ) / total_tao) ;
3179
- assert_eq ! ( rel_stake_c, I96F32 :: from_num( 50_000 ) / total_tao) ;
3194
+ assert ! (
3195
+ ( rel_stake_a - I96F32 :: from_num( stake_a) / total_tao) . abs( ) < 0.001
3196
+ ) ;
3197
+ assert ! (
3198
+ ( rel_stake_b - I96F32 :: from_num( stake_b) / total_tao) . abs( ) < 0.001
3199
+ ) ;
3200
+ assert ! (
3201
+ ( rel_stake_c - I96F32 :: from_num( stake_c) / total_tao) . abs( ) < 0.001
3202
+ ) ;
3180
3203
3181
3204
// Set parent-child relationships
3182
3205
// A -> B (50% of A's stake)
3183
- mock_schedule_children ( & coldkey_a , & hotkey_a, netuid , & [ ( u64:: MAX / 2 , hotkey_b) ] ) ;
3206
+ mock_set_children_no_epochs ( netuid , & hotkey_a, & [ ( u64:: MAX / 2 , hotkey_b) ] ) ;
3184
3207
3185
3208
// B -> C (50% of B's stake)
3186
- mock_schedule_children ( & coldkey_b, & hotkey_b, netuid, & [ ( u64:: MAX / 2 , hotkey_c) ] ) ;
3187
- wait_and_set_pending_children ( netuid) ; // Don't want to run blocks before both children are scheduled
3209
+ mock_set_children_no_epochs ( netuid, & hotkey_b, & [ ( u64:: MAX / 2 , hotkey_c) ] ) ;
3188
3210
3189
3211
// Get old stakes after children are scheduled
3190
3212
let stake_a_old: u64 = SubtensorModule :: get_total_stake_for_hotkey ( & hotkey_a) ;
3191
3213
let stake_b_old: u64 = SubtensorModule :: get_total_stake_for_hotkey ( & hotkey_b) ;
3192
3214
let stake_c_old: u64 = SubtensorModule :: get_total_stake_for_hotkey ( & hotkey_c) ;
3193
3215
3194
3216
let total_stake_old: I96F32 = I96F32 :: from_num ( stake_a_old + stake_b_old + stake_c_old) ;
3217
+ log:: info!( "Old stake for hotkey A: {:?}" , stake_a_old) ;
3218
+ log:: info!( "Old stake for hotkey B: {:?}" , stake_b_old) ;
3219
+ log:: info!( "Old stake for hotkey C: {:?}" , stake_c_old) ;
3220
+ log:: info!( "Total old stake: {:?}" , total_stake_old) ;
3195
3221
3196
3222
// Set CHK take rate to 1/9
3197
3223
let chk_take: I96F32 = I96F32 :: from_num ( 1_f64 / 9_f64 ) ;
@@ -3203,8 +3229,6 @@ fn test_parent_child_chain_emission() {
3203
3229
SubtensorModule :: set_tao_weight ( 0 ) ;
3204
3230
3205
3231
let hardcoded_emission: I96F32 = I96F32 :: from_num ( 1_000_000 ) ; // 1 million (adjust as needed)
3206
- let emission_as_alpha =
3207
- I96F32 :: from_num ( hardcoded_emission) / SubtensorModule :: get_alpha_price ( netuid) ;
3208
3232
3209
3233
// Set pending emission to 0
3210
3234
PendingEmission :: < Test > :: insert ( netuid, 0 ) ;
@@ -3238,8 +3262,8 @@ fn test_parent_child_chain_emission() {
3238
3262
3239
3263
// Verify the final stake distribution
3240
3264
let stake_inc_eps: I96F32 = I96F32 :: from_num ( 1e-4 ) ; // 4 decimal places
3241
- // Each child has chk_take take
3242
-
3265
+
3266
+ // Each child has chk_take take
3243
3267
let expected_a = I96F32 :: from_num ( 2_f64 / 3_f64 )
3244
3268
* ( I96F32 :: from_num ( 1_f64 ) - ( I96F32 :: from_num ( 1_f64 / 2_f64 ) * chk_take) ) ;
3245
3269
assert ! (
@@ -3289,11 +3313,10 @@ fn test_parent_child_chain_emission() {
3289
3313
total_stake_new
3290
3314
) ;
3291
3315
3292
- let eps: I96F32 = I96F32 :: from_num ( 10_000 ) ;
3293
- assert ! (
3294
- ( total_stake_new - ( total_stake_old + emission_as_alpha) ) . abs( ) <= eps,
3295
- "Total stake should have increased by the hardcoded emission amount {:?}" ,
3296
- total_stake_new - ( total_stake_old + emission_as_alpha)
3316
+ assert_abs_diff_eq ! (
3317
+ total_stake_inc. to_num:: <u64 >( ) ,
3318
+ hardcoded_emission. to_num:: <u64 >( ) ,
3319
+ epsilon = 10_000 ,
3297
3320
) ;
3298
3321
} ) ;
3299
3322
}
0 commit comments