@@ -1114,60 +1114,82 @@ fn test_clear_small_nominations() {
1114
1114
assert_eq ! ( SubtensorModule :: get_owning_coldkey_for_hotkey( & hot2) , cold2) ;
1115
1115
1116
1116
// Add stake cold1 --> hot1 (non delegation.)
1117
- SubtensorModule :: add_balance_to_coldkey_account ( & cold1, 5 ) ;
1117
+ SubtensorModule :: add_balance_to_coldkey_account ( & cold1, 1_000 ) ;
1118
1118
assert_ok ! ( SubtensorModule :: add_stake(
1119
1119
RuntimeOrigin :: signed( cold1) ,
1120
1120
hot1,
1121
1121
netuid,
1122
- 1
1122
+ 1_000
1123
+ ) ) ;
1124
+ assert_ok ! ( SubtensorModule :: remove_stake(
1125
+ RuntimeOrigin :: signed( cold1) ,
1126
+ hot1,
1127
+ netuid,
1128
+ SubtensorModule :: get_stake_for_hotkey_and_coldkey_on_subnet( & hot1, & cold1, netuid) - 1
1123
1129
) ) ;
1124
1130
assert_eq ! (
1125
1131
SubtensorModule :: get_stake_for_hotkey_and_coldkey_on_subnet( & hot1, & cold1, netuid) ,
1126
1132
1
1127
1133
) ;
1128
- assert_eq ! ( Balances :: free_balance( cold1) , 4 ) ;
1129
1134
1130
1135
// Add stake cold2 --> hot1 (is delegation.)
1131
- SubtensorModule :: add_balance_to_coldkey_account ( & cold2, 5 ) ;
1136
+ SubtensorModule :: add_balance_to_coldkey_account ( & cold2, 1_000 ) ;
1132
1137
assert_ok ! ( SubtensorModule :: add_stake(
1133
1138
RuntimeOrigin :: signed( cold2) ,
1134
1139
hot1,
1135
1140
netuid,
1136
- 1
1141
+ 1_000
1142
+ ) ) ;
1143
+ assert_ok ! ( SubtensorModule :: remove_stake(
1144
+ RuntimeOrigin :: signed( cold2) ,
1145
+ hot1,
1146
+ netuid,
1147
+ SubtensorModule :: get_stake_for_hotkey_and_coldkey_on_subnet( & hot1, & cold2, netuid) - 1
1137
1148
) ) ;
1138
1149
assert_eq ! (
1139
1150
SubtensorModule :: get_stake_for_hotkey_and_coldkey_on_subnet( & hot1, & cold2, netuid) ,
1140
1151
1
1141
1152
) ;
1142
- assert_eq ! ( Balances :: free_balance( cold2) , 4 ) ;
1143
1153
1144
1154
// Add stake cold1 --> hot2 (non delegation.)
1145
- SubtensorModule :: add_balance_to_coldkey_account ( & cold1, 5 ) ;
1155
+ SubtensorModule :: add_balance_to_coldkey_account ( & cold1, 1_000 ) ;
1146
1156
assert_ok ! ( SubtensorModule :: add_stake(
1147
1157
RuntimeOrigin :: signed( cold1) ,
1148
1158
hot2,
1149
1159
netuid,
1150
- 1
1160
+ 1_000
1161
+ ) ) ;
1162
+ assert_ok ! ( SubtensorModule :: remove_stake(
1163
+ RuntimeOrigin :: signed( cold1) ,
1164
+ hot2,
1165
+ netuid,
1166
+ SubtensorModule :: get_stake_for_hotkey_and_coldkey_on_subnet( & hot2, & cold1, netuid) - 1
1151
1167
) ) ;
1152
1168
assert_eq ! (
1153
1169
SubtensorModule :: get_stake_for_hotkey_and_coldkey_on_subnet( & hot2, & cold1, netuid) ,
1154
1170
1
1155
1171
) ;
1156
- assert_eq ! ( Balances :: free_balance( cold1) , 8 ) ;
1172
+ let balance1_before_cleaning = Balances :: free_balance ( cold1) ;
1157
1173
1158
1174
// Add stake cold2 --> hot2 (is delegation.)
1159
- SubtensorModule :: add_balance_to_coldkey_account ( & cold2, 5 ) ;
1175
+ SubtensorModule :: add_balance_to_coldkey_account ( & cold2, 1_000 ) ;
1160
1176
assert_ok ! ( SubtensorModule :: add_stake(
1161
1177
RuntimeOrigin :: signed( cold2) ,
1162
1178
hot2,
1163
1179
netuid,
1164
- 1
1180
+ 1_000
1181
+ ) ) ;
1182
+ assert_ok ! ( SubtensorModule :: remove_stake(
1183
+ RuntimeOrigin :: signed( cold2) ,
1184
+ hot2,
1185
+ netuid,
1186
+ SubtensorModule :: get_stake_for_hotkey_and_coldkey_on_subnet( & hot2, & cold2, netuid) - 1
1165
1187
) ) ;
1166
1188
assert_eq ! (
1167
1189
SubtensorModule :: get_stake_for_hotkey_and_coldkey_on_subnet( & hot2, & cold2, netuid) ,
1168
1190
1
1169
1191
) ;
1170
- assert_eq ! ( Balances :: free_balance( cold2) , 8 ) ;
1192
+ let balance2_before_cleaning = Balances :: free_balance ( cold2) ;
1171
1193
1172
1194
// Run clear all small nominations when min stake is zero (noop)
1173
1195
SubtensorModule :: set_nominator_min_required_stake ( 0 ) ;
@@ -1218,8 +1240,10 @@ fn test_clear_small_nominations() {
1218
1240
) ;
1219
1241
1220
1242
// Balances have been added back into accounts.
1221
- assert_eq ! ( Balances :: free_balance( cold1) , 9 ) ;
1222
- assert_eq ! ( Balances :: free_balance( cold2) , 9 ) ;
1243
+ let balance1_after_cleaning = Balances :: free_balance ( cold1) ;
1244
+ let balance2_after_cleaning = Balances :: free_balance ( cold2) ;
1245
+ assert_eq ! ( balance1_before_cleaning + 1 , balance1_after_cleaning) ;
1246
+ assert_eq ! ( balance2_before_cleaning + 1 , balance2_after_cleaning) ;
1223
1247
1224
1248
assert_eq ! (
1225
1249
TotalHotkeyAlpha :: <Test >:: get( hot2, netuid) ,
@@ -1644,7 +1668,7 @@ fn test_get_total_delegated_stake_single_delegator() {
1644
1668
let delegate_coldkey = U256 :: from ( 1 ) ;
1645
1669
let delegate_hotkey = U256 :: from ( 2 ) ;
1646
1670
let delegator = U256 :: from ( 3 ) ;
1647
- let stake_amount = 999 ;
1671
+ let stake_amount = 1_999 ;
1648
1672
let existential_deposit = ExistentialDeposit :: get ( ) ;
1649
1673
let netuid = add_dynamic_network ( & subnet_owner_hotkey, & subnet_owner_coldkey) ;
1650
1674
@@ -1753,8 +1777,8 @@ fn test_get_total_delegated_stake_exclude_owner_stake() {
1753
1777
let delegate_coldkey = U256 :: from ( 1 ) ;
1754
1778
let delegate_hotkey = U256 :: from ( 2 ) ;
1755
1779
let delegator = U256 :: from ( 3 ) ;
1756
- let owner_stake = 1000 ;
1757
- let delegator_stake = 999 ;
1780
+ let owner_stake = 1_000_000 ;
1781
+ let delegator_stake = 999_999 ;
1758
1782
1759
1783
let netuid = add_dynamic_network ( & delegate_hotkey, & delegate_coldkey) ;
1760
1784
@@ -1792,10 +1816,10 @@ fn test_get_total_delegated_stake_exclude_owner_stake() {
1792
1816
let actual_delegated_stake =
1793
1817
SubtensorModule :: get_total_stake_for_coldkey ( & delegate_coldkey) ;
1794
1818
1795
- assert_eq ! (
1796
- actual_delegated_stake, expected_delegated_stake ,
1797
- "Delegated stake should exclude owner's stake. Expected: {}, Actual: {}" ,
1798
- expected_delegated_stake , actual_delegated_stake
1819
+ assert_abs_diff_eq ! (
1820
+ actual_delegated_stake,
1821
+ expected_delegated_stake ,
1822
+ epsilon = 100
1799
1823
) ;
1800
1824
} ) ;
1801
1825
}
0 commit comments