@@ -3058,28 +3058,34 @@ fn test_childkey_multiple_parents_emission() {
3058
3058
3059
3059
// Register neurons and add initial stakes
3060
3060
let initial_stakes: Vec < ( bool , U256 , U256 , u64 ) > = vec ! [
3061
- ( false , coldkey_parent1, parent1, 200_000 ) ,
3062
- ( true , coldkey_parent2, parent2, 150_000 ) ,
3063
- ( true , coldkey_child, child, 20_000 ) ,
3064
- ( true , coldkey_weight_setter, weight_setter, 100_000 ) ,
3061
+ ( false , coldkey_parent1, parent1, 200_000_000 ) ,
3062
+ ( true , coldkey_parent2, parent2, 150_000_000 ) ,
3063
+ ( true , coldkey_child, child, 20_000_000 ) ,
3064
+ ( true , coldkey_weight_setter, weight_setter, 100_000_000 ) ,
3065
3065
] ;
3066
3066
3067
- for ( register, coldkey, hotkey, stake) in initial_stakes. iter ( ) {
3068
- SubtensorModule :: add_balance_to_coldkey_account ( coldkey, * stake) ;
3069
- if * register {
3070
- // Register a neuron
3071
- register_ok_neuron ( netuid, * hotkey, * coldkey, 0 ) ;
3072
- } else {
3073
- // Just create hotkey account
3074
- SubtensorModule :: create_account_if_non_existent ( coldkey, hotkey) ;
3075
- }
3076
- assert_ok ! ( SubtensorModule :: add_stake(
3077
- RuntimeOrigin :: signed( * coldkey) ,
3078
- * hotkey,
3079
- netuid,
3080
- * stake
3081
- ) ) ;
3082
- }
3067
+ let initial_actual_stakes: Vec < u64 > = initial_stakes
3068
+ . iter ( )
3069
+ . map ( |( register, coldkey, hotkey, stake) | {
3070
+ SubtensorModule :: add_balance_to_coldkey_account ( coldkey, * stake) ;
3071
+ if * register {
3072
+ // Register a neuron
3073
+ register_ok_neuron ( netuid, * hotkey, * coldkey, 0 ) ;
3074
+ } else {
3075
+ // Just create hotkey account
3076
+ SubtensorModule :: create_account_if_non_existent ( coldkey, hotkey) ;
3077
+ }
3078
+ assert_ok ! ( SubtensorModule :: add_stake(
3079
+ RuntimeOrigin :: signed( * coldkey) ,
3080
+ * hotkey,
3081
+ netuid,
3082
+ * stake
3083
+ ) ) ;
3084
+
3085
+ // Return actual stake
3086
+ SubtensorModule :: get_stake_for_hotkey_and_coldkey_on_subnet ( hotkey, coldkey, netuid)
3087
+ } )
3088
+ . collect ( ) ;
3083
3089
3084
3090
SubtensorModule :: set_weights_set_rate_limit ( netuid, 0 ) ;
3085
3091
step_block ( 2 ) ;
@@ -3152,23 +3158,26 @@ fn test_childkey_multiple_parents_emission() {
3152
3158
) ;
3153
3159
3154
3160
assert ! (
3155
- parent1_stake > 200_000 ,
3161
+ parent1_stake > initial_actual_stakes [ 0 ] ,
3156
3162
"Parent1 should have received emission"
3157
3163
) ;
3158
3164
assert ! (
3159
- parent2_stake > 150_000 ,
3165
+ parent2_stake > initial_actual_stakes [ 1 ] ,
3160
3166
"Parent2 should have received emission"
3161
3167
) ;
3162
- assert ! ( child_stake > 20_000 , "Child should have received emission" ) ;
3163
3168
assert ! (
3164
- weight_setter_stake > 100_000 ,
3169
+ child_stake > initial_actual_stakes[ 2 ] ,
3170
+ "Child should have received emission"
3171
+ ) ;
3172
+ assert ! (
3173
+ weight_setter_stake > initial_actual_stakes[ 3 ] ,
3165
3174
"Weight setter should have received emission"
3166
3175
) ;
3167
3176
3168
3177
// Check individual stake increases
3169
- let parent1_stake_increase = parent1_stake - 200_000 ;
3170
- let parent2_stake_increase = parent2_stake - 150_000 ;
3171
- let child_stake_increase = child_stake - 20_000 ;
3178
+ let parent1_stake_increase = parent1_stake - initial_actual_stakes [ 0 ] ;
3179
+ let parent2_stake_increase = parent2_stake - initial_actual_stakes [ 1 ] ;
3180
+ let child_stake_increase = child_stake - initial_actual_stakes [ 2 ] ;
3172
3181
3173
3182
log:: debug!(
3174
3183
"Stake increases - Parent1: {}, Parent2: {}, Child: {}" ,
@@ -3192,12 +3201,13 @@ fn test_childkey_multiple_parents_emission() {
3192
3201
) ;
3193
3202
3194
3203
// Check that the total stake has increased by the emission amount
3204
+ // Allow 1% slippage
3195
3205
let total_stake = parent1_stake + parent2_stake + child_stake + weight_setter_stake;
3196
- let initial_total_stake: u64 = initial_stakes . iter ( ) . map ( | ( _ , _ , _ , stake ) | stake ) . sum ( ) ;
3206
+ let initial_total_stake: u64 = initial_actual_stakes . iter ( ) . sum :: < u64 > ( ) ;
3197
3207
assert_abs_diff_eq ! (
3198
3208
total_stake,
3199
- initial_total_stake + total_emission - 2 ,
3200
- epsilon = total_emission / 10_000
3209
+ initial_total_stake + total_emission,
3210
+ epsilon = total_emission / 100
3201
3211
) ;
3202
3212
} ) ;
3203
3213
}
0 commit comments