Skip to content

Commit 03cd1db

Browse files
committed
adds unit test
1 parent d32dc2c commit 03cd1db

File tree

1 file changed

+91
-0
lines changed

1 file changed

+91
-0
lines changed

tests/unit_tests/test_subtensor.py

Lines changed: 91 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2611,6 +2611,97 @@ def test_get_minimum_required_stake_query_failure(mocker, subtensor):
26112611
)
26122612

26132613

2614+
def test_get_stake_fee_parameter_handling(mocker, subtensor):
2615+
"""Test get_stake_fee parameter handling, focusing on None cases and tuple creation."""
2616+
# Mock data
2617+
fake_hotkey = "hk1"
2618+
fake_hotkey2 = "hk2"
2619+
fake_coldkey = "ck1"
2620+
fake_amount = Balance.from_tao(100)
2621+
netuid = 1
2622+
fake_fee = 1_000_000
2623+
2624+
# Mock return fee
2625+
mock_query = mocker.patch.object(
2626+
subtensor,
2627+
"query_runtime_api",
2628+
side_effect=lambda runtime_api, method, params, block: (
2629+
fake_fee
2630+
if runtime_api == "StakeInfoRuntimeApi" and method == "get_stake_fee"
2631+
else None
2632+
),
2633+
)
2634+
2635+
# Test Cases
2636+
test_cases = [
2637+
# 1. Adding new stake (origin is None)
2638+
{
2639+
"name": "new_stake",
2640+
"params": {
2641+
"origin_hotkey_ss58": None,
2642+
"origin_netuid": None,
2643+
"origin_coldkey_ss58": fake_coldkey,
2644+
"destination_hotkey_ss58": fake_hotkey,
2645+
"destination_netuid": netuid,
2646+
"destination_coldkey_ss58": fake_coldkey,
2647+
"amount": fake_amount,
2648+
},
2649+
"expected_origin": None,
2650+
"expected_destination": (fake_hotkey, netuid),
2651+
},
2652+
# 2. Removing stake (destination is None)
2653+
{
2654+
"name": "remove_stake",
2655+
"params": {
2656+
"origin_hotkey_ss58": fake_hotkey,
2657+
"origin_netuid": netuid,
2658+
"origin_coldkey_ss58": fake_coldkey,
2659+
"destination_hotkey_ss58": None,
2660+
"destination_netuid": None,
2661+
"destination_coldkey_ss58": fake_coldkey,
2662+
"amount": fake_amount,
2663+
},
2664+
"expected_origin": (fake_hotkey, netuid),
2665+
"expected_destination": None,
2666+
},
2667+
# 3. All parameters present
2668+
{
2669+
"name": "all_parameters",
2670+
"params": {
2671+
"origin_hotkey_ss58": fake_hotkey,
2672+
"origin_netuid": netuid,
2673+
"origin_coldkey_ss58": fake_coldkey,
2674+
"destination_hotkey_ss58": fake_hotkey2,
2675+
"destination_netuid": netuid,
2676+
"destination_coldkey_ss58": fake_coldkey,
2677+
"amount": fake_amount,
2678+
},
2679+
"expected_origin": (fake_hotkey, netuid),
2680+
"expected_destination": (fake_hotkey2, netuid),
2681+
},
2682+
]
2683+
2684+
for test_case in test_cases:
2685+
mock_query.reset_mock()
2686+
2687+
result = subtensor.get_stake_fee(**test_case["params"])
2688+
assert isinstance(result, Balance)
2689+
assert result == Balance.from_rao(fake_fee)
2690+
2691+
mock_query.assert_called_once_with(
2692+
runtime_api="StakeInfoRuntimeApi",
2693+
method="get_stake_fee",
2694+
params=[
2695+
test_case["expected_origin"],
2696+
test_case["params"]["origin_coldkey_ss58"],
2697+
test_case["expected_destination"],
2698+
test_case["params"]["destination_coldkey_ss58"],
2699+
test_case["params"]["amount"],
2700+
],
2701+
block=None,
2702+
)
2703+
2704+
26142705
def test_get_minimum_required_stake_invalid_result(mocker, subtensor):
26152706
"""Test when the result cannot be decoded."""
26162707
# Mock data

0 commit comments

Comments
 (0)