2
2
# Copyright © 2024 Opentensor Foundation
3
3
#
4
4
# Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated
5
- # documentation files (the “ Software” ), to deal in the Software without restriction, including without limitation
5
+ # documentation files (the " Software" ), to deal in the Software without restriction, including without limitation
6
6
# the rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software,
7
7
# and to permit persons to whom the Software is furnished to do so, subject to the following conditions:
8
8
#
9
9
# The above copyright notice and this permission notice shall be included in all copies or substantial portions of
10
10
# the Software.
11
11
#
12
- # THE SOFTWARE IS PROVIDED “ AS IS” , WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO
12
+ # THE SOFTWARE IS PROVIDED " AS IS" , WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO
13
13
# THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL
14
14
# THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
15
15
# OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER
@@ -2854,6 +2854,9 @@ def test_add_stake_success(mocker, fake_wallet, subtensor):
2854
2854
amount = fake_amount ,
2855
2855
wait_for_inclusion = True ,
2856
2856
wait_for_finalization = False ,
2857
+ safe_staking = False ,
2858
+ allow_partial_stake = False ,
2859
+ rate_threshold = 0.005 ,
2857
2860
)
2858
2861
2859
2862
# Assertions
@@ -2865,6 +2868,48 @@ def test_add_stake_success(mocker, fake_wallet, subtensor):
2865
2868
amount = Balance .from_rao (fake_amount ),
2866
2869
wait_for_inclusion = True ,
2867
2870
wait_for_finalization = False ,
2871
+ safe_staking = False ,
2872
+ allow_partial_stake = False ,
2873
+ rate_threshold = 0.005 ,
2874
+ )
2875
+ assert result == mock_add_stake_extrinsic .return_value
2876
+
2877
+
2878
+ def test_add_stake_with_safe_staking (mocker , fake_wallet , subtensor ):
2879
+ """Test add_stake with safe staking parameters enabled."""
2880
+ # Prep
2881
+ fake_hotkey_ss58 = "fake_hotkey"
2882
+ fake_amount = 10.0
2883
+ fake_rate_threshold = 0.01 # 1% threshold
2884
+
2885
+ mock_add_stake_extrinsic = mocker .patch .object (
2886
+ subtensor_module , "add_stake_extrinsic"
2887
+ )
2888
+
2889
+ # Call
2890
+ result = subtensor .add_stake (
2891
+ wallet = fake_wallet ,
2892
+ hotkey_ss58 = fake_hotkey_ss58 ,
2893
+ amount = fake_amount ,
2894
+ wait_for_inclusion = True ,
2895
+ wait_for_finalization = False ,
2896
+ safe_staking = True ,
2897
+ allow_partial_stake = False ,
2898
+ rate_threshold = fake_rate_threshold ,
2899
+ )
2900
+
2901
+ # Assertions
2902
+ mock_add_stake_extrinsic .assert_called_once_with (
2903
+ subtensor = subtensor ,
2904
+ wallet = fake_wallet ,
2905
+ hotkey_ss58 = fake_hotkey_ss58 ,
2906
+ netuid = None ,
2907
+ amount = Balance .from_rao (fake_amount ),
2908
+ wait_for_inclusion = True ,
2909
+ wait_for_finalization = False ,
2910
+ safe_staking = True ,
2911
+ allow_partial_stake = False ,
2912
+ rate_threshold = fake_rate_threshold ,
2868
2913
)
2869
2914
assert result == mock_add_stake_extrinsic .return_value
2870
2915
@@ -2917,6 +2962,45 @@ def test_unstake_success(mocker, subtensor, fake_wallet):
2917
2962
amount = fake_amount ,
2918
2963
wait_for_inclusion = True ,
2919
2964
wait_for_finalization = False ,
2965
+ safe_staking = False ,
2966
+ allow_partial_stake = False ,
2967
+ rate_threshold = 0.005 ,
2968
+ )
2969
+
2970
+ # Assertions
2971
+ mock_unstake_extrinsic .assert_called_once_with (
2972
+ subtensor = subtensor ,
2973
+ wallet = fake_wallet ,
2974
+ hotkey_ss58 = fake_hotkey_ss58 ,
2975
+ netuid = None ,
2976
+ amount = Balance .from_rao (fake_amount ),
2977
+ wait_for_inclusion = True ,
2978
+ wait_for_finalization = False ,
2979
+ safe_staking = False ,
2980
+ allow_partial_stake = False ,
2981
+ rate_threshold = 0.005 ,
2982
+ )
2983
+ assert result == mock_unstake_extrinsic .return_value
2984
+
2985
+
2986
+ def test_unstake_with_safe_staking (mocker , subtensor , fake_wallet ):
2987
+ """Test unstake with safe staking parameters enabled."""
2988
+ fake_hotkey_ss58 = "hotkey_1"
2989
+ fake_amount = 10.0
2990
+ fake_rate_threshold = 0.01 # 1% threshold
2991
+
2992
+ mock_unstake_extrinsic = mocker .patch .object (subtensor_module , "unstake_extrinsic" )
2993
+
2994
+ # Call
2995
+ result = subtensor .unstake (
2996
+ wallet = fake_wallet ,
2997
+ hotkey_ss58 = fake_hotkey_ss58 ,
2998
+ amount = fake_amount ,
2999
+ wait_for_inclusion = True ,
3000
+ wait_for_finalization = False ,
3001
+ safe_staking = True ,
3002
+ allow_partial_stake = True ,
3003
+ rate_threshold = fake_rate_threshold ,
2920
3004
)
2921
3005
2922
3006
# Assertions
@@ -2928,6 +3012,9 @@ def test_unstake_success(mocker, subtensor, fake_wallet):
2928
3012
amount = Balance .from_rao (fake_amount ),
2929
3013
wait_for_inclusion = True ,
2930
3014
wait_for_finalization = False ,
3015
+ safe_staking = True ,
3016
+ allow_partial_stake = True ,
3017
+ rate_threshold = fake_rate_threshold ,
2931
3018
)
2932
3019
assert result == mock_unstake_extrinsic .return_value
2933
3020
0 commit comments