Skip to content

Commit

Permalink
Merge pull request #2168 from coldint/feature/mvds00/fix-for-broken-c…
Browse files Browse the repository at this point in the history
…i-relating-to-epoch-calculation-and-asyncio

CI/E2E test improvements
  • Loading branch information
thewhaleking authored Jul 28, 2024
2 parents 8fe1e73 + b40165e commit 7895c02
Show file tree
Hide file tree
Showing 7 changed files with 91 additions and 63 deletions.
13 changes: 7 additions & 6 deletions tests/e2e_tests/multistep/test_axon.py
Original file line number Diff line number Diff line change
Expand Up @@ -31,12 +31,13 @@

@pytest.mark.asyncio
async def test_axon(local_chain):
netuid = 1
# Register root as Alice
alice_keypair, exec_command, wallet = setup_wallet("//Alice")
exec_command(RegisterSubnetworkCommand, ["s", "create"])

# Verify subnet 1 created successfully
assert local_chain.query("SubtensorModule", "NetworksAdded", [1]).serialize()
# Verify subnet <netuid> created successfully
assert local_chain.query("SubtensorModule", "NetworksAdded", [netuid]).serialize()

# Register a neuron to the subnet
exec_command(
Expand All @@ -45,11 +46,11 @@ async def test_axon(local_chain):
"s",
"register",
"--netuid",
"1",
str(netuid),
],
)

metagraph = bittensor.metagraph(netuid=1, network="ws://localhost:9945")
metagraph = bittensor.metagraph(netuid=netuid, network="ws://localhost:9945")

# validate one miner with ip of none
old_axon = metagraph.axons[0]
Expand All @@ -69,7 +70,7 @@ async def test_axon(local_chain):
f'"{template_path}{templates_repo}/neurons/miner.py"',
"--no_prompt",
"--netuid",
"1",
str(netuid),
"--subtensor.network",
"local",
"--subtensor.chain_endpoint",
Expand All @@ -94,7 +95,7 @@ async def test_axon(local_chain):
) # wait for 5 seconds for the metagraph to refresh with latest data

# refresh metagraph
metagraph = bittensor.metagraph(netuid=1, network="ws://localhost:9945")
metagraph = bittensor.metagraph(netuid=netuid, network="ws://localhost:9945")
updated_axon = metagraph.axons[0]
external_ip = networking.get_external_ip()

Expand Down
27 changes: 14 additions & 13 deletions tests/e2e_tests/multistep/test_dendrite.py
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@
setup_wallet,
template_path,
templates_repo,
wait_interval,
wait_epoch,
)


Expand All @@ -35,12 +35,13 @@

@pytest.mark.asyncio
async def test_dendrite(local_chain):
netuid = 1
# Register root as Alice - the subnet owner
alice_keypair, exec_command, wallet = setup_wallet("//Alice")
exec_command(RegisterSubnetworkCommand, ["s", "create"])

# Verify subnet 1 created successfully
assert local_chain.query("SubtensorModule", "NetworksAdded", [1]).serialize()
# Verify subnet <netuid> created successfully
assert local_chain.query("SubtensorModule", "NetworksAdded", [netuid]).serialize()

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

Expand All @@ -51,15 +52,15 @@ async def test_dendrite(local_chain):
"s",
"register",
"--netuid",
"1",
str(netuid),
],
)

metagraph = bittensor.metagraph(netuid=1, network="ws://localhost:9945")
metagraph = bittensor.metagraph(netuid=netuid, network="ws://localhost:9945")
subtensor = bittensor.subtensor(network="ws://localhost:9945")

# assert one neuron is Bob
assert len(subtensor.neurons(netuid=1)) == 1
assert len(subtensor.neurons(netuid=netuid)) == 1
neuron = metagraph.neurons[0]
assert neuron.hotkey == bob_keypair.ss58_address
assert neuron.coldkey == bob_keypair.ss58_address
Expand All @@ -79,7 +80,7 @@ async def test_dendrite(local_chain):
)

# refresh metagraph
metagraph = bittensor.metagraph(netuid=1, network="ws://localhost:9945")
metagraph = bittensor.metagraph(netuid=netuid, network="ws://localhost:9945")
neuron = metagraph.neurons[0]
# assert stake is 10000
assert neuron.stake.tao == 10_000.0
Expand All @@ -97,7 +98,7 @@ async def test_dendrite(local_chain):
f'"{template_path}{templates_repo}/neurons/validator.py"',
"--no_prompt",
"--netuid",
"1",
str(netuid),
"--subtensor.network",
"local",
"--subtensor.chain_endpoint",
Expand Down Expand Up @@ -129,7 +130,7 @@ async def test_dendrite(local_chain):
"root",
"register",
"--netuid",
"1",
str(netuid),
],
)

Expand All @@ -139,16 +140,16 @@ async def test_dendrite(local_chain):
"root",
"boost",
"--netuid",
"1",
str(netuid),
"--increase",
"1",
],
)
# get current block, wait until 360 blocks pass (subnet tempo)
wait_interval(360, subtensor)
# get current block, wait until next epoch
await wait_epoch(subtensor, netuid=netuid)

