From 467bcf9b1b2b57e0914b9acde5e99ea6cc3ce522 Mon Sep 17 00:00:00 2001 From: Andreea Popescu Date: Wed, 20 Nov 2024 10:18:50 +0000 Subject: [PATCH] add neuron certificate e2e test --- bittensor/core/subtensor.py | 2 +- tests/e2e_tests/test_neuron_certificate.py | 59 ++++++++++++++++++++++ 2 files changed, 60 insertions(+), 1 deletion(-) create mode 100644 tests/e2e_tests/test_neuron_certificate.py diff --git a/bittensor/core/subtensor.py b/bittensor/core/subtensor.py index 33dd75dbf6..959bea5756 100644 --- a/bittensor/core/subtensor.py +++ b/bittensor/core/subtensor.py @@ -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 diff --git a/tests/e2e_tests/test_neuron_certificate.py b/tests/e2e_tests/test_neuron_certificate.py new file mode 100644 index 0000000000..f4e61463c0 --- /dev/null +++ b/tests/e2e_tests/test_neuron_certificate.py @@ -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 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")