Skip to content

Commit 97ccae7

Browse files
authored
Merge pull request #2959 from opentensor/fix/roman/stake-fee-e2e-test
fix and improve e2e stake fee test
2 parents 8ac6605 + 3d1f463 commit 97ccae7

File tree

4 files changed

+43
-31
lines changed

4 files changed

+43
-31
lines changed

bittensor/core/async_subtensor.py

Lines changed: 0 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1951,13 +1951,9 @@ async def get_hotkey_owner(
19511951
async def get_minimum_required_stake(self):
19521952
"""
19531953
Returns the minimum required stake for nominators in the Subtensor network.
1954-
This method retries the substrate call up to three times with exponential backoff in case of failures.
19551954
19561955
Returns:
19571956
Balance: The minimum required stake as a Balance object.
1958-
1959-
Raises:
1960-
Exception: If the substrate call fails after the maximum number of retries.
19611957
"""
19621958
result = await self.substrate.query(
19631959
module="SubtensorModule", storage_function="NominatorMinRequiredStake"

bittensor/core/subtensor.py

Lines changed: 1 addition & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1277,13 +1277,9 @@ def get_hotkey_owner(
12771277
def get_minimum_required_stake(self) -> Balance:
12781278
"""
12791279
Returns the minimum required stake for nominators in the Subtensor network.
1280-
This method retries the substrate call up to three times with exponential backoff in case of failures.
12811280
12821281
Returns:
1283-
Balance: The minimum required stake as a Balance object.
1284-
1285-
Raises:
1286-
Exception: If the substrate call fails after the maximum number of retries.
1282+
The minimum required stake as a Balance object in TAO.
12871283
"""
12881284
result = self.substrate.query(
12891285
module="SubtensorModule", storage_function="NominatorMinRequiredStake"

tests/e2e_tests/test_delegate.py

Lines changed: 21 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -293,11 +293,13 @@ async def test_delegates(local_chain, subtensor, alice_wallet, bob_wallet):
293293
bittensor.logging.console.success("Test [green]test_delegates[/green] passed.")
294294

295295

296-
def test_nominator_min_required_stake(local_chain, subtensor, alice_wallet, bob_wallet):
296+
def test_nominator_min_required_stake(
297+
local_chain, subtensor, alice_wallet, bob_wallet, dave_wallet
298+
):
297299
"""
298300
Tests:
299301
- Check default NominatorMinRequiredStake
300-
- Add Stake to Nominate
302+
- Add Stake to Nominate from Dave to Bob
301303
- Update NominatorMinRequiredStake
302304
- Check Nominator is removed
303305
"""
@@ -323,15 +325,22 @@ def test_nominator_min_required_stake(local_chain, subtensor, alice_wallet, bob_
323325
assert minimum_required_stake == Balance(0)
324326

325327
subtensor.burned_register(
326-
bob_wallet,
327-
alice_subnet_netuid,
328+
wallet=bob_wallet,
329+
netuid=alice_subnet_netuid,
330+
wait_for_inclusion=True,
331+
wait_for_finalization=True,
332+
)
333+
334+
subtensor.burned_register(
335+
wallet=dave_wallet,
336+
netuid=alice_subnet_netuid,
328337
wait_for_inclusion=True,
329338
wait_for_finalization=True,
330339
)
331340

332341
success = subtensor.add_stake(
333-
alice_wallet,
334-
bob_wallet.hotkey.ss58_address,
342+
wallet=dave_wallet,
343+
hotkey_ss58=bob_wallet.hotkey.ss58_address,
335344
netuid=alice_subnet_netuid,
336345
amount=Balance.from_tao(10_000),
337346
wait_for_inclusion=True,
@@ -341,17 +350,17 @@ def test_nominator_min_required_stake(local_chain, subtensor, alice_wallet, bob_
341350
assert success is True
342351

343352
stake = subtensor.get_stake(
344-
alice_wallet.coldkey.ss58_address,
345-
bob_wallet.hotkey.ss58_address,
353+
coldkey_ss58=dave_wallet.coldkey.ss58_address,
354+
hotkey_ss58=bob_wallet.hotkey.ss58_address,
346355
netuid=alice_subnet_netuid,
347356
)
348357

349358
assert stake > 0
350359

351360
# this will trigger clear_small_nominations
352361
sudo_set_admin_utils(
353-
local_chain,
354-
alice_wallet,
362+
substrate=local_chain,
363+
wallet=alice_wallet,
355364
call_function="sudo_set_nominator_min_required_stake",
356365
call_params={
357366
"min_stake": "100000000000000",
@@ -363,8 +372,8 @@ def test_nominator_min_required_stake(local_chain, subtensor, alice_wallet, bob_
363372
assert minimum_required_stake == Balance.from_tao(100_000)
364373

365374
stake = subtensor.get_stake(
366-
alice_wallet.coldkey.ss58_address,
367-
bob_wallet.hotkey.ss58_address,
375+
coldkey_ss58=dave_wallet.coldkey.ss58_address,
376+
hotkey_ss58=bob_wallet.hotkey.ss58_address,
368377
netuid=alice_subnet_netuid,
369378
)
370379

tests/e2e_tests/test_stake_fee.py

Lines changed: 21 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -19,7 +19,7 @@ async def test_stake_fee_api(local_chain, subtensor, alice_wallet, bob_wallet):
1919
netuid = 2
2020
root_netuid = 0
2121
stake_amount = Balance.from_tao(100) # 100 TAO
22-
min_stake_fee = Balance.from_rao(50_000)
22+
min_stake_fee = Balance.from_tao(0.299076829)
2323

2424
# Register subnet as Alice
2525
assert subtensor.register_subnet(alice_wallet), "Unable to register the subnet"
@@ -33,21 +33,19 @@ async def test_stake_fee_api(local_chain, subtensor, alice_wallet, bob_wallet):
3333
hotkey_ss58=alice_wallet.hotkey.ss58_address,
3434
)
3535
assert isinstance(stake_fee_0, Balance), "Stake fee should be a Balance object"
36-
assert stake_fee_0 >= min_stake_fee, (
37-
"Stake fee should be greater than the minimum stake fee"
36+
assert stake_fee_0 == min_stake_fee, (
37+
"Stake fee should be equal the minimum stake fee"
3838
)
3939

4040
# Test unstake fee
41-
stake_fee_1 = subtensor.get_unstake_fee(
41+
unstake_fee_root = subtensor.get_unstake_fee(
4242
amount=stake_amount,
4343
netuid=root_netuid,
4444
coldkey_ss58=alice_wallet.coldkeypub.ss58_address,
4545
hotkey_ss58=bob_wallet.hotkey.ss58_address,
4646
)
47-
assert isinstance(stake_fee_1, Balance), "Stake fee should be a Balance object"
48-
assert stake_fee_1 >= min_stake_fee, (
49-
"Stake fee should be greater than the minimum stake fee"
50-
)
47+
assert isinstance(unstake_fee_root, Balance), "Stake fee should be a Balance object"
48+
assert unstake_fee_root == 0, "Root unstake fee should be 0."
5149

5250
# Test various stake movement scenarios
5351
movement_scenarios = [
@@ -59,6 +57,7 @@ async def test_stake_fee_api(local_chain, subtensor, alice_wallet, bob_wallet):
5957
"dest_netuid": netuid,
6058
"dest_hotkey": alice_wallet.hotkey.ss58_address,
6159
"dest_coldkey": alice_wallet.coldkeypub.ss58_address,
60+
"stake_fee": min_stake_fee,
6261
},
6362
# Move between hotkeys on root
6463
{
@@ -68,15 +67,27 @@ async def test_stake_fee_api(local_chain, subtensor, alice_wallet, bob_wallet):
6867
"dest_netuid": root_netuid,
6968
"dest_hotkey": bob_wallet.hotkey.ss58_address,
7069
"dest_coldkey": alice_wallet.coldkeypub.ss58_address,
70+
"stake_fee": 0,
7171
},
72-
# Move between coldkeys
72+
# Move between coldkeys on root
7373
{
7474
"origin_netuid": root_netuid,
7575
"origin_hotkey": bob_wallet.hotkey.ss58_address,
7676
"origin_coldkey": alice_wallet.coldkeypub.ss58_address,
7777
"dest_netuid": root_netuid,
7878
"dest_hotkey": bob_wallet.hotkey.ss58_address,
7979
"dest_coldkey": bob_wallet.coldkeypub.ss58_address,
80+
"stake_fee": 0,
81+
},
82+
# Move between coldkeys on non-root
83+
{
84+
"origin_netuid": netuid,
85+
"origin_hotkey": bob_wallet.hotkey.ss58_address,
86+
"origin_coldkey": alice_wallet.coldkeypub.ss58_address,
87+
"dest_netuid": netuid,
88+
"dest_hotkey": bob_wallet.hotkey.ss58_address,
89+
"dest_coldkey": bob_wallet.coldkeypub.ss58_address,
90+
"stake_fee": min_stake_fee,
8091
},
8192
]
8293

@@ -91,7 +102,7 @@ async def test_stake_fee_api(local_chain, subtensor, alice_wallet, bob_wallet):
91102
destination_coldkey_ss58=scenario["dest_coldkey"],
92103
)
93104
assert isinstance(stake_fee, Balance), "Stake fee should be a Balance object"
94-
assert stake_fee >= min_stake_fee, (
105+
assert stake_fee >= scenario["stake_fee"], (
95106
"Stake fee should be greater than the minimum stake fee"
96107
)
97108

0 commit comments

Comments
 (0)