-
Notifications
You must be signed in to change notification settings - Fork 362
/
Copy pathtest_neuron_certificate.py
54 lines (44 loc) · 1.76 KB
/
test_neuron_certificate.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
import pytest
from bittensor.core.axon import Axon
from bittensor.utils.btlogging import logging
from tests.e2e_tests.utils.chain_interactions import (
wait_interval,
)
@pytest.mark.asyncio
async def test_neuron_certificate(subtensor, alice_wallet):
"""
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 = 2
# Register root as Alice - the subnet owner and validator
assert subtensor.register_subnet(alice_wallet)
# Verify subnet <netuid> created successfully
assert subtensor.subnet_exists(netuid), "Subnet wasn't created successfully"
# Register Alice as a neuron on the subnet
assert subtensor.burned_register(
alice_wallet, netuid
), "Unable to register Alice as a neuron"
# 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_wallet.hotkey.ss58_address,
)
== encoded_certificate
)
all_certs_query = subtensor.get_all_neuron_certificates(netuid=netuid)
assert alice_wallet.hotkey.ss58_address in all_certs_query.keys()
assert all_certs_query[alice_wallet.hotkey.ss58_address] == encoded_certificate
logging.info("✅ Passed test_neuron_certificate")