Skip to content

Commit 26d20cf

Browse files
authored
Merge pull request #2192 from opentensor/fix/abe/enhancing-e2e-tests
Enhances e2e tests to contain assertions & logging
2 parents 85a3cf0 + c1a5d75 commit 26d20cf

19 files changed

+259
-168
lines changed

tests/e2e_tests/multistep/test_axon.py

Lines changed: 9 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -4,11 +4,12 @@
44
import pytest
55

66
import bittensor
7-
from bittensor.utils import networking
7+
from bittensor import logging
88
from bittensor.commands import (
99
RegisterCommand,
1010
RegisterSubnetworkCommand,
1111
)
12+
from bittensor.utils import networking
1213
from tests.e2e_tests.utils import (
1314
setup_wallet,
1415
template_path,
@@ -31,13 +32,16 @@
3132

3233
@pytest.mark.asyncio
3334
async def test_axon(local_chain):
35+
logging.info("Testing test_axon")
3436
netuid = 1
3537
# Register root as Alice
3638
alice_keypair, exec_command, wallet = setup_wallet("//Alice")
3739
exec_command(RegisterSubnetworkCommand, ["s", "create"])
3840

3941
# Verify subnet <netuid> created successfully
40-
assert local_chain.query("SubtensorModule", "NetworksAdded", [netuid]).serialize()
42+
assert local_chain.query(
43+
"SubtensorModule", "NetworksAdded", [netuid]
44+
).serialize(), "Subnet wasn't created successfully"
4145

4246
# Register a neuron to the subnet
4347
exec_command(
@@ -55,7 +59,7 @@ async def test_axon(local_chain):
5559
# validate one miner with ip of none
5660
old_axon = metagraph.axons[0]
5761

58-
assert len(metagraph.axons) == 1
62+
assert len(metagraph.axons) == 1, "Expected 1 axon, but got len(metagraph.axons)"
5963
assert old_axon.hotkey == alice_keypair.ss58_address
6064
assert old_axon.coldkey == alice_keypair.ss58_address
6165
assert old_axon.ip == "0.0.0.0"
@@ -89,7 +93,7 @@ async def test_axon(local_chain):
8993
stdout=asyncio.subprocess.PIPE,
9094
stderr=asyncio.subprocess.PIPE,
9195
)
92-
96+
logging.info("Neuron Alice is now mining")
9397
await asyncio.sleep(
9498
5
9599
) # wait for 5 seconds for the metagraph to refresh with latest data
@@ -105,3 +109,4 @@ async def test_axon(local_chain):
105109
assert updated_axon.port == 8091
106110
assert updated_axon.hotkey == alice_keypair.ss58_address
107111
assert updated_axon.coldkey == alice_keypair.ss58_address
112+
logging.info("Passed test_axon")

tests/e2e_tests/multistep/test_dendrite.py

Lines changed: 11 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -1,16 +1,16 @@
11
import asyncio
2-
import logging
32
import sys
43

54
import pytest
65

76
import bittensor
7+
from bittensor import logging
88
from bittensor.commands import (
99
RegisterCommand,
1010
RegisterSubnetworkCommand,
11-
StakeCommand,
1211
RootRegisterCommand,
1312
RootSetBoostCommand,
13+
StakeCommand,
1414
)
1515
from tests.e2e_tests.utils import (
1616
setup_wallet,
@@ -19,9 +19,6 @@
1919
wait_epoch,
2020
)
2121

22-
23-
logging.basicConfig(level=logging.INFO)
24-
2522
"""
2623
Test the dendrites mechanism.
2724
@@ -35,13 +32,16 @@
3532

3633
@pytest.mark.asyncio
3734
async def test_dendrite(local_chain):
35+
logging.info("Testing test_dendrite")
3836
netuid = 1
3937
# Register root as Alice - the subnet owner
4038
alice_keypair, exec_command, wallet = setup_wallet("//Alice")
4139
exec_command(RegisterSubnetworkCommand, ["s", "create"])
4240

4341
# Verify subnet <netuid> created successfully
44-
assert local_chain.query("SubtensorModule", "NetworksAdded", [netuid]).serialize()
42+
assert local_chain.query(
43+
"SubtensorModule", "NetworksAdded", [netuid]
44+
).serialize(), "Subnet wasn't created successfully"
4545

4646
bob_keypair, exec_command, wallet_path = setup_wallet("//Bob")
4747

@@ -83,7 +83,9 @@ async def test_dendrite(local_chain):
8383
metagraph = bittensor.metagraph(netuid=netuid, network="ws://localhost:9945")
8484
neuron = metagraph.neurons[0]
8585
# assert stake is 10000
86-
assert neuron.stake.tao == 10_000.0
86+
assert (
87+
neuron.stake.tao == 10_000.0
88+
), f"Expected 10_000.0 staked TAO, but got {neuron.stake.tao}"
8789

8890
# assert neuron is not validator
8991
assert neuron.active is True
@@ -118,7 +120,7 @@ async def test_dendrite(local_chain):
118120
stdout=asyncio.subprocess.PIPE,
119121
stderr=asyncio.subprocess.PIPE,
120122
)
121-
123+
logging.info("Neuron Alice is now validating")
122124
await asyncio.sleep(
123125
5
124126
) # wait for 5 seconds for the metagraph and subtensor to refresh with latest data
@@ -159,3 +161,4 @@ async def test_dendrite(local_chain):
159161
assert neuron.validator_permit is True
160162
assert neuron.hotkey == bob_keypair.ss58_address
161163
assert neuron.coldkey == bob_keypair.ss58_address
164+
logging.info("Passed test_dendrite")

tests/e2e_tests/multistep/test_emissions.py

Lines changed: 16 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -1,19 +1,19 @@
11
import asyncio
2-
import logging
32
import sys
43

54
import pytest
65

76
import bittensor
7+
from bittensor import logging
88
from bittensor.commands import (
99
RegisterCommand,
1010
RegisterSubnetworkCommand,
11-
StakeCommand,
1211
RootRegisterCommand,
1312
RootSetBoostCommand,
14-
SubnetSudoCommand,
1513
RootSetWeightsCommand,
1614
SetTakeCommand,
15+
StakeCommand,
16+
SubnetSudoCommand,
1717
)
1818
from tests.e2e_tests.utils import (
1919
setup_wallet,
@@ -22,8 +22,6 @@
2222
wait_epoch,
2323
)
2424

25-
logging.basicConfig(level=logging.INFO)
26-
2725
"""
2826
Test the emissions mechanism.
2927
@@ -46,13 +44,17 @@
4644

4745

4846
@pytest.mark.asyncio
47+
@pytest.mark.skip
4948
async def test_emissions(local_chain):
49+
logging.info("Testing test_emissions")
5050
netuid = 1
5151
# Register root as Alice - the subnet owner and validator
5252
alice_keypair, alice_exec_command, alice_wallet = setup_wallet("//Alice")
5353
alice_exec_command(RegisterSubnetworkCommand, ["s", "create"])
5454
# Verify subnet <netuid> created successfully
55-
assert local_chain.query("SubtensorModule", "NetworksAdded", [netuid]).serialize()
55+
assert local_chain.query(
56+
"SubtensorModule", "NetworksAdded", [netuid]
57+
).serialize(), "Subnet wasn't created successfully"
5658

5759
# Register Bob as miner
5860
bob_keypair, bob_exec_command, bob_wallet = setup_wallet("//Bob")
@@ -126,7 +128,7 @@ async def test_emissions(local_chain):
126128
stdout=asyncio.subprocess.PIPE,
127129
stderr=asyncio.subprocess.PIPE,
128130
)
129-
131+
logging.info("Neuron Alice is now validating")
130132
await asyncio.sleep(5)
131133

