Skip to content

Commit 666e741

Browse files
Merge pull request #2443 from opentensor/feat/abe/e2e-tests-1
E2E tests - Increasing Subtensor coverage (Pt 1)
2 parents bcc7dc2 + ef47604 commit 666e741

9 files changed

+159
-95
lines changed

tests/e2e_tests/test_axon.py

+9-7
Original file line numberDiff line numberDiff line change
@@ -4,9 +4,9 @@
44
import pytest
55

66
import bittensor
7+
from bittensor.core.subtensor import Subtensor
78
from bittensor.utils import networking
8-
from bittensor.utils.btlogging import logging
9-
from tests.e2e_tests.utils.chain_interactions import register_neuron, register_subnet
9+
from tests.e2e_tests.utils.chain_interactions import register_subnet
1010
from tests.e2e_tests.utils.e2e_test_utils import (
1111
setup_wallet,
1212
template_path,
@@ -28,12 +28,14 @@ async def test_axon(local_chain):
2828
AssertionError: If any of the checks or verifications fail
2929
"""
3030

31-
logging.info("Testing test_axon")
31+
print("Testing test_axon")
3232

3333
netuid = 1
3434
# Register root as Alice - the subnet owner
3535
alice_keypair, wallet = setup_wallet("//Alice")
3636

37+
subtensor = Subtensor(network="ws://localhost:9945")
38+
3739
# Register a subnet, netuid 1
3840
assert register_subnet(local_chain, wallet), "Subnet wasn't created"
3941

@@ -43,8 +45,8 @@ async def test_axon(local_chain):
4345
).serialize(), "Subnet wasn't created successfully"
4446

4547
# Register Alice to the network
46-
assert register_neuron(
47-
local_chain, wallet, netuid
48+
assert subtensor.burned_register(
49+
wallet, netuid
4850
), f"Neuron wasn't registered to subnet {netuid}"
4951

5052
metagraph = bittensor.Metagraph(netuid=netuid, network="ws://localhost:9945")
@@ -87,7 +89,7 @@ async def test_axon(local_chain):
8789
stderr=asyncio.subprocess.PIPE,
8890
)
8991

90-
logging.info("Neuron Alice is now mining")
92+
print("Neuron Alice is now mining")
9193

9294
# Waiting for 5 seconds for metagraph to be updated
9395
await asyncio.sleep(5)
@@ -124,4 +126,4 @@ async def test_axon(local_chain):
124126
updated_axon.coldkey == alice_keypair.ss58_address
125127
), "Coldkey mismatch after mining"
126128

127-
logging.info("✅ Passed test_axon")
129+
print("✅ Passed test_axon")

tests/e2e_tests/test_commit_weights.py

+7-7
Original file line numberDiff line numberDiff line change
@@ -5,11 +5,9 @@
55

66
from bittensor.core.subtensor import Subtensor
77
from bittensor.utils.balance import Balance
8-
from bittensor.utils.btlogging import logging
98
from bittensor.utils.weight_utils import convert_weights_and_uids_for_emit
109
from tests.e2e_tests.utils.chain_interactions import (
1110
add_stake,
12-
register_neuron,
1311
register_subnet,
1412
sudo_set_hyperparameter_bool,
1513
sudo_set_hyperparameter_values,
@@ -34,7 +32,7 @@ async def test_commit_and_reveal_weights(local_chain):
3432
AssertionError: If any of the checks or verifications fail
3533
"""
3634
netuid = 1
37-
logging.info("Testing test_commit_and_reveal_weights")
35+
print("Testing test_commit_and_reveal_weights")
3836
# Register root as Alice
3937
keypair, alice_wallet = setup_wallet("//Alice")
4038
assert register_subnet(local_chain, alice_wallet), "Unable to register the subnet"
@@ -44,8 +42,11 @@ async def test_commit_and_reveal_weights(local_chain):
4442
"SubtensorModule", "NetworksAdded", [1]
4543
).serialize(), "Subnet wasn't created successfully"
4644

