@@ -3271,96 +3271,6 @@ def test_get_timestamp(mocker, subtensor):
3271
3271
assert expected_result == actual_result
3272
3272
3273
3273
3274
- def test_stake_fee_methods (mocker , subtensor ):
3275
- """Test the three stake fee calculation methods."""
3276
- # Mock data
3277
- fake_hotkey = "hk1"
3278
- fake_coldkey = "ck1"
3279
- fake_amount = Balance .from_tao (100 )
3280
- netuid = 1
3281
- fake_fee = 1_000_000
3282
-
3283
- # Mock return fee
3284
- mock_query = mocker .patch .object (
3285
- subtensor ,
3286
- "query_runtime_api" ,
3287
- side_effect = lambda runtime_api , method , params , block : (
3288
- fake_fee
3289
- if runtime_api == "StakeInfoRuntimeApi" and method == "get_stake_fee"
3290
- else None
3291
- ),
3292
- )
3293
-
3294
- # get_stake_add_fee
3295
- result = subtensor .get_stake_add_fee (
3296
- amount = fake_amount ,
3297
- netuid = netuid ,
3298
- coldkey_ss58 = fake_coldkey ,
3299
- hotkey_ss58 = fake_hotkey ,
3300
- )
3301
- assert isinstance (result , Balance )
3302
- assert result == Balance .from_rao (fake_fee )
3303
- mock_query .assert_called_with (
3304
- runtime_api = "StakeInfoRuntimeApi" ,
3305
- method = "get_stake_fee" ,
3306
- params = [
3307
- None ,
3308
- fake_coldkey ,
3309
- (fake_hotkey , netuid ),
3310
- fake_coldkey ,
3311
- fake_amount .rao ,
3312
- ],
3313
- block = None ,
3314
- )
3315
-
3316
- # get_unstake_fee
3317
- result = subtensor .get_unstake_fee (
3318
- amount = fake_amount ,
3319
- netuid = netuid ,
3320
- coldkey_ss58 = fake_coldkey ,
3321
- hotkey_ss58 = fake_hotkey ,
3322
- )
3323
- assert isinstance (result , Balance )
3324
- assert result == Balance .from_rao (fake_fee )
3325
- mock_query .assert_called_with (
3326
- runtime_api = "StakeInfoRuntimeApi" ,
3327
- method = "get_stake_fee" ,
3328
- params = [
3329
- (fake_hotkey , netuid ),
3330
- fake_coldkey ,
3331
- None ,
3332
- fake_coldkey ,
3333
- fake_amount .rao ,
3334
- ],
3335
- block = None ,
3336
- )
3337
-
3338
- # get_stake_movement_fee
3339
- result = subtensor .get_stake_movement_fee (
3340
- amount = fake_amount ,
3341
- origin_netuid = 2 ,
3342
- origin_hotkey_ss58 = fake_hotkey ,
3343
- origin_coldkey_ss58 = fake_coldkey ,
3344
- destination_netuid = 3 ,
3345
- destination_hotkey_ss58 = "hk2" ,
3346
- destination_coldkey_ss58 = fake_coldkey ,
3347
- )
3348
- assert isinstance (result , Balance )
3349
- assert result == Balance .from_rao (fake_fee )
3350
- mock_query .assert_called_with (
3351
- runtime_api = "StakeInfoRuntimeApi" ,
3352
- method = "get_stake_fee" ,
3353
- params = [
3354
- (fake_hotkey , 2 ),
3355
- fake_coldkey ,
3356
- ("hk2" , 3 ),
3357
- fake_coldkey ,
3358
- fake_amount .rao ,
3359
- ],
3360
- block = None ,
3361
- )
3362
-
3363
-
3364
3274
def test_get_owned_hotkeys_happy_path (subtensor , mocker ):
3365
3275
"""Tests that the output of get_owned_hotkeys."""
3366
3276
# Prep
@@ -4266,3 +4176,102 @@ def test_subnet(subtensor, mocker):
4266
4176
{"netuid" : netuid , "price" : Balance .from_tao (100.0 )}
4267
4177
)
4268
4178
assert result == mocked_di_from_dict .return_value
4179
+
4180
+
4181
+ def test_get_stake_operations_fee (subtensor , mocker ):
4182
+ """Verify that `get_stake_operations_fee` calls proper methods and returns the correct value."""
4183
+ # Preps
4184
+ netuid = 1
4185
+ amount = Balance .from_rao (100_000_000_000 ) # 100 Tao
4186
+ mocked_determine_block_hash = mocker .patch .object (subtensor , "determine_block_hash" )
4187
+ mocked_query_map = mocker .patch .object (
4188
+ subtensor .substrate , "query" , return_value = mocker .Mock (value = 196 )
4189
+ )
4190
+
4191
+ # Call
4192
+ result = subtensor .get_stake_operations_fee (amount = amount , netuid = netuid )
4193
+
4194
+ # Assert
4195
+ mocked_determine_block_hash .assert_called_once_with (block = None )
4196
+ mocked_query_map .assert_called_once_with (
4197
+ module = "Swap" ,
4198
+ storage_function = "FeeRate" ,
4199
+ params = [netuid ],
4200
+ block_hash = mocked_determine_block_hash .return_value ,
4201
+ )
4202
+ assert result == Balance .from_rao (299076829 ).set_unit (netuid )
4203
+
4204
+
4205
+ def test_get_stake_add_fee (subtensor , mocker ):
4206
+ """Verify that `get_stake_add_fee` calls proper methods and returns the correct value."""
4207
+ # Preps
4208
+ netuid = mocker .Mock ()
4209
+ amount = mocker .Mock ()
4210
+ mocked_get_stake_operations_fee = mocker .patch .object (
4211
+ subtensor , "get_stake_operations_fee"
4212
+ )
4213
+
4214
+ # Call
4215
+ result = subtensor .get_stake_add_fee (
4216
+ amount = amount ,
4217
+ netuid = netuid ,
4218
+ coldkey_ss58 = mocker .Mock (),
4219
+ hotkey_ss58 = mocker .Mock (),
4220
+ )
4221
+
4222
+ # Asserts
4223
+ mocked_get_stake_operations_fee .assert_called_once_with (
4224
+ amount = amount , netuid = netuid , block = None
4225
+ )
4226
+ assert result == mocked_get_stake_operations_fee .return_value
4227
+
4228
+
4229
+ def test_get_unstake_fee (subtensor , mocker ):
4230
+ """Verify that `get_unstake_fee` calls proper methods and returns the correct value."""
4231
+ # Preps
4232
+ netuid = mocker .Mock ()
4233
+ amount = mocker .Mock ()
4234
+ mocked_get_stake_operations_fee = mocker .patch .object (
4235
+ subtensor , "get_stake_operations_fee"
4236
+ )
4237
+
4238
+ # Call
4239
+ result = subtensor .get_unstake_fee (
4240
+ amount = amount ,
4241
+ netuid = netuid ,
4242
+ coldkey_ss58 = mocker .Mock (),
4243
+ hotkey_ss58 = mocker .Mock (),
4244
+ )
4245
+
4246
+ # Asserts
4247
+ mocked_get_stake_operations_fee .assert_called_once_with (
4248
+ amount = amount , netuid = netuid , block = None
4249
+ )
4250
+ assert result == mocked_get_stake_operations_fee .return_value
4251
+
4252
+
4253
+ def test_get_stake_movement_fee (subtensor , mocker ):
4254
+ """Verify that `get_stake_movement_fee` calls proper methods and returns the correct value."""
4255
+ # Preps
4256
+ netuid = mocker .Mock ()
4257
+ amount = mocker .Mock ()
4258
+ mocked_get_stake_operations_fee = mocker .patch .object (
4259
+ subtensor , "get_stake_operations_fee"
4260
+ )
4261
+
4262
+ # Call
4263
+ result = subtensor .get_stake_movement_fee (
4264
+ amount = amount ,
4265
+ origin_netuid = netuid ,
4266
+ origin_hotkey_ss58 = mocker .Mock (),
4267
+ origin_coldkey_ss58 = mocker .Mock (),
4268
+ destination_netuid = mocker .Mock (),
4269
+ destination_hotkey_ss58 = mocker .Mock (),
4270
+ destination_coldkey_ss58 = mocker .Mock (),
4271
+ )
4272
+
4273
+ # Asserts
4274
+ mocked_get_stake_operations_fee .assert_called_once_with (
4275
+ amount = amount , netuid = netuid , block = None
4276
+ )
4277
+ assert result == mocked_get_stake_operations_fee .return_value
0 commit comments