132134
# register validator with root network
@@ -189,7 +191,7 @@ async def test_emissions(local_chain):
189191
stdout=asyncio.subprocess.PIPE,
190192
stderr=asyncio.subprocess.PIPE,
191193
)
192-
194+
logging.info("Neuron Bob is now mining")
193195
await wait_epoch(subtensor)
194196

195197
logging.warning("Setting root set weights")
@@ -250,7 +252,9 @@ async def test_emissions(local_chain):
250252

251253
# get current emissions and validate that Alice has gotten tao
252254
weights = [(0, [(0, 65535), (1, 65535)])]
253-
assert subtensor.weights(netuid=netuid) == weights
255+
assert (
256+
subtensor.weights(netuid=netuid) == weights
257+
), "Weights set vs weights in subtensor don't match"
254258

255259
neurons = subtensor.neurons(netuid=netuid)
256260
bob = neurons[1]
@@ -273,4 +277,7 @@ async def test_emissions(local_chain):
273277

274278
assert (
275279
subtensor.get_emission_value_by_subnet(netuid=netuid) > 0
280+
), (
281+
"Emissions are not greated than 0"
276282
) # emission on this subnet is strictly greater than 0
283+
logging.info("Passed test_emissions")

tests/e2e_tests/multistep/test_incentive.py

Lines changed: 13 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -1,16 +1,16 @@
11
import asyncio
2-
import logging
32
import sys
43

54
import pytest
65

76
import bittensor
7+
from bittensor import logging
88
from bittensor.commands import (
99
RegisterCommand,
1010
RegisterSubnetworkCommand,
11-
StakeCommand,
1211
RootRegisterCommand,
1312
RootSetBoostCommand,
13+
StakeCommand,
1414
)
1515
from tests.e2e_tests.utils import (
1616
setup_wallet,
@@ -19,8 +19,6 @@
1919
wait_epoch,
2020
)
2121

