@@ -2219,6 +2219,67 @@ fn test_remove_stake_fee_goes_to_subnet_tao() {
2219
2219
} ) ;
2220
2220
}
2221
2221
2222
+ // cargo test --package pallet-subtensor --lib -- tests::staking::test_add_stake_fee_equals_dividends --exact --show-output --nocapture
2223
+ #[ test]
2224
+ fn test_add_stake_fee_equals_dividends ( ) {
2225
+ new_test_ext ( 1 ) . execute_with ( || {
2226
+ let subnet_owner_coldkey = U256 :: from ( 1001 ) ;
2227
+ let subnet_owner_hotkey = U256 :: from ( 1002 ) ;
2228
+ let hotkey = U256 :: from ( 2 ) ;
2229
+ let coldkey = U256 :: from ( 3 ) ;
2230
+ let tao_to_stake = DefaultMinStake :: < Test > :: get ( ) * 10_000 ;
2231
+
2232
+ let netuid = add_dynamic_network ( & subnet_owner_hotkey, & subnet_owner_coldkey) ;
2233
+ SubtensorModule :: create_account_if_non_existent ( & coldkey, & hotkey) ;
2234
+
2235
+ // Add stake first time to init TotalHotkeyAlpha
2236
+ SubtensorModule :: add_balance_to_coldkey_account (
2237
+ & coldkey,
2238
+ 2 * ( tao_to_stake + ExistentialDeposit :: get ( ) ) ,
2239
+ ) ;
2240
+ assert_ok ! ( SubtensorModule :: add_stake(
2241
+ RuntimeOrigin :: signed( coldkey) ,
2242
+ hotkey,
2243
+ netuid,
2244
+ tao_to_stake
2245
+ ) ) ;
2246
+
2247
+ // Mock 0.001 per alpha dividends
2248
+ AlphaDividendsPerSubnet :: < Test > :: insert (
2249
+ netuid,
2250
+ hotkey,
2251
+ TotalHotkeyAlpha :: < Test > :: get ( hotkey, netuid) / 1000 ,
2252
+ ) ;
2253
+
2254
+ // Mock price to be 1 and a lot of liquidity
2255
+ let tao_reserve: U96F32 = U96F32 :: from_num ( 100_000_000_000_000_u64 ) ;
2256
+ let alpha_in: U96F32 = U96F32 :: from_num ( 100_000_000_000_000_u64 ) ;
2257
+ SubnetTAO :: < Test > :: insert ( netuid, tao_reserve. to_num :: < u64 > ( ) ) ;
2258
+ SubnetAlphaIn :: < Test > :: insert ( netuid, alpha_in. to_num :: < u64 > ( ) ) ;
2259
+
2260
+ // Add stake again to measure fee
2261
+ let alpha_before =
2262
+ SubtensorModule :: get_stake_for_hotkey_and_coldkey_on_subnet ( & hotkey, & coldkey, netuid) ;
2263
+ assert_ok ! ( SubtensorModule :: add_stake(
2264
+ RuntimeOrigin :: signed( coldkey) ,
2265
+ hotkey,
2266
+ netuid,
2267
+ tao_to_stake
2268
+ ) ) ;
2269
+
2270
+ // Calculate expected fee
2271
+ let expected_alpha_no_fee = tao_to_stake;
2272
+ let alpha_after =
2273
+ SubtensorModule :: get_stake_for_hotkey_and_coldkey_on_subnet ( & hotkey, & coldkey, netuid) ;
2274
+
2275
+ let actual_fee = expected_alpha_no_fee - ( alpha_after - alpha_before) ;
2276
+ let expected_fee =
2277
+ ( expected_alpha_no_fee as f64 * 0.001 * Tempo :: < Test > :: get ( netuid) as f64 ) as u64 ;
2278
+
2279
+ assert_abs_diff_eq ! ( actual_fee, expected_fee, epsilon = expected_fee / 1000 ) ;
2280
+ } ) ;
2281
+ }
2282
+
2222
2283
#[ test]
2223
2284
fn test_stake_below_min_validate ( ) {
2224
2285
// Testing the signed extension validate function
0 commit comments