# refresh metagraph
metagraph = bittensor.metagraph(netuid=1, network="ws://localhost:9945")
metagraph = bittensor.metagraph(netuid=netuid, network="ws://localhost:9945")

# refresh validator neuron
neuron = metagraph.neurons[0]
Expand Down
37 changes: 19 additions & 18 deletions tests/e2e_tests/multistep/test_emissions.py
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@
setup_wallet,
template_path,
templates_repo,
wait_interval,
wait_epoch,
)

logging.basicConfig(level=logging.INFO)
Expand Down Expand Up @@ -47,11 +47,12 @@

@pytest.mark.asyncio
async def test_emissions(local_chain):
netuid = 1
# Register root as Alice - the subnet owner and validator
alice_keypair, alice_exec_command, alice_wallet = setup_wallet("//Alice")
alice_exec_command(RegisterSubnetworkCommand, ["s", "create"])
# Verify subnet 1 created successfully
assert local_chain.query("SubtensorModule", "NetworksAdded", [1]).serialize()
# Verify subnet <netuid> created successfully
assert local_chain.query("SubtensorModule", "NetworksAdded", [netuid]).serialize()

# Register Bob as miner
bob_keypair, bob_exec_command, bob_wallet = setup_wallet("//Bob")
Expand All @@ -63,7 +64,7 @@ async def test_emissions(local_chain):
"s",
"register",
"--netuid",
"1",
str(netuid),
],
)

Expand All @@ -74,13 +75,13 @@ async def test_emissions(local_chain):
"s",
"register",
"--netuid",
"1",
str(netuid),
],
)

subtensor = bittensor.subtensor(network="ws://localhost:9945")
# assert two neurons are in network
assert len(subtensor.neurons(netuid=1)) == 2
assert len(subtensor.neurons(netuid=netuid)) == 2

# Alice to stake to become to top neuron after the first epoch
alice_exec_command(
Expand All @@ -104,7 +105,7 @@ async def test_emissions(local_chain):
f'"{template_path}{templates_repo}/neurons/validator.py"',
"--no_prompt",
"--netuid",
"1",
str(netuid),
"--subtensor.network",
"local",
"--subtensor.chain_endpoint",
Expand Down Expand Up @@ -135,23 +136,23 @@ async def test_emissions(local_chain):
"root",
"register",
"--netuid",
"1",
str(netuid),
"--wait_for_inclusion",
"True",
"--wait_for_finalization",
"True",
],
)

wait_interval(360, subtensor)
await wait_epoch(subtensor, netuid=netuid)

alice_exec_command(
RootSetBoostCommand,
[
"root",
"boost",
"--netuid",
"1",
str(netuid),
"--increase",
"1000",
"--wait_for_inclusion",
Expand All @@ -168,7 +169,7 @@ async def test_emissions(local_chain):
f'"{template_path}{templates_repo}/neurons/miner.py"',
"--no_prompt",
"--netuid",
"1",
str(netuid),
"--subtensor.network",
"local",
"--subtensor.chain_endpoint",
Expand All @@ -189,7 +190,7 @@ async def test_emissions(local_chain):
stderr=asyncio.subprocess.PIPE,
)

wait_interval(360, subtensor)
await wait_epoch(subtensor)

logging.warning("Setting root set weights")
alice_exec_command(
Expand All @@ -198,7 +199,7 @@ async def test_emissions(local_chain):
"root",
"weights",
"--netuid",
"1",
str(netuid),
"--weights",
"0.3",
"--wallet.name",
Expand All @@ -223,7 +224,7 @@ async def test_emissions(local_chain):
"set",
"hyperparameters",
"--netuid",
"1",
str(netuid),
"--wallet.name",
alice_wallet.name,
"--param",
Expand All @@ -238,7 +239,7 @@ async def test_emissions(local_chain):
)

# wait epoch until for emissions to get distributed
wait_interval(360, subtensor)
await wait_epoch(subtensor)

await asyncio.sleep(
5
Expand All @@ -249,9 +250,9 @@ async def test_emissions(local_chain):

# get current emissions and validate that Alice has gotten tao
weights = [(0, [(0, 65535), (1, 65535)])]
assert subtensor.weights(netuid=1) == weights
assert subtensor.weights(netuid=netuid) == weights

neurons = subtensor.neurons(netuid=1)
neurons = subtensor.neurons(netuid=netuid)
bob = neurons[1]
alice = neurons[0]

Expand All @@ -271,5 +272,5 @@ async def test_emissions(local_chain):
assert alice.weights == [(0, 65535), (1, 65535)]

assert (
subtensor.get_emission_value_by_subnet(netuid=1) > 0
subtensor.get_emission_value_by_subnet(netuid=netuid) > 0
) # emission on this subnet is strictly greater than 0
Loading

0 comments on commit 7895c02

Please sign in to comment.