47-
assert register_neuron(
48-
local_chain, alice_wallet, netuid
45+
subtensor = Subtensor(network="ws://localhost:9945")
46+
47+
# Register Alice to the subnet
48+
assert subtensor.burned_register(
49+
alice_wallet, netuid
4950
), "Unable to register Alice as a neuron"
5051

5152
# Stake to become to top neuron after the first epoch
@@ -60,7 +61,6 @@ async def test_commit_and_reveal_weights(local_chain):
6061
netuid,
6162
), "Unable to enable commit reveal on the subnet"
6263

63-
subtensor = Subtensor(network="ws://localhost:9945")
6464
assert subtensor.get_subnet_hyperparameters(
6565
netuid=netuid,
6666
).commit_reveal_weights_enabled, "Failed to enable commit/reveal"
@@ -169,4 +169,4 @@ async def test_commit_and_reveal_weights(local_chain):
169169
assert (
170170
weight_vals[0] == revealed_weights.value[0][1]
171171
), f"Incorrect revealed weights. Expected: {weights[0]}, Actual: {revealed_weights.value[0][1]}"
172-
logging.info("✅ Passed test_commit_and_reveal_weights")
172+
print("✅ Passed test_commit_and_reveal_weights")

tests/e2e_tests/test_dendrite.py

