Skip to content

Commit 8086324

Browse files
author
Roman
committed
add async extrinsic unit test
1 parent 70b653d commit 8086324

File tree

1 file changed

+131
-0
lines changed

1 file changed

+131
-0
lines changed

tests/unit_tests/extrinsics/asyncex/test_registration.py

Lines changed: 131 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -447,3 +447,134 @@ async def is_stale_side_effect(*_, **__):
447447
wait_for_finalization=True,
448448
)
449449
assert result is False
450+
451+
452+
@pytest.mark.asyncio
453+
async def test_set_subnet_identity_extrinsic_is_success(subtensor, mocker):
454+
"""Verify that set_subnet_identity_extrinsic calls the correct functions and returns the correct result."""
455+
# Preps
456+
wallet = mocker.MagicMock(autospec=Wallet)
457+
netuid = 123
458+
subnet_name = "mock_subnet_name"
459+
github_repo = "mock_github_repo"
460+
subnet_contact = "mock_subnet_contact"
461+
subnet_url = "mock_subnet_url"
462+
discord = "mock_discord"
463+
description = "mock_description"
464+
additional = "mock_additional"
465+
466+
mocked_compose_call = mocker.patch.object(subtensor.substrate, "compose_call")
467+
468+
fake_response = mocker.Mock()
469+
fake_response.is_success = mocker.AsyncMock(return_value=True)()
470+
mocked_submit_extrinsic = mocker.patch.object(
471+
subtensor.substrate, "submit_extrinsic", return_value=fake_response
472+
)
473+
474+
# Call
475+
result = await async_registration.set_subnet_identity_extrinsic(
476+
subtensor=subtensor,
477+
wallet=wallet,
478+
netuid=netuid,
479+
subnet_name=subnet_name,
480+
github_repo=github_repo,
481+
subnet_contact=subnet_contact,
482+
subnet_url=subnet_url,
483+
discord=discord,
484+
description=description,
485+
additional=additional,
486+
)
487+
488+
# Asserts
489+
mocked_compose_call.assert_awaited_once_with(
490+
call_module="SubtensorModule",
491+
call_function="set_subnet_identity",
492+
call_params={
493+
"hotkey": wallet.hotkey.ss58_address,
494+
"netuid": netuid,
495+
"subnet_name": subnet_name,
496+
"github_repo": github_repo,
497+
"subnet_contact": subnet_contact,
498+
"subnet_url": subnet_url,
499+
"discord": discord,
500+
"description": description,
501+
"additional": additional,
502+
},
503+
)
504+
mocked_submit_extrinsic.assert_awaited_once_with(
505+
call=mocked_compose_call.return_value,
506+
wallet=wallet,
507+
wait_for_inclusion=False,
508+
wait_for_finalization=True,
509+
)
510+
511+
assert result == (True, "Identities for subnet 123 are set.")
512+
513+
514+
@pytest.mark.asyncio
515+
async def test_set_subnet_identity_extrinsic_is_failed(subtensor, mocker):
516+
"""Verify that set_subnet_identity_extrinsic calls the correct functions and returns False with bad result."""
517+
# Preps
518+
wallet = mocker.MagicMock(autospec=Wallet)
519+
netuid = 123
520+
subnet_name = "mock_subnet_name"
521+
github_repo = "mock_github_repo"
522+
subnet_contact = "mock_subnet_contact"
523+
subnet_url = "mock_subnet_url"
524+
discord = "mock_discord"
525+
description = "mock_description"
526+
additional = "mock_additional"
527+
fake_error_message = "error message"
528+
529+
mocked_compose_call = mocker.patch.object(subtensor.substrate, "compose_call")
530+
531+
fake_response = mocker.Mock()
532+
fake_response.is_success = mocker.AsyncMock(return_value=False)()
533+
fake_response.error_message = mocker.AsyncMock(return_value=fake_error_message)()
534+
mocked_submit_extrinsic = mocker.patch.object(
535+
subtensor.substrate, "submit_extrinsic", return_value=fake_response
536+
)
537+
538+
# Call
539+
result = await async_registration.set_subnet_identity_extrinsic(
540+
subtensor=subtensor,
541+
wallet=wallet,
542+
netuid=netuid,
543+
subnet_name=subnet_name,
544+
github_repo=github_repo,
545+
subnet_contact=subnet_contact,
546+
subnet_url=subnet_url,
547+
discord=discord,
548+
description=description,
549+
additional=additional,
550+
wait_for_inclusion=True,
551+
wait_for_finalization=True,
552+
)
553+
554+
# Asserts
555+
mocked_compose_call.assert_awaited_once_with(
556+
call_module="SubtensorModule",
557+
call_function="set_subnet_identity",
558+
call_params={
559+
"hotkey": wallet.hotkey.ss58_address,
560+
"netuid": netuid,
561+
"subnet_name": subnet_name,
562+
"github_repo": github_repo,
563+
"subnet_contact": subnet_contact,
564+
"subnet_url": subnet_url,
565+
"discord": discord,
566+
"description": description,
567+
"additional": additional,
568+
},
569+
)
570+
mocked_submit_extrinsic.assert_awaited_once_with(
571+
call=mocked_compose_call.return_value,
572+
wallet=wallet,
573+
wait_for_inclusion=True,
574+
wait_for_finalization=True,
575+
)
576+
577+
assert result == (
578+
False,
579+
f"Failed to set identity for subnet {netuid}: {fake_error_message}",
580+
)

0 commit comments

Comments
 (0)