@@ -3,6 +3,7 @@ use crate::*;
3
3
use approx:: assert_abs_diff_eq;
4
4
use frame_support:: { assert_err, assert_noop, assert_ok} ;
5
5
use sp_core:: { Get , U256 } ;
6
+ use substrate_fixed:: types:: I96F32 ;
6
7
7
8
// 1. test_do_move_success
8
9
// Description: Test a successful move of stake between two hotkeys in the same subnet
@@ -111,14 +112,19 @@ fn test_do_move_different_subnets() {
111
112
) ,
112
113
0
113
114
) ;
115
+ let alpha_fee: I96F32 =
116
+ I96F32 :: from_num ( fee) / SubtensorModule :: get_alpha_price ( destination_netuid) ;
117
+ let expected_value = I96F32 :: from_num ( alpha)
118
+ * SubtensorModule :: get_alpha_price ( origin_netuid)
119
+ / SubtensorModule :: get_alpha_price ( destination_netuid) ;
114
120
assert_abs_diff_eq ! (
115
121
SubtensorModule :: get_stake_for_hotkey_and_coldkey_on_subnet(
116
122
& destination_hotkey,
117
123
& coldkey,
118
124
destination_netuid
119
125
) ,
120
- stake_amount - 2 * fee ,
121
- epsilon = stake_amount / 1000
126
+ ( expected_value - alpha_fee ) . to_num :: < u64 > ( ) ,
127
+ epsilon = ( expected_value / 1000 ) . to_num :: < u64 > ( )
122
128
) ;
123
129
} ) ;
124
130
}
@@ -700,13 +706,17 @@ fn test_do_move_storage_updates() {
700
706
) ,
701
707
0
702
708
) ;
709
+ let alpha_fee =
710
+ I96F32 :: from_num ( fee) / SubtensorModule :: get_alpha_price ( destination_netuid) ;
711
+ let alpha2 = I96F32 :: from_num ( alpha) * SubtensorModule :: get_alpha_price ( origin_netuid)
712
+ / SubtensorModule :: get_alpha_price ( destination_netuid) ;
703
713
assert_abs_diff_eq ! (
704
714
SubtensorModule :: get_stake_for_hotkey_and_coldkey_on_subnet(
705
715
& destination_hotkey,
706
716
& coldkey,
707
717
destination_netuid
708
718
) ,
709
- alpha - fee ,
719
+ ( alpha2 - alpha_fee ) . to_num :: < u64 > ( ) ,
710
720
epsilon = alpha / 1000
711
721
) ;
712
722
} ) ;
@@ -1063,10 +1073,12 @@ fn test_do_transfer_different_subnets() {
1063
1073
& destination_coldkey,
1064
1074
destination_netuid,
1065
1075
) ;
1076
+ let expected_value = I96F32 :: from_num ( stake_amount - fee)
1077
+ / SubtensorModule :: get_alpha_price ( destination_netuid) ;
1066
1078
assert_abs_diff_eq ! (
1067
1079
dest_stake,
1068
- stake_amount - fee ,
1069
- epsilon = stake_amount / 1000
1080
+ expected_value . to_num :: < u64 > ( ) ,
1081
+ epsilon = ( expected_value / 1000 ) . to_num :: < u64 > ( )
1070
1082
) ;
1071
1083
} ) ;
1072
1084
}
@@ -1114,10 +1126,15 @@ fn test_do_swap_success() {
1114
1126
& coldkey,
1115
1127
destination_netuid,
1116
1128
) ;
1129
+ let alpha_fee =
1130
+ I96F32 :: from_num ( fee) / SubtensorModule :: get_alpha_price ( destination_netuid) ;
1131
+ let expected_value = I96F32 :: from_num ( alpha_before)
1132
+ * SubtensorModule :: get_alpha_price ( origin_netuid)
1133
+ / SubtensorModule :: get_alpha_price ( destination_netuid) ;
1117
1134
assert_abs_diff_eq ! (
1118
1135
alpha_after,
1119
- stake_amount - fee ,
1120
- epsilon = stake_amount / 1000
1136
+ ( expected_value - alpha_fee ) . to_num :: < u64 > ( ) ,
1137
+ epsilon = ( expected_value / 1000 ) . to_num :: < u64 > ( )
1121
1138
) ;
1122
1139
} ) ;
1123
1140
}
@@ -1309,7 +1326,6 @@ fn test_do_swap_partial_stake() {
1309
1326
SubtensorModule :: create_account_if_non_existent ( & coldkey, & hotkey) ;
1310
1327
SubtensorModule :: stake_into_subnet ( & hotkey, & coldkey, origin_netuid, total_stake, 0 ) ;
1311
1328
1312
- let fee_as_alpha2 = SubtensorModule :: swap_tao_for_alpha ( destination_netuid, fee) ;
1313
1329
let swap_amount = total_stake / 2 ;
1314
1330
assert_ok ! ( SubtensorModule :: do_swap_stake(
1315
1331
RuntimeOrigin :: signed( coldkey) ,
@@ -1328,14 +1344,20 @@ fn test_do_swap_partial_stake() {
1328
1344
total_stake - swap_amount,
1329
1345
epsilon = total_stake / 1000
1330
1346
) ;
1347
+
1348
+ let alpha_fee =
1349
+ I96F32 :: from_num ( fee) / SubtensorModule :: get_alpha_price ( destination_netuid) ;
1350
+ let expected_value = I96F32 :: from_num ( swap_amount)
1351
+ * SubtensorModule :: get_alpha_price ( origin_netuid)
1352
+ / SubtensorModule :: get_alpha_price ( destination_netuid) ;
1331
1353
assert_abs_diff_eq ! (
1332
1354
SubtensorModule :: get_stake_for_hotkey_and_coldkey_on_subnet(
1333
1355
& hotkey,
1334
1356
& coldkey,
1335
1357
destination_netuid
1336
1358
) ,
1337
- swap_amount - fee_as_alpha2 ,
1338
- epsilon = total_stake / 1000
1359
+ ( expected_value - alpha_fee ) . to_num :: < u64 > ( ) ,
1360
+ epsilon = ( expected_value / 1000 ) . to_num :: < u64 > ( )
1339
1361
) ;
1340
1362
} ) ;
1341
1363
}
@@ -1378,16 +1400,19 @@ fn test_do_swap_storage_updates() {
1378
1400
0
1379
1401
) ;
1380
1402
1381
- let fee_as_alpha = SubtensorModule :: swap_tao_for_alpha ( destination_netuid, fee) ;
1382
-
1403
+ let alpha_fee =
1404
+ I96F32 :: from_num ( fee) / SubtensorModule :: get_alpha_price ( destination_netuid) ;
1405
+ let expected_value = I96F32 :: from_num ( alpha)
1406
+ * SubtensorModule :: get_alpha_price ( origin_netuid)
1407
+ / SubtensorModule :: get_alpha_price ( destination_netuid) ;
1383
1408
assert_abs_diff_eq ! (
1384
1409
SubtensorModule :: get_stake_for_hotkey_and_coldkey_on_subnet(
1385
1410
& hotkey,
1386
1411
& coldkey,
1387
1412
destination_netuid
1388
1413
) ,
1389
- alpha - fee_as_alpha ,
1390
- epsilon = 5
1414
+ ( expected_value - alpha_fee ) . to_num :: < u64 > ( ) ,
1415
+ epsilon = ( expected_value / 1000 ) . to_num :: < u64 > ( )
1391
1416
) ;
1392
1417
} ) ;
1393
1418
}
0 commit comments