Skip to content

Commit 58a8700

Browse files
authored
Merge branch 'staging' into feat/roman/subtensor-api
2 parents 04d4c42 + 8f01580 commit 58a8700

File tree

7 files changed

+101
-107
lines changed

7 files changed

+101
-107
lines changed

README.md

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -239,18 +239,18 @@ pytest tests/unit_tests
239239
- are executed very quickly
240240
- require docker installed in OS
241241

242-
Ho to use:
242+
How to use:
243243
```bash
244244
pytest tests/e2e_tests
245245
```
246246

247-
#### TUsing `legacy runner`:
247+
#### Using `legacy runner`:
248248
- Will start compilation of the collected code in your subtensor repository
249249
- you must provide the `LOCALNET_SH_PATH` variable in the local environment with the path to the file `/scripts/localnet.sh` in the cloned repository within your OS
250250
- you can use the `BUILD_BINARY=0` variable, this will skip the copy step for each test.
251251
- you can use the `USE_DOCKER=0` variable, this will run tests using the "legacy runner", even if docker is installed in your OS
252252

253-
#### Ho to use:
253+
#### How to use:
254254
Regular e2e tests run
255255
```bash
256256
LOCALNET_SH_PATH=/path/to/your/localnet.sh pytest tests/e2e_tests

tests/e2e_tests/test_commit_reveal_v3.py

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -129,6 +129,7 @@ async def test_commit_and_reveal_weights_cr3(local_chain, subtensor, alice_walle
129129
wait_for_inclusion=True,
130130
wait_for_finalization=True,
131131
block_time=BLOCK_TIME,
132+
period=16,
132133
)
133134

134135
# Assert committing was a success

tests/e2e_tests/test_staking.py

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@
55
from tests.helpers.helpers import ApproxBalance
66
from tests.e2e_tests.utils.e2e_test_utils import wait_to_start_call
77

8-
logging.enable_info()
8+
logging.enable_debug()
99

1010

1111
def test_single_operation(subtensor, alice_wallet, bob_wallet):
@@ -162,11 +162,11 @@ def test_single_operation(subtensor, alice_wallet, bob_wallet):
162162
),
163163
}
164164

165+
# unstale all to check in later
165166
success = subtensor.unstake(
166167
wallet=alice_wallet,
167168
hotkey_ss58=bob_wallet.hotkey.ss58_address,
168169
netuid=alice_subnet_netuid,
169-
amount=stake_bob,
170170
wait_for_inclusion=True,
171171
wait_for_finalization=True,
172172
period=16,
@@ -180,6 +180,7 @@ def test_single_operation(subtensor, alice_wallet, bob_wallet):
180180
netuid=alice_subnet_netuid,
181181
)
182182

183+
# all balances have been unstaked
183184
assert stake == Balance(0).set_unit(alice_subnet_netuid)
184185

185186

tests/unit_tests/extrinsics/test_registration.py

Lines changed: 89 additions & 96 deletions
Original file line numberDiff line numberDiff line change
@@ -80,40 +80,37 @@ def test_register_extrinsic_without_pow(
8080
mocker,
8181
):
8282
# Arrange
83-
with (
84-
mocker.patch.object(
85-
mock_subtensor, "subnet_exists", return_value=subnet_exists
86-
),
87-
mocker.patch.object(
88-
mock_subtensor,
89-
"get_neuron_for_pubkey_and_subnet",
90-
return_value=mocker.MagicMock(is_null=neuron_is_null),
91-
),
92-
mocker.patch("torch.cuda.is_available", return_value=cuda_available),
93-
mocker.patch(
94-
"bittensor.utils.registration.pow._get_block_with_retry",
95-
return_value=(0, 0, "00ff11ee"),
96-
),
97-
):
98-
# Act
99-
result = registration.register_extrinsic(
100-
subtensor=mock_subtensor,
101-
wallet=mock_wallet,
102-
netuid=123,
103-
wait_for_inclusion=True,
104-
wait_for_finalization=True,
105-
max_allowed_attempts=3,
106-
output_in_place=True,
107-
cuda=True,
108-
dev_id=0,
109-
tpb=256,
110-
num_processes=None,
111-
update_interval=None,
112-
log_verbose=False,
113-
)
83+
mocker.patch.object(mock_subtensor, "subnet_exists", return_value=subnet_exists)
84+
mocker.patch.object(
85+
mock_subtensor,
86+
"get_neuron_for_pubkey_and_subnet",
87+
return_value=mocker.MagicMock(is_null=neuron_is_null),
88+
)
89+
mocker.patch("torch.cuda.is_available", return_value=cuda_available)
90+
mocker.patch(
91+
"bittensor.utils.registration.pow._get_block_with_retry",
92+
return_value=(0, 0, "00ff11ee"),
93+
)
11494

115-
# Assert
116-
assert result == expected_result, f"Test failed for test_id: {test_id}"
95+
# Act
96+
result = registration.register_extrinsic(
97+
subtensor=mock_subtensor,
98+
wallet=mock_wallet,
99+
netuid=123,
100+
wait_for_inclusion=True,
101+
wait_for_finalization=True,
102+
max_allowed_attempts=3,
103+
output_in_place=True,
104+
cuda=True,
105+
dev_id=0,
106+
tpb=256,
107+
num_processes=None,
108+
update_interval=None,
109+
log_verbose=False,
110+
)
111+
112+
# Assert
113+
assert result == expected_result, f"Test failed for test_id: {test_id}"
117114

118115

119116
@pytest.mark.parametrize(
@@ -141,48 +138,47 @@ def test_register_extrinsic_with_pow(
141138
mocker,
142139
):
143140
# Arrange
144-
with (
145-
mocker.patch(
146-
"bittensor.utils.registration.pow._solve_for_difficulty_fast",
147-
return_value=mock_pow_solution if pow_success else None,
148-
),
149-
mocker.patch(
150-
"bittensor.utils.registration.pow._solve_for_difficulty_fast_cuda",
151-
return_value=mock_pow_solution if pow_success else None,
152-
),
153-
mocker.patch(
154-
"bittensor.core.extrinsics.registration._do_pow_register",
155-
return_value=(registration_success, "HotKeyAlreadyRegisteredInSubNet"),
156-
),
157-
mocker.patch("torch.cuda.is_available", return_value=cuda),
158-
):
159-
# Act
160-
if pow_success:
161-
mock_pow_solution.is_stale.return_value = pow_stale
162-
163-
if not pow_success and hotkey_registered:
164-
mock_subtensor.is_hotkey_registered = mocker.MagicMock(
165-
return_value=hotkey_registered
166-
)
167-
168-
result = registration.register_extrinsic(
169-
subtensor=mock_subtensor,
170-
wallet=mock_wallet,
171-
netuid=123,
172-
wait_for_inclusion=True,
173-
wait_for_finalization=True,
174-
max_allowed_attempts=3,
175-
output_in_place=True,
176-
cuda=cuda,
177-
dev_id=0,
178-
tpb=256,
179-
num_processes=None,
180-
update_interval=None,
181-
log_verbose=False,
141+
mocker.patch(
142+
"bittensor.utils.registration.pow._solve_for_difficulty_fast",
143+
return_value=mock_pow_solution if pow_success else None,
144+
)
145+
mocker.patch(
146+
"bittensor.utils.registration.pow._solve_for_difficulty_fast_cuda",
147+
return_value=mock_pow_solution if pow_success else None,
148+
)
149+
mocker.patch(
150+
"bittensor.core.extrinsics.registration._do_pow_register",
151+
return_value=(registration_success, "HotKeyAlreadyRegisteredInSubNet"),
152+
)
153+
mocker.patch("torch.cuda.is_available", return_value=cuda)
154+
155+
# Act
156+
if pow_success:
157+
mock_pow_solution.is_stale.return_value = pow_stale
158+
159+
if not pow_success and hotkey_registered:
160+
mock_subtensor.is_hotkey_registered = mocker.MagicMock(
161+
return_value=hotkey_registered
182162
)
183163

184-
# Assert
185-
assert result == expected_result, f"Test failed for test_id: {test_id}."
164+
result = registration.register_extrinsic(
165+
subtensor=mock_subtensor,
166+
wallet=mock_wallet,
167+
netuid=123,
168+
wait_for_inclusion=True,
169+
wait_for_finalization=True,
170+
max_allowed_attempts=3,
171+
output_in_place=True,
172+
cuda=cuda,
173+
dev_id=0,
174+
tpb=256,
175+
num_processes=None,
176+
update_interval=None,
177+
log_verbose=False,
178+
)
179+
180+
# Assert
181+
assert result == expected_result, f"Test failed for test_id: {test_id}."
186182

187183

188184
@pytest.mark.parametrize(
@@ -209,29 +205,26 @@ def test_burned_register_extrinsic(
209205
mocker,
210206
):
211207
# Arrange
212-
with (
213-
mocker.patch.object(
214-
mock_subtensor, "subnet_exists", return_value=subnet_exists
215-
),
216-
mocker.patch.object(
217-
mock_subtensor,
218-
"get_neuron_for_pubkey_and_subnet",
219-
return_value=mocker.MagicMock(is_null=neuron_is_null),
220-
),
221-
mocker.patch(
222-
"bittensor.core.extrinsics.registration._do_burned_register",
223-
return_value=(recycle_success, "Mock error message"),
224-
),
225-
mocker.patch.object(
226-
mock_subtensor, "is_hotkey_registered", return_value=is_registered
227-
),
228-
):
229-
# Act
230-
result = registration.burned_register_extrinsic(
231-
subtensor=mock_subtensor, wallet=mock_wallet, netuid=123
232-
)
233-
# Assert
234-
assert result == expected_result, f"Test failed for test_id: {test_id}"
208+
mocker.patch.object(mock_subtensor, "subnet_exists", return_value=subnet_exists)
209+
mocker.patch.object(
210+
mock_subtensor,
211+
"get_neuron_for_pubkey_and_subnet",
212+
return_value=mocker.MagicMock(is_null=neuron_is_null),
213+
)
214+
mocker.patch(
215+
"bittensor.core.extrinsics.registration._do_burned_register",
216+
return_value=(recycle_success, "Mock error message"),
217+
)
218+
mocker.patch.object(
219+
mock_subtensor, "is_hotkey_registered", return_value=is_registered
220+
)
221+
222+
# Act
223+
result = registration.burned_register_extrinsic(
224+
subtensor=mock_subtensor, wallet=mock_wallet, netuid=123
225+
)
226+
# Assert
227+
assert result == expected_result, f"Test failed for test_id: {test_id}"
235228

236229

237230
def test_set_subnet_identity_extrinsic_is_success(mock_subtensor, mock_wallet, mocker):

tests/unit_tests/test_dendrite.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -305,7 +305,7 @@ async def test_dendrite__call__success_response(
305305
)
306306
mock_aio_response.post(
307307
f"http://127.0.0.1:666/SynapseDummy",
308-
body=expected_synapse.json(),
308+
body=expected_synapse.model_dump_json(),
309309
)
310310
synapse = await setup_dendrite.call(axon_info, synapse=input_synapse)
311311

tests/unit_tests/test_metagraph.py

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -129,10 +129,10 @@ def mock_subtensor(mocker):
129129
@pytest.fixture
130130
def metagraph_instance(mocker):
131131
metagraph = Metagraph(netuid=1337, sync=False)
132-
metagraph._assign_neurons = mocker.AsyncMock()
133-
metagraph._set_metagraph_attributes = mocker.AsyncMock()
134-
metagraph._set_weights_and_bonds = mocker.AsyncMock()
135-
metagraph._get_all_stakes_from_chain = mocker.AsyncMock()
132+
metagraph._assign_neurons = mocker.Mock()
133+
metagraph._set_metagraph_attributes = mocker.Mock()
134+
metagraph._set_weights_and_bonds = mocker.Mock()
135+
metagraph._get_all_stakes_from_chain = mocker.Mock()
136136
return metagraph
137137

138138

tests/unit_tests/test_subtensor.py

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2258,7 +2258,6 @@ def test_networks_during_connection(mock_substrate, mocker):
22582258
sub.chain_endpoint = settings.NETWORK_MAP.get(network)
22592259

22602260

2261-
@pytest.mark.asyncio
22622261
def test_get_stake_for_coldkey_and_hotkey(subtensor, mocker):
22632262
netuids = [1, 2, 3]
22642263
stake_info_dict = {

0 commit comments

Comments
 (0)