Skip to content

Commit 1fab7b0

Browse files
author
Roman
committed
add e2e test (happy pass, failed)
1 parent 8086324 commit 1fab7b0

File tree

1 file changed

+104
-0
lines changed

1 file changed

+104
-0
lines changed
Lines changed: 104 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,104 @@
1+
import pytest
2+
3+
from bittensor.core.chain_data import SubnetIdentity
4+
from bittensor.utils.btlogging import logging
5+
6+
7+
@pytest.mark.asyncio
8+
async def test_set_subnet_identity_extrinsic_happy_pass(subtensor, alice_wallet):
9+
logging.console.info(
10+
"[magenta]Testing `set_subnet_identity_extrinsic` with success result.[/magenta]"
11+
)
12+
13+
netuid = 2
14+
15+
# Register a subnet, netuid 2
16+
assert subtensor.register_subnet(alice_wallet), "Subnet wasn't created"
17+
18+
# Verify subnet <netuid> created successfully
19+
assert subtensor.subnet_exists(netuid), "Subnet wasn't created successfully"
20+
21+
# make sure subnet_identity is empty
22+
assert (
23+
subtensor.subnet(netuid).subnet_identity is None
24+
), "Subnet identity should be None before set"
25+
26+
# prepare SubnetIdentity for subnet
27+
subnet_identity = SubnetIdentity(
28+
subnet_name="e2e test subnet",
29+
github_repo="e2e test repo",
30+
subnet_contact="e2e test contact",
31+
subnet_url="e2e test url",
32+
discord="e2e test discord",
33+
description="e2e test description",
34+
additional="e2e test additional",
35+
)
36+
37+
# set SubnetIdentity to subnet
38+
assert (
39+
subtensor.set_subnet_identity(
40+
wallet=alice_wallet,
41+
netuid=netuid,
42+
subnet_identity=subnet_identity,
43+
)[0]
44+
is True
45+
), "Set subnet identity failed"
46+
47+
# check SubnetIdentity of the subnet
48+
assert subtensor.subnet(netuid).subnet_identity == subnet_identity
49+
50+
51+
@pytest.mark.asyncio
52+
async def test_set_subnet_identity_extrinsic_failed(
53+
subtensor, alice_wallet, bob_wallet
54+
):
55+
"""
56+
Test case for verifying the behavior of the `set_subnet_identity_extrinsic` function in the
57+
scenario where the result of the function is expected to fail. It ensures proper handling
58+
and validation when attempting to set the subnet identity under specific conditions.
59+
60+
Args:
61+
subtensor: The instance of the subtensor class under test.
62+
alice_wallet: A mock or test wallet associated with Alice, used for creating a subnet.
63+
bob_wallet: A mock or test wallet associated with Bob, used for setting the subnet identity.
64+
65+
Decorators:
66+
@pytest.mark.asyncio: Marks this test as an asynchronous test.
67+
"""
68+
logging.console.info(
69+
"[magenta]Testing `set_subnet_identity_extrinsic` with failed result.[/magenta]"
70+
)
71+
72+
netuid = 2
73+
74+
# Register a subnet, netuid 2
75+
assert subtensor.register_subnet(alice_wallet), "Subnet wasn't created"
76+
77+
# Verify subnet <netuid> created successfully
78+
assert subtensor.subnet_exists(netuid), "Subnet wasn't created successfully"
79+
80+
# make sure subnet_identity is empty
81+
assert (
82+
subtensor.subnet(netuid).subnet_identity is None
83+
), "Subnet identity should be None before set"
84+
85+
# prepare SubnetIdentity for subnet
86+
subnet_identity = SubnetIdentity(
87+
subnet_name="e2e test subnet",
88+
github_repo="e2e test repo",
89+
subnet_contact="e2e test contact",
90+
subnet_url="e2e test url",
91+
discord="e2e test discord",
92+
description="e2e test description",
93+
additional="e2e test additional",
94+
)
95+
96+
# set SubnetIdentity to subnet
97+
assert (
98+
subtensor.set_subnet_identity(
99+
wallet=bob_wallet,
100+
netuid=netuid,
101+
subnet_identity=subnet_identity,
102+
)[0]
103+
is False
104+
), "Set subnet identity failed"

0 commit comments

Comments
 (0)