Skip to content

Commit

Permalink
add neuron certificate e2e test
Browse files Browse the repository at this point in the history
  • Loading branch information
andreea-popescu-reef committed Nov 20, 2024
1 parent ab54fdd commit 467bcf9
Show file tree
Hide file tree
Showing 2 changed files with 60 additions and 1 deletion.
2 changes: 1 addition & 1 deletion bittensor/core/subtensor.py
Original file line number Diff line number Diff line change
Expand Up @@ -1199,7 +1199,7 @@ def get_neuron_certificate(
try:
serialized_certificate = certificate.serialize()
if serialized_certificate:
return serialized_certificate.get("certificate", None)
return chr(serialized_certificate["algorithm"]) + serialized_certificate["public_key"]
except AttributeError:
return None

Expand Down
59 changes: 59 additions & 0 deletions tests/e2e_tests/test_neuron_certificate.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,59 @@
import pytest
from bittensor.core.subtensor import Subtensor
from bittensor.core.axon import Axon
from bittensor.utils.btlogging import logging
from tests.e2e_tests.utils.chain_interactions import (
wait_interval,
register_subnet,
register_neuron,
)
from tests.e2e_tests.utils.e2e_test_utils import (
setup_wallet,
)


@pytest.mark.asyncio
async def test_neuron_certificate(local_chain):
"""
Tests the metagraph
Steps:
1. Register a subnet through Alice
2. Serve Alice axon with neuron certificate
3. Verify neuron certificate can be retrieved
Raises:
AssertionError: If any of the checks or verifications fail
"""
logging.info("Testing neuron_certificate")
netuid = 1

# Register root as Alice - the subnet owner and validator
alice_keypair, alice_wallet = setup_wallet("//Alice")
register_subnet(local_chain, alice_wallet)

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

# Register Alice as a neuron on the subnet
register_neuron(local_chain, alice_wallet, netuid)

subtensor = Subtensor(network="ws://localhost:9945")

# Serve Alice's axon with a certificate
axon = Axon(wallet=alice_wallet)
encoded_certificate = "?FAKE_ALICE_CERT"
axon.serve(netuid=netuid, subtensor=subtensor, certificate=encoded_certificate)

await wait_interval(tempo=1, subtensor=subtensor, netuid=netuid)

# Verify we are getting the correct certificate
assert (
subtensor.get_neuron_certificate(
netuid=netuid, hotkey=alice_keypair.ss58_address
)
== encoded_certificate
)

logging.info("✅ Passed test_neuron_certificate")

0 comments on commit 467bcf9

Please sign in to comment.