22-
logging.basicConfig(level=logging.INFO)
23-
2422
"""
2523
Test the incentive mechanism.
2624
@@ -43,12 +41,15 @@
4341

4442
@pytest.mark.asyncio
4543
async def test_incentive(local_chain):
44+
logging.info("Testing test_incentive")
4645
netuid = 1
4746
# Register root as Alice - the subnet owner and validator
4847
alice_keypair, alice_exec_command, alice_wallet = setup_wallet("//Alice")
4948
alice_exec_command(RegisterSubnetworkCommand, ["s", "create"])
5049
# Verify subnet <netuid> created successfully
51-
assert local_chain.query("SubtensorModule", "NetworksAdded", [netuid]).serialize()
50+
assert local_chain.query(
51+
"SubtensorModule", "NetworksAdded", [netuid]
52+
).serialize(), "Subnet wasn't created successfully"
5253

5354
# Register Bob as miner
5455
bob_keypair, bob_exec_command, bob_wallet = setup_wallet("//Bob")
@@ -77,7 +78,9 @@ async def test_incentive(local_chain):
7778

7879
subtensor = bittensor.subtensor(network="ws://localhost:9945")
7980
# assert two neurons are in network
80-
assert len(subtensor.neurons(netuid=netuid)) == 2
81+
assert (
82+
len(subtensor.neurons(netuid=netuid)) == 2
83+
), "Alice & Bob not registered in the subnet"
8184

8285
# Alice to stake to become to top neuron after the first epoch
8386
alice_exec_command(
@@ -117,7 +120,7 @@ async def test_incentive(local_chain):
117120
stdout=asyncio.subprocess.PIPE,
118121
stderr=asyncio.subprocess.PIPE,
119122
)
120-
123+
logging.info("Neuron Bob is now mining")
121124
await asyncio.sleep(
122125
5
123126
) # wait for 5 seconds for the metagraph to refresh with latest data
@@ -150,7 +153,7 @@ async def test_incentive(local_chain):
150153
stdout=asyncio.subprocess.PIPE,
151154
stderr=asyncio.subprocess.PIPE,
152155
)
153-
156+
logging.info("Neuron Alice is now validating")
154157
await asyncio.sleep(
155158
5
156159
) # wait for 5 seconds for the metagraph and subtensor to refresh with latest data
@@ -221,6 +224,7 @@ async def test_incentive(local_chain):
221224
wait_for_inclusion=True,
222225
wait_for_finalization=True,
223226
)
227+
logging.info("Alice neuron set weights successfully")
224228

225229
# wait epoch until weight go into effect
226230
await wait_epoch(subtensor)
@@ -240,3 +244,4 @@ async def test_incentive(local_chain):
240244
assert alice_neuron.dividends == 1
241245
assert alice_neuron.stake.tao == 10_000.0
242246
assert alice_neuron.validator_trust == 1
247+
logging.info("Passed test_incentive")

tests/e2e_tests/multistep/test_last_tx_block.py

Lines changed: 0 additions & 51 deletions
This file was deleted.

tests/e2e_tests/subcommands/delegation/test_set_delegate_take.py

Lines changed: 11 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1,23 +1,27 @@
1-
from bittensor.commands.delegates import SetTakeCommand, NominateCommand
1+
from bittensor import logging
2+
from bittensor.commands.delegates import NominateCommand, SetTakeCommand
23
from bittensor.commands.network import RegisterSubnetworkCommand
34
from bittensor.commands.register import RegisterCommand
45
from bittensor.commands.root import RootRegisterCommand
5-
66
from tests.e2e_tests.utils import setup_wallet
77

88

99
def test_set_delegate_increase_take(local_chain):
10+
logging.info("Testing test_set_delegate_increase_take")
1011
# Register root as Alice
1112
keypair, exec_command, wallet = setup_wallet("//Alice")
1213
exec_command(RootRegisterCommand, ["root", "register"])
1314

1415
# Create subnet 1 and verify created successfully
15-
assert not (local_chain.query("SubtensorModule", "NetworksAdded", [1]).serialize())
16+
assert not (
17+
local_chain.query("SubtensorModule", "NetworksAdded", [1]).serialize()
18+
), "Subnet is already registered"
1619

1720
exec_command(RegisterSubnetworkCommand, ["s", "create"])
18-
assert local_chain.query("SubtensorModule", "NetworksAdded", [1])
1921

20-
assert local_chain.query("SubtensorModule", "NetworksAdded", [1]).serialize()
22+
assert local_chain.query(
23+
"SubtensorModule", "NetworksAdded", [1]
24+
).serialize(), "Subnet wasn't registered"
2125

2226
# Register and nominate Bob
2327
keypair, exec_command, wallet = setup_wallet("//Bob")
@@ -53,4 +57,5 @@ def test_set_delegate_increase_take(local_chain):
5357
exec_command(SetTakeCommand, ["r", "set_take", "--take", "0.15"])
5458
assert local_chain.query(
5559
"SubtensorModule", "Delegates", [keypair.ss58_address]
56-
).value == int(0.15 * 65535)
60+
).value == int(0.15 * 65535), "Take value set incorrectly"
61+
logging.info("Passed test_set_delegate_increase_take")

0 commit comments

Comments
 (0)