Skip to content

Commit 8501f30

Browse files
committed
Tests
1 parent d37d740 commit 8501f30

File tree

2 files changed

+0
-124
lines changed

2 files changed

+0
-124
lines changed

tests/unit_tests/extrinsics/test_async_weights.py

Lines changed: 0 additions & 47 deletions
Original file line numberDiff line numberDiff line change
@@ -278,53 +278,6 @@ async def test_set_weights_extrinsic_exception(subtensor, mocker):
278278
assert message == "Unexpected error"
279279

280280

281-
@pytest.mark.asyncio
282-
async def test_set_weights_extrinsic_if_use_torch(subtensor, mocker):
283-
"""Tests set_weights_extrinsic when use_torch is True."""
284-
# Preps
285-
fake_wallet = mocker.Mock(autospec=Wallet)
286-
fake_netuid = 1
287-
fake_uids = [1, 2, 3]
288-
fake_weights = [0.1, 0.2, 0.7]
289-
290-
mocked_use_torch = mocker.patch.object(
291-
async_weights, "use_torch", return_value=True
292-
)
293-
mocked_torch_tensor = mocker.patch.object(
294-
async_weights.torch, "tensor", return_value=mocker.Mock()
295-
)
296-
297-
mocked_do_set_weights = mocker.patch.object(
298-
async_weights, "_do_set_weights", return_value=(False, "Test error message")
299-
)
300-
mocked_convert_weights_and_uids_for_emit = mocker.patch.object(
301-
async_weights.weight_utils,
302-
"convert_weights_and_uids_for_emit",
303-
return_value=(mocker.Mock(), mocker.Mock()),
304-
)
305-
306-
# Call
307-
result, message = await async_weights.set_weights_extrinsic(
308-
subtensor=subtensor,
309-
wallet=fake_wallet,
310-
netuid=fake_netuid,
311-
uids=fake_uids,
312-
weights=fake_weights,
313-
wait_for_inclusion=True,
314-
wait_for_finalization=True,
315-
)
316-
317-
# Asserts
318-
mocked_do_set_weights.assert_called_once()
319-
mocked_use_torch.assert_called_once()
320-
mocked_convert_weights_and_uids_for_emit.assert_called()
321-
mocked_torch_tensor.assert_called_with(
322-
fake_weights, dtype=async_weights.torch.float32
323-
)
324-
assert result is False
325-
assert message == "Test error message"
326-
327-
328281
@pytest.mark.asyncio
329282
async def test_do_commit_weights_success(subtensor, mocker):
330283
"""Tests _do_commit_weights when the commit is successful."""

tests/unit_tests/extrinsics/test_commit_reveal.py

Lines changed: 0 additions & 77 deletions
Original file line numberDiff line numberDiff line change
@@ -150,81 +150,6 @@ def test_do_commit_reveal_v3_failure_due_to_error(mocker, subtensor):
150150
assert result == (False, "Formatted error")
151151

152152

153-
def test_commit_reveal_v3_extrinsic_success_with_torch(mocker, subtensor, hyperparams):
154-
"""Test successful commit-reveal with torch tensors."""
155-
# Preps
156-
fake_wallet = mocker.Mock(autospec=subtensor_module.Wallet)
157-
fake_netuid = 1
158-
fake_uids = torch.tensor([1, 2, 3], dtype=torch.int64)
159-
fake_weights = torch.tensor([0.1, 0.2, 0.7], dtype=torch.float32)
160-
fake_commit_for_reveal = b"mock_commit_for_reveal"
161-
fake_reveal_round = 1
162-
163-
# Mocks
164-
mocker.patch.object(commit_reveal, "use_torch", return_value=True)
165-
166-
mocked_uids = mocker.Mock()
167-
mocked_weights = mocker.Mock()
168-
mocked_convert_weights_and_uids_for_emit = mocker.patch.object(
169-
commit_reveal,
170-
"convert_weights_and_uids_for_emit",
171-
return_value=(mocked_uids, mocked_weights),
172-
)
173-
mocked_get_subnet_reveal_period_epochs = mocker.patch.object(
174-
subtensor, "get_subnet_reveal_period_epochs"
175-
)
176-
mocked_get_encrypted_commit = mocker.patch.object(
177-
commit_reveal,
178-
"get_encrypted_commit",
179-
return_value=(fake_commit_for_reveal, fake_reveal_round),
180-
)
181-
mock_do_commit_reveal_v3 = mocker.patch.object(
182-
commit_reveal, "_do_commit_reveal_v3", return_value=(True, "Success")
183-
)
184-
mock_block = mocker.patch.object(subtensor, "get_current_block", return_value=1)
185-
mock_hyperparams = mocker.patch.object(
186-
subtensor,
187-
"get_subnet_hyperparameters",
188-
return_value=hyperparams,
189-
)
190-
191-
# Call
192-
success, message = commit_reveal.commit_reveal_v3_extrinsic(
193-
subtensor=subtensor,
194-
wallet=fake_wallet,
195-
netuid=fake_netuid,
196-
uids=fake_uids,
197-
weights=fake_weights,
198-
wait_for_inclusion=True,
199-
wait_for_finalization=True,
200-
)
201-
202-
# Asserts
203-
assert success is True
204-
assert message == "reveal_round:1"
205-
mocked_convert_weights_and_uids_for_emit.assert_called_once_with(
206-
fake_uids, fake_weights
207-
)
208-
mocked_get_encrypted_commit.assert_called_once_with(
209-
uids=mocked_uids,
210-
weights=mocked_weights,
211-
subnet_reveal_period_epochs=mock_hyperparams.return_value.commit_reveal_weights_interval,
212-
version_key=commit_reveal.version_as_int,
213-
tempo=mock_hyperparams.return_value.tempo,
214-
netuid=fake_netuid,
215-
current_block=mock_block.return_value,
216-
)
217-
mock_do_commit_reveal_v3.assert_called_once_with(
218-
self=subtensor,
219-
wallet=fake_wallet,
220-
netuid=fake_netuid,
221-
commit=fake_commit_for_reveal,
222-
reveal_round=fake_reveal_round,
223-
wait_for_inclusion=True,
224-
wait_for_finalization=True,
225-
)
226-
227-
228153
def test_commit_reveal_v3_extrinsic_success_with_numpy(mocker, subtensor, hyperparams):
229154
"""Test successful commit-reveal with numpy arrays."""
230155
# Preps
@@ -233,7 +158,6 @@ def test_commit_reveal_v3_extrinsic_success_with_numpy(mocker, subtensor, hyperp
233158
fake_uids = np.array([1, 2, 3], dtype=np.int64)
234159
fake_weights = np.array([0.1, 0.2, 0.7], dtype=np.float32)
235160

236-
mocker.patch.object(commit_reveal, "use_torch", return_value=False)
237161
mock_convert = mocker.patch.object(
238162
commit_reveal,
239163
"convert_weights_and_uids_for_emit",
@@ -282,7 +206,6 @@ def test_commit_reveal_v3_extrinsic_response_false(mocker, subtensor, hyperparam
282206
fake_reveal_round = 1
283207

284208
# Mocks
285-
mocker.patch.object(commit_reveal, "use_torch", return_value=True)
286209
mocker.patch.object(
287210
commit_reveal,
288211
"convert_weights_and_uids_for_emit",

0 commit comments

Comments
 (0)