22# Copyright © 2024 Opentensor Foundation
33#
44# 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
66# the rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software,
77# and to permit persons to whom the Software is furnished to do so, subject to the following conditions:
88#
99# The above copyright notice and this permission notice shall be included in all copies or substantial portions of
1010# the Software.
1111#
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
1313# THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL
1414# THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
1515# 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):
28542854 amount = fake_amount ,
28552855 wait_for_inclusion = True ,
28562856 wait_for_finalization = False ,
2857+ safe_staking = False ,
2858+ allow_partial_stake = False ,
2859+ rate_threshold = 0.005 ,
28572860 )
28582861
28592862 # Assertions
@@ -2865,6 +2868,48 @@ def test_add_stake_success(mocker, fake_wallet, subtensor):
28652868 amount = Balance .from_rao (fake_amount ),
28662869 wait_for_inclusion = True ,
28672870 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 ,
28682913 )
28692914 assert result == mock_add_stake_extrinsic .return_value
28702915
@@ -2917,6 +2962,45 @@ def test_unstake_success(mocker, subtensor, fake_wallet):
29172962 amount = fake_amount ,
29182963 wait_for_inclusion = True ,
29192964 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 ,
29203004 )
29213005
29223006 # Assertions
@@ -2928,6 +3012,9 @@ def test_unstake_success(mocker, subtensor, fake_wallet):
29283012 amount = Balance .from_rao (fake_amount ),
29293013 wait_for_inclusion = True ,
29303014 wait_for_finalization = False ,
3015+ safe_staking = True ,
3016+ allow_partial_stake = True ,
3017+ rate_threshold = fake_rate_threshold ,
29313018 )
29323019 assert result == mock_unstake_extrinsic .return_value
29333020
0 commit comments