Skip to content

Commit 70b653d

Browse files
author
Roman
committed
add sync extrinsic unit test
1 parent 3aa0d78 commit 70b653d

File tree

1 file changed

+121
-0
lines changed

1 file changed

+121
-0
lines changed

tests/unit_tests/extrinsics/test_registration.py

Lines changed: 121 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -222,3 +222,124 @@ def test_burned_register_extrinsic(
222222
)
223223
# Assert
224224
assert result == expected_result, f"Test failed for test_id: {test_id}"
225+
226+
227+
def test_set_subnet_identity_extrinsic_is_success(mock_subtensor, mock_wallet, mocker):
228+
"""Verify that set_subnet_identity_extrinsic calls the correct functions and returns the correct result."""
229+
# Preps
230+
netuid = 123
231+
subnet_name = "mock_subnet_name"
232+
github_repo = "mock_github_repo"
233+
subnet_contact = "mock_subnet_contact"
234+
subnet_url = "mock_subnet_url"
235+
discord = "mock_discord"
236+
description = "mock_description"
237+
additional = "mock_additional"
238+
239+
mocked_compose_call = mocker.patch.object(mock_subtensor.substrate, "compose_call")
240+
mocked_sign_and_send_extrinsic = mocker.patch.object(
241+
mock_subtensor, "sign_and_send_extrinsic", return_value=(True, "Success")
242+
)
243+
244+
# Call
245+
result = registration.set_subnet_identity_extrinsic(
246+
subtensor=mock_subtensor,
247+
wallet=mock_wallet,
248+
netuid=netuid,
249+
subnet_name=subnet_name,
250+
github_repo=github_repo,
251+
subnet_contact=subnet_contact,
252+
subnet_url=subnet_url,
253+
discord=discord,
254+
description=description,
255+
additional=additional,
256+
)
257+
258+
# Asserts
259+
mocked_compose_call.assert_called_once_with(
260+
call_module="SubtensorModule",
261+
call_function="set_subnet_identity",
262+
call_params={
263+
"hotkey": mock_wallet.hotkey.ss58_address,
264+
"netuid": netuid,
265+
"subnet_name": "mock_subnet_name",
266+
"github_repo": "mock_github_repo",
267+
"subnet_contact": "mock_subnet_contact",
268+
"subnet_url": "mock_subnet_url",
269+
"discord": "mock_discord",
270+
"description": "mock_description",
271+
"additional": "mock_additional",
272+
},
273+
)
274+
mocked_sign_and_send_extrinsic.assert_called_once_with(
275+
call=mocked_compose_call.return_value,
276+
wallet=mock_wallet,
277+
wait_for_inclusion=False,
278+
wait_for_finalization=True,
279+
)
280+
281+
assert result == (True, "Identities for subnet 123 are set.")
282+
283+
284+
def test_set_subnet_identity_extrinsic_is_failed(mock_subtensor, mock_wallet, mocker):
285+
"""Verify that set_subnet_identity_extrinsic calls the correct functions and returns False with bad result."""
286+
# Preps
287+
netuid = 123
288+
subnet_name = "mock_subnet_name"
289+
github_repo = "mock_github_repo"
290+
subnet_contact = "mock_subnet_contact"
291+
subnet_url = "mock_subnet_url"
292+
discord = "mock_discord"
293+
description = "mock_description"
294+
additional = "mock_additional"
295+
296+
fake_error_message = "error message"
297+
298+
mocked_compose_call = mocker.patch.object(mock_subtensor.substrate, "compose_call")
299+
mocked_sign_and_send_extrinsic = mocker.patch.object(
300+
mock_subtensor,
301+
"sign_and_send_extrinsic",
302+
return_value=(False, fake_error_message),
303+
)
304+
305+
# Call
306+
result = registration.set_subnet_identity_extrinsic(
307+
subtensor=mock_subtensor,
308+
wallet=mock_wallet,
309+
netuid=netuid,
310+
subnet_name=subnet_name,
311+
github_repo=github_repo,
312+
subnet_contact=subnet_contact,
313+
subnet_url=subnet_url,
314+
discord=discord,
315+
description=description,
316+
additional=additional,
317+
)
318+
319+
# Asserts
320+
mocked_compose_call.assert_called_once_with(
321+
call_module="SubtensorModule",
322+
call_function="set_subnet_identity",
323+
call_params={
324+
"hotkey": mock_wallet.hotkey.ss58_address,
325+
"netuid": netuid,
326+
"subnet_name": "mock_subnet_name",
327+
"github_repo": "mock_github_repo",
328+
"subnet_contact": "mock_subnet_contact",
329+
"subnet_url": "mock_subnet_url",
330+
"discord": "mock_discord",
331+
"description": "mock_description",
332+
"additional": "mock_additional",
333+
},
334+
)
335+
mocked_sign_and_send_extrinsic.assert_called_once_with(
336+
call=mocked_compose_call.return_value,
337+
wallet=mock_wallet,
338+
wait_for_inclusion=False,
339+
wait_for_finalization=True,
340+
)
341+
342+
assert result == (
343+
False,
344+
f"Failed to set identity for subnet {netuid}: {fake_error_message}",
345+
)

0 commit comments

Comments
 (0)