Skip to content

Commit 7ce2b7d

Browse files
committed
metagraph e2e
1 parent 56caa1e commit 7ce2b7d

File tree

2 files changed

+25
-25
lines changed

2 files changed

+25
-25
lines changed

tests/e2e_tests/test_metagraph.py

Lines changed: 23 additions & 23 deletions
Original file line numberDiff line numberDiff line change
@@ -48,7 +48,7 @@ def test_metagraph(local_chain):
4848
AssertionError: If any of the checks or verifications fail
4949
"""
5050
logging.console.info("Testing test_metagraph_command")
51-
netuid = 1
51+
netuid = 2
5252

5353
# Register Alice, Bob, and Dave
5454
alice_keypair, alice_wallet = setup_wallet("//Alice")
@@ -60,15 +60,15 @@ def test_metagraph(local_chain):
6060

6161
# Verify subnet was created successfully
6262
assert local_chain.query(
63-
"SubtensorModule", "NetworksAdded", [1]
63+
"SubtensorModule", "NetworksAdded", [2]
6464
).serialize(), "Subnet wasn't created successfully"
6565

6666
# Initialize metagraph
6767
subtensor = Subtensor(network="ws://localhost:9945")
68-
metagraph = subtensor.metagraph(netuid=1)
68+
metagraph = subtensor.metagraph(netuid=2)
6969

7070
# Assert metagraph is empty
71-
assert len(metagraph.uids) == 0, "Metagraph is not empty"
71+
assert len(metagraph.uids) == 1, "Metagraph is not empty"
7272

7373
# Register Bob to the subnet
7474
assert subtensor.burned_register(
@@ -79,14 +79,14 @@ def test_metagraph(local_chain):
7979
metagraph.sync(subtensor=subtensor)
8080

8181
# Assert metagraph has Bob neuron
82-
assert len(metagraph.uids) == 1, "Metagraph doesn't have exactly 1 neuron"
82+
assert len(metagraph.uids) == 2, "Metagraph doesn't have exactly 2 neurons"
8383
assert (
84-
metagraph.hotkeys[0] == bob_keypair.ss58_address
84+
metagraph.hotkeys[1] == bob_keypair.ss58_address
8585
), "Bob's hotkey doesn't match in metagraph"
86-
assert len(metagraph.coldkeys) == 1, "Metagraph doesn't have exactly 1 coldkey"
87-
assert metagraph.n.max() == 1, "Metagraph's max n is not 1"
88-
assert metagraph.n.min() == 1, "Metagraph's min n is not 1"
89-
assert len(metagraph.addresses) == 1, "Metagraph doesn't have exactly 1 address"
86+
assert len(metagraph.coldkeys) == 2, "Metagraph doesn't have exactly 2 coldkeys"
87+
assert metagraph.n.max() == 2, "Metagraph's max n is not 2"
88+
assert metagraph.n.min() == 2, "Metagraph's min n is not 2"
89+
assert len(metagraph.addresses) == 2, "Metagraph doesn't have exactly 2 addresses"
9090

9191
# Fetch UID of Bob
9292
uid = subtensor.get_uid_for_hotkey_on_subnet(
@@ -104,7 +104,7 @@ def test_metagraph(local_chain):
104104
), "Neuron info of Bob doesn't match b/w metagraph & subtensor"
105105

106106
# Create pre_dave metagraph for future verifications
107-
metagraph_pre_dave = subtensor.metagraph(netuid=1)
107+
metagraph_pre_dave = subtensor.metagraph(netuid=2)
108108

109109
# Register Dave as a neuron
110110
assert subtensor.burned_register(
@@ -115,32 +115,32 @@ def test_metagraph(local_chain):
115115

116116
# Assert metagraph now includes Dave's neuron
117117
assert (
118-
len(metagraph.uids) == 2
119-
), "Metagraph doesn't have exactly 2 neurons post Dave"
118+
len(metagraph.uids) == 3
119+
), "Metagraph doesn't have exactly 3 neurons post Dave"
120120
assert (
121-
metagraph.hotkeys[1] == dave_keypair.ss58_address
121+
metagraph.hotkeys[2] == dave_keypair.ss58_address
122122
), "Neuron's hotkey in metagraph doesn't match"
123123
assert (
124-
len(metagraph.coldkeys) == 2
125-
), "Metagraph doesn't have exactly 2 coldkeys post Dave"
126-
assert metagraph.n.max() == 2, "Metagraph's max n is not 2 post Dave"
127-
assert metagraph.n.min() == 2, "Metagraph's min n is not 2 post Dave"
128-
assert len(metagraph.addresses) == 2, "Metagraph doesn't have 2 addresses post Dave"
124+
len(metagraph.coldkeys) == 3
125+
), "Metagraph doesn't have exactly 3 coldkeys post Dave"
126+
assert metagraph.n.max() == 3, "Metagraph's max n is not 3 post Dave"
127+
assert metagraph.n.min() == 3, "Metagraph's min n is not 3 post Dave"
128+
assert len(metagraph.addresses) == 3, "Metagraph doesn't have 3 addresses post Dave"
129129

130130
# Test staking with low balance
131131
assert not add_stake(
132-
local_chain, dave_wallet, Balance.from_tao(10_000)
132+
local_chain, dave_wallet, Balance.from_tao(10_000), netuid=netuid
133133
), "Low balance stake should fail"
134134

135135
# Add stake by Bob
136136
assert add_stake(
137-
local_chain, bob_wallet, Balance.from_tao(10_000)
137+
local_chain, bob_wallet, Balance.from_tao(10_000), netuid=netuid
138138
), "Failed to add stake for Bob"
139139

140140
# Assert stake is added after updating metagraph
141141
metagraph.sync(subtensor=subtensor)
142-
assert metagraph.neurons[0].stake == Balance.from_tao(
143-
10_000
142+
assert metagraph.neurons[1].stake > Balance.from_tao(
143+
0
144144
), "Bob's stake not updated in metagraph"
145145

146146
# Test the save() and load() mechanism

tests/e2e_tests/utils/chain_interactions.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -71,15 +71,15 @@ def sudo_set_hyperparameter_values(
7171

7272

7373
def add_stake(
74-
substrate: "SubstrateInterface", wallet: "Wallet", amount: "Balance"
74+
substrate: "SubstrateInterface", wallet: "Wallet", amount: "Balance", netuid: int
7575
) -> bool:
7676
"""
7777
Adds stake to a hotkey using SubtensorModule. Mimics command of adding stake
7878
"""
7979
stake_call = substrate.compose_call(
8080
call_module="SubtensorModule",
8181
call_function="add_stake",
82-
call_params={"hotkey": wallet.hotkey.ss58_address, "amount_staked": amount.rao},
82+
call_params={"hotkey": wallet.hotkey.ss58_address, "amount_staked": amount.rao, "netuid": netuid},
8383
)
8484
extrinsic = substrate.create_signed_extrinsic(
8585
call=stake_call, keypair=wallet.coldkey

0 commit comments

Comments
 (0)