Skip to content

Commit 09ed453

Browse files
committed
added e2es
1 parent 03cd1db commit 09ed453

File tree

1 file changed

+154
-0
lines changed

1 file changed

+154
-0
lines changed

tests/e2e_tests/test_stake_fee.py

Lines changed: 154 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,154 @@
1+
import pytest
2+
from bittensor import Balance
3+
4+
5+
@pytest.mark.parametrize("local_chain", [False], indirect=True)
6+
@pytest.mark.asyncio
7+
async def test_stake_fee_api(local_chain, subtensor, alice_wallet, bob_wallet):
8+
"""
9+
Tests the stake fee calculation mechanism for various staking operations
10+
11+
Steps:
12+
1. Register a subnet through Alice
13+
2. Set up test parameters
14+
3. Test stake fees for different scenarios:
15+
- Adding new stake
16+
- Removing stake
17+
- Moving between subnets
18+
- Moving between hotkeys
19+
- Moving between coldkeys
20+
- Swapping between subnets
21+
"""
22+
MIN_STAKE_FEE = Balance.from_rao(50_000)
23+
netuid = 2
24+
root_netuid = 0
25+
stake_amount = Balance.from_tao(100).rao # 100 TAO
26+
27+
# Register subnet as Alice
28+
assert subtensor.register_subnet(alice_wallet), "Unable to register the subnet"
29+
assert subtensor.subnet_exists(netuid), "Subnet wasn't created successfully"
30+
31+
# Add_stake (new stake)
32+
stake_fee_0 = subtensor.get_stake_fee(
33+
origin_hotkey_ss58=None,
34+
origin_netuid=None,
35+
origin_coldkey_ss58=alice_wallet.coldkeypub.ss58_address,
36+
destination_hotkey_ss58=alice_wallet.hotkey.ss58_address,
37+
destination_netuid=netuid,
38+
destination_coldkey_ss58=alice_wallet.coldkeypub.ss58_address,
39+
amount=stake_amount,
40+
)
41+
assert isinstance(stake_fee_0, Balance), "Stake fee should be a Balance object"
42+
43+
# Remove stake
44+
stake_fee_1 = subtensor.get_stake_fee(
45+
origin_hotkey_ss58=bob_wallet.hotkey.ss58_address,
46+
origin_netuid=root_netuid,
47+
origin_coldkey_ss58=alice_wallet.coldkeypub.ss58_address,
48+
destination_hotkey_ss58=None,
49+
destination_netuid=None,
50+
destination_coldkey_ss58=alice_wallet.coldkeypub.ss58_address,
51+
amount=stake_amount,
52+
)
53+
assert isinstance(stake_fee_1, Balance), "Stake fee should be a Balance object"
54+
55+
# Move from root to non-root
56+
stake_fee_2 = subtensor.get_stake_fee(
57+
origin_hotkey_ss58=alice_wallet.hotkey.ss58_address,
58+
origin_netuid=root_netuid,
59+
origin_coldkey_ss58=alice_wallet.coldkeypub.ss58_address,
60+
destination_hotkey_ss58=alice_wallet.hotkey.ss58_address,
61+
destination_netuid=netuid,
62+
destination_coldkey_ss58=alice_wallet.coldkeypub.ss58_address,
63+
amount=stake_amount,
64+
)
65+
assert isinstance(stake_fee_2, Balance), "Stake fee should be a Balance object"
66+
67+
# Move between hotkeys on root
68+
stake_fee_3 = subtensor.get_stake_fee(
69+
origin_hotkey_ss58=alice_wallet.hotkey.ss58_address,
70+
origin_netuid=root_netuid,
71+
origin_coldkey_ss58=alice_wallet.coldkeypub.ss58_address,
72+
destination_hotkey_ss58=bob_wallet.hotkey.ss58_address,
73+
destination_netuid=root_netuid,
74+
destination_coldkey_ss58=alice_wallet.coldkeypub.ss58_address,
75+
amount=stake_amount,
76+
)
77+
assert isinstance(stake_fee_3, Balance), "Stake fee should be a Balance object"
78+
79+
# Move between coldkeys on root
80+
stake_fee_4 = subtensor.get_stake_fee(
81+
origin_hotkey_ss58=bob_wallet.hotkey.ss58_address,
82+
origin_netuid=root_netuid,
83+
origin_coldkey_ss58=alice_wallet.coldkeypub.ss58_address,
84+
destination_hotkey_ss58=bob_wallet.hotkey.ss58_address,
85+
destination_netuid=root_netuid,
86+
destination_coldkey_ss58=bob_wallet.coldkeypub.ss58_address,
87+
amount=stake_amount,
88+
)
89+
assert isinstance(stake_fee_4, Balance), "Stake fee should be a Balance object"
90+
91+
# Swap from non-root to root
92+
stake_fee_5 = subtensor.get_stake_fee(
93+
origin_hotkey_ss58=bob_wallet.hotkey.ss58_address,
94+
origin_netuid=netuid,
95+
origin_coldkey_ss58=alice_wallet.coldkeypub.ss58_address,
96+
destination_hotkey_ss58=bob_wallet.hotkey.ss58_address,
97+
destination_netuid=root_netuid,
98+
destination_coldkey_ss58=alice_wallet.coldkeypub.ss58_address,
99+
amount=stake_amount,
100+
)
101+
assert isinstance(stake_fee_5, Balance), "Stake fee should be a Balance object"
102+
103+
# Move between hotkeys on non-root
104+
stake_fee_6 = subtensor.get_stake_fee(
105+
origin_hotkey_ss58=bob_wallet.hotkey.ss58_address,
106+
origin_netuid=netuid,
107+
origin_coldkey_ss58=alice_wallet.coldkeypub.ss58_address,
108+
destination_hotkey_ss58=alice_wallet.hotkey.ss58_address,
109+
destination_netuid=netuid,
110+
destination_coldkey_ss58=alice_wallet.coldkeypub.ss58_address,
111+
amount=stake_amount,
112+
)
113+
assert isinstance(stake_fee_6, Balance), "Stake fee should be a Balance object"
114+
115+
# Move between coldkeys on non-root
116+
stake_fee_7 = subtensor.get_stake_fee(
117+
origin_hotkey_ss58=bob_wallet.hotkey.ss58_address,
118+
origin_netuid=netuid,
119+
origin_coldkey_ss58=alice_wallet.coldkeypub.ss58_address,
120+
destination_hotkey_ss58=bob_wallet.hotkey.ss58_address,
121+
destination_netuid=netuid,
122+
destination_coldkey_ss58=bob_wallet.coldkeypub.ss58_address,
123+
amount=stake_amount,
124+
)
125+
assert isinstance(stake_fee_7, Balance), "Stake fee should be a Balance object"
126+
127+
# Swap from non-root to non-root (between subnets)
128+
netuid2 = 3
129+
assert subtensor.register_subnet(
130+
alice_wallet
131+
), "Unable to register the second subnet"
132+
assert subtensor.subnet_exists(netuid2), "Second subnet wasn't created successfully"
133+
134+
stake_fee_8 = subtensor.get_stake_fee(
135+
origin_hotkey_ss58=bob_wallet.hotkey.ss58_address,
136+
origin_netuid=netuid,
137+
origin_coldkey_ss58=alice_wallet.coldkeypub.ss58_address,
138+
destination_hotkey_ss58=bob_wallet.hotkey.ss58_address,
139+
destination_netuid=netuid2,
140+
destination_coldkey_ss58=alice_wallet.coldkeypub.ss58_address,
141+
amount=stake_amount,
142+
)
143+
assert isinstance(stake_fee_8, Balance), "Stake fee should be a Balance object"
144+
145+
# Verify all fees are non-zero
146+
assert stake_fee_0 >= MIN_STAKE_FEE, "Stake fee should be greater than 0"
147+
assert stake_fee_1 >= MIN_STAKE_FEE, "Stake fee should be greater than 0"
148+
assert stake_fee_2 >= MIN_STAKE_FEE, "Stake fee should be greater than 0"
149+
assert stake_fee_3 >= MIN_STAKE_FEE, "Stake fee should be greater than 0"
150+
assert stake_fee_4 >= MIN_STAKE_FEE, "Stake fee should be greater than 0"
151+
assert stake_fee_5 >= MIN_STAKE_FEE, "Stake fee should be greater than 0"
152+
assert stake_fee_6 >= MIN_STAKE_FEE, "Stake fee should be greater than 0"
153+
assert stake_fee_7 >= MIN_STAKE_FEE, "Stake fee should be greater than 0"
154+
assert stake_fee_8 >= MIN_STAKE_FEE, "Stake fee should be greater than 0"

0 commit comments

Comments
 (0)