@@ -2823,20 +2823,21 @@ fn test_set_weights_no_parent() {
2823
2823
#[ test]
2824
2824
fn test_childkey_take_drain ( ) {
2825
2825
new_test_ext ( 1 ) . execute_with ( || {
2826
+ let subnet_owner_coldkey = U256 :: from ( 1001 ) ;
2827
+ let subnet_owner_hotkey = U256 :: from ( 1002 ) ;
2826
2828
let coldkey = U256 :: from ( 1 ) ;
2827
2829
let parent = U256 :: from ( 2 ) ;
2828
2830
let child = U256 :: from ( 3 ) ;
2829
2831
let nominator = U256 :: from ( 4 ) ;
2830
- let netuid: u16 = 1 ;
2831
2832
let root_id: u16 = 0 ;
2832
2833
let subnet_tempo = 10 ;
2833
- let hotkey_tempo = 20 ;
2834
2834
let stake = 100_000_000_000 ;
2835
2835
let proportion: u64 = u64:: MAX ;
2836
2836
2837
2837
// Add network, register hotkeys, and setup network parameters
2838
2838
add_network ( root_id, subnet_tempo, 0 ) ;
2839
- add_network ( netuid, subnet_tempo, 0 ) ;
2839
+ let netuid: u16 = add_dynamic_network ( & subnet_owner_hotkey, & subnet_owner_coldkey) ;
2840
+ crate :: Tempo :: < Test > :: set ( netuid, subnet_tempo) ;
2840
2841
register_ok_neuron ( netuid, child, coldkey, 0 ) ;
2841
2842
register_ok_neuron ( netuid, parent, coldkey, 1 ) ;
2842
2843
@@ -2903,13 +2904,6 @@ fn test_childkey_take_drain() {
2903
2904
crate :: Weights :: < Test > :: insert ( root_id, 0 , vec ! [ ( 0 , 0xFFFF ) , ( 1 , 0xFFFF ) ] ) ;
2904
2905
crate :: Weights :: < Test > :: insert ( root_id, 1 , vec ! [ ( 0 , 0xFFFF ) , ( 1 , 0xFFFF ) ] ) ;
2905
2906
2906
- // Prevent further subnet epochs
2907
- crate :: Tempo :: < Test > :: set ( netuid, u16:: MAX ) ;
2908
- crate :: Tempo :: < Test > :: set ( root_id, u16:: MAX ) ;
2909
-
2910
- // Run run_coinbase until PendingHotkeyEmission is drained for both child and parent
2911
- step_block ( ( hotkey_tempo * 2 ) as u16 ) ;
2912
-
2913
2907
// Verify how emission is split between keys
2914
2908
// - Child stake increased by its child key take only (20% * 50% = 10% of total emission)
2915
2909
// - Parent stake increased by 40% of total emission
@@ -2919,21 +2913,9 @@ fn test_childkey_take_drain() {
2919
2913
let nominator_emission = crate :: Stake :: < Test > :: get ( child, nominator) . saturating_sub ( stake) ;
2920
2914
let total_emission = child_emission + parent_emission + nominator_emission;
2921
2915
2922
- assert ! ( is_within_tolerance(
2923
- child_emission,
2924
- total_emission / 10 ,
2925
- 500
2926
- ) ) ;
2927
- assert ! ( is_within_tolerance(
2928
- parent_emission,
2929
- total_emission / 10 * 4 ,
2930
- 500
2931
- ) ) ;
2932
- assert ! ( is_within_tolerance(
2933
- nominator_emission,
2934
- total_emission / 2 ,
2935
- 500
2936
- ) ) ;
2916
+ assert_abs_diff_eq ! ( child_emission, total_emission / 10 , epsilon = 500 ) ;
2917
+ assert_abs_diff_eq ! ( parent_emission, total_emission / 10 * 4 , epsilon = 500 ) ;
2918
+ assert_abs_diff_eq ! ( nominator_emission, total_emission / 2 , epsilon = 500 ) ;
2937
2919
} ) ;
2938
2920
}
2939
2921
@@ -3037,17 +3019,9 @@ fn test_childkey_take_drain_validator_take() {
3037
3019
let nominator_emission = crate :: Stake :: < Test > :: get ( child, nominator) . saturating_sub ( stake) ;
3038
3020
let total_emission = child_emission + parent_emission + nominator_emission;
3039
3021
3040
- assert ! ( is_within_tolerance( child_emission, total_emission / 5 , 500 ) ) ;
3041
- assert ! ( is_within_tolerance(
3042
- parent_emission,
3043
- total_emission / 10 * 4 ,
3044
- 500
3045
- ) ) ;
3046
- assert ! ( is_within_tolerance(
3047
- nominator_emission,
3048
- total_emission / 10 * 4 ,
3049
- 500
3050
- ) ) ;
3022
+ assert_abs_diff_eq ! ( child_emission, total_emission / 5 , epsilon = 500 ) ;
3023
+ assert_abs_diff_eq ! ( parent_emission, total_emission / 10 * 4 , epsilon = 500 ) ;
3024
+ assert_abs_diff_eq ! ( nominator_emission, total_emission / 10 * 4 , epsilon = 500 ) ;
3051
3025
} ) ;
3052
3026
}
3053
3027
0 commit comments