+5-5
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,6 @@
88
from bittensor.utils.balance import Balance
99
from bittensor.utils.btlogging import logging
1010
from tests.e2e_tests.utils.chain_interactions import (
11-
register_neuron,
1211
register_subnet,
1312
add_stake,
1413
wait_epoch,
@@ -52,13 +51,14 @@ async def test_dendrite(local_chain):
5251
# Register Bob
5352
bob_keypair, bob_wallet = setup_wallet("//Bob")
5453

54+
subtensor = Subtensor(network="ws://localhost:9945")
55+
5556
# Register Bob to the network
56-
assert register_neuron(
57-
local_chain, bob_wallet, netuid
58-
), f"Neuron wasn't registered to subnet {netuid}"
57+
assert subtensor.burned_register(
58+
bob_wallet, netuid
59+
), "Unable to register Bob as a neuron"
5960

6061
metagraph = Metagraph(netuid=netuid, network="ws://localhost:9945")
61-
subtensor = Subtensor(network="ws://localhost:9945")
6262

6363
# Assert one neuron is Bob
6464
assert len(subtensor.neurons(netuid=netuid)) == 1

tests/e2e_tests/test_incentive.py

+14-10
Original file line numberDiff line numberDiff line change
@@ -3,10 +3,9 @@
33

44
import pytest
55

6-
from bittensor import Subtensor, logging
6+
from bittensor.core.subtensor import Subtensor
77
from tests.e2e_tests.utils.chain_interactions import (
88
add_stake,
9-
register_neuron,
109
register_subnet,
1110
wait_epoch,
1211
)
@@ -38,7 +37,7 @@ async def test_incentive(local_chain):
3837
AssertionError: If any of the checks or verifications fail
3938
"""
4039

41-
logging.info("Testing test_incentive")
40+
print("Testing test_incentive")
4241
netuid = 1
4342

4443
# Register root as Alice - the subnet owner and validator
@@ -53,13 +52,18 @@ async def test_incentive(local_chain):
5352
# Register Bob as miner
5453
bob_keypair, bob_wallet = setup_wallet("//Bob")
5554

55+
subtensor = Subtensor(network="ws://localhost:9945")
56+
5657
# Register Alice as a neuron on the subnet
57-
register_neuron(local_chain, alice_wallet, netuid)
58+
assert subtensor.burned_register(
59+
alice_wallet, netuid
60+
), "Unable to register Alice as a neuron"
5861

5962
# Register Bob as a neuron on the subnet
60-
register_neuron(local_chain, bob_wallet, netuid)
63+
assert subtensor.burned_register(
64+
bob_wallet, netuid
65+
), "Unable to register Bob as a neuron"
6166

62-
subtensor = Subtensor(network="ws://localhost:9945")
6367
# Assert two neurons are in network
6468
assert (
6569
len(subtensor.neurons(netuid=netuid)) == 2
@@ -95,7 +99,7 @@ async def test_incentive(local_chain):
9599
stdout=asyncio.subprocess.PIPE,
96100
stderr=asyncio.subprocess.PIPE,
97101
)
98-
logging.info("Neuron Bob is now mining")
102+
print("Neuron Bob is now mining")
99103
await asyncio.sleep(
100104
5
101105
) # wait for 5 seconds for the metagraph to refresh with latest data
@@ -127,7 +131,7 @@ async def test_incentive(local_chain):
127131
stdout=asyncio.subprocess.PIPE,
128132
stderr=asyncio.subprocess.PIPE,
129133
)
130-
logging.info("Neuron Alice is now validating")
134+
print("Neuron Alice is now validating")
131135
await asyncio.sleep(
132136
5
133137
) # wait for 5 seconds for the metagraph and subtensor to refresh with latest data
@@ -163,7 +167,7 @@ async def test_incentive(local_chain):
163167
wait_for_finalization=True,
164168
period=5 * FAST_BLOCKS_SPEEDUP_FACTOR,
165169
)
166-
logging.info("Alice neuron set weights successfully")
170+
print("Alice neuron set weights successfully")
167171

168172
await wait_epoch(subtensor)
169173

@@ -183,4 +187,4 @@ async def test_incentive(local_chain):
183187
assert alice_neuron.stake.tao == 10_000.0
184188
assert alice_neuron.validator_trust == 1
185189

186-
logging.info("✅ Passed test_incentive")
190+
print("✅ Passed test_incentive")

tests/e2e_tests/test_liquid_alpha.py

+4-5
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,6 @@
33
from bittensor.utils.btlogging import logging
44
from tests.e2e_tests.utils.chain_interactions import (
55
add_stake,
6-
register_neuron,
76
register_subnet,
87
sudo_set_hyperparameter_bool,
98
sudo_set_hyperparameter_values,
@@ -44,16 +43,16 @@ def test_liquid_alpha(local_chain):
4443
# Verify subnet 1 created successfully
4544
assert local_chain.query("SubtensorModule", "NetworksAdded", [1]).serialize()
4645

47-
# Register a neuron to the subnet
48-
assert register_neuron(
49-
local_chain, alice_wallet, netuid
46+
# Register a neuron (Alice) to the subnet
47+
subtensor = Subtensor(network="ws://localhost:9945")
48+
assert subtensor.burned_register(
49+
alice_wallet, netuid
5050
), "Unable to register Alice as a neuron"
5151

5252
# Stake to become to top neuron after the first epoch
5353
add_stake(local_chain, alice_wallet, Balance.from_tao(100_000))
5454

5555
# Assert liquid alpha is disabled
56-
subtensor = Subtensor(network="ws://localhost:9945")
5756
assert (
5857
subtensor.get_subnet_hyperparameters(netuid=netuid).liquid_alpha_enabled
5958
is False

tests/e2e_tests/test_metagraph.py

+4-5
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,6 @@
55
from bittensor.utils.btlogging import logging
66
from tests.e2e_tests.utils.chain_interactions import (
77
add_stake,
8-
register_neuron,
98
register_subnet,
109
)
1110
from tests.e2e_tests.utils.e2e_test_utils import (
@@ -72,8 +71,8 @@ def test_metagraph(local_chain):
7271
assert len(metagraph.uids) == 0, "Metagraph is not empty"
7372

7473
# Register Bob to the subnet
75-
assert register_neuron(
76-
local_chain, bob_wallet, netuid
74+
assert subtensor.burned_register(
75+
bob_wallet, netuid
7776
), "Unable to register Bob as a neuron"
7877

7978
# Refresh the metagraph
@@ -108,8 +107,8 @@ def test_metagraph(local_chain):
108107
metagraph_pre_dave = subtensor.metagraph(netuid=1)
109108

110109
# Register Dave as a neuron
111-
assert register_neuron(
112-
local_chain, dave_wallet, netuid
110+
assert subtensor.burned_register(
111+
dave_wallet, netuid
113112
), "Unable to register Dave as a neuron"
114113

115114
metagraph.sync(subtensor=subtensor)

0 commit comments

Comments
 (0)