Skip to content

Commit 54f7193

Browse files
author
Roman
committed
add tests for extrinsics
1 parent e226f14 commit 54f7193

File tree

2 files changed

+180
-0
lines changed

2 files changed

+180
-0
lines changed
Lines changed: 94 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,94 @@
1+
import pytest
2+
3+
from bittensor.core.extrinsics.asyncex import children
4+
5+
6+
@pytest.mark.asyncio
7+
async def test_set_children_extrinsic(subtensor, mocker, fake_wallet):
8+
"""Test that set_children_extrinsic correctly constructs and submits the extrinsic."""
9+
# Preps
10+
hotkey = "fake hotkey"
11+
netuid = 123
12+
fake_children = [
13+
(
14+
1.0,
15+
"5C4hrfjw9DjXZTzV3MwzrrAr9P1MJhSrvWGWqi1eSuyUpnhM",
16+
),
17+
]
18+
19+
substrate = subtensor.substrate.__aenter__.return_value
20+
substrate.compose_call = mocker.AsyncMock()
21+
mocked_sign_and_send_extrinsic = mocker.patch.object(
22+
subtensor, "sign_and_send_extrinsic", return_value=(True, "")
23+
)
24+
25+
# Call
26+
success, message = await children.set_children_extrinsic(
27+
subtensor=subtensor,
28+
wallet=fake_wallet,
29+
hotkey=hotkey,
30+
netuid=netuid,
31+
children=fake_children,
32+
)
33+
34+
# Asserts
35+
substrate.compose_call.assert_awaited_once_with(
36+
call_module="SubtensorModule",
37+
call_function="set_children",
38+
call_params={
39+
"children": [
40+
(
41+
18446744073709551615,
42+
"5C4hrfjw9DjXZTzV3MwzrrAr9P1MJhSrvWGWqi1eSuyUpnhM",
43+
),
44+
],
45+
"hotkey": "fake hotkey",
46+
"netuid": netuid,
47+
},
48+
)
49+
50+
mocked_sign_and_send_extrinsic.assert_awaited_once_with(
51+
call=substrate.compose_call.return_value,
52+
wallet=fake_wallet,
53+
wait_for_inclusion=True,
54+
wait_for_finalization=False,
55+
period=None,
56+
raise_error=False,
57+
)
58+
59+
assert success is True
60+
assert "Success" in message
61+
62+
63+
@pytest.mark.asyncio
64+
async def test_root_set_pending_childkey_cooldown_extrinsic(
65+
subtensor, mocker, fake_wallet
66+
):
67+
"""Verify root_set_pending_childkey_cooldown_extrinsic extrinsic."""
68+
# Preps
69+
cooldown = 100
70+
71+
substrate = subtensor.substrate.__aenter__.return_value
72+
substrate.compose_call = mocker.AsyncMock()
73+
mocked_sign_and_send_extrinsic = mocker.patch.object(
74+
subtensor, "sign_and_send_extrinsic", return_value=(True, "")
75+
)
76+
77+
# Call
78+
success, message = await children.root_set_pending_childkey_cooldown_extrinsic(
79+
subtensor=subtensor,
80+
wallet=fake_wallet,
81+
cooldown=cooldown,
82+
)
83+
# Asserts
84+
85+
substrate.compose_call.call_count == 2
86+
mocked_sign_and_send_extrinsic.assert_awaited_once_with(
87+
call=substrate.compose_call.return_value,
88+
wallet=fake_wallet,
89+
wait_for_inclusion=True,
90+
wait_for_finalization=False,
91+
period=None,
92+
)
93+
assert success is True
94+
assert "Success" in message
Lines changed: 86 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,86 @@
1+
from bittensor.core.extrinsics import children
2+
3+
4+
def test_set_children_extrinsic(subtensor, mocker, fake_wallet):
5+
"""Test that set_children_extrinsic correctly constructs and submits the extrinsic."""
6+
# Preps
7+
hotkey = "fake hotkey"
8+
netuid = 123
9+
fake_children = [
10+
(
11+
1.0,
12+
"5C4hrfjw9DjXZTzV3MwzrrAr9P1MJhSrvWGWqi1eSuyUpnhM",
13+
),
14+
]
15+
16+
subtensor.substrate.compose_call = mocker.Mock()
17+
mocked_sign_and_send_extrinsic = mocker.patch.object(
18+
subtensor, "sign_and_send_extrinsic", return_value=(True, "")
19+
)
20+
21+
# Call
22+
success, message = children.set_children_extrinsic(
23+
subtensor=subtensor,
24+
wallet=fake_wallet,
25+
hotkey=hotkey,
26+
netuid=netuid,
27+
children=fake_children,
28+
)
29+
30+
# Asserts
31+
subtensor.substrate.compose_call.assert_called_once_with(
32+
call_module="SubtensorModule",
33+
call_function="set_children",
34+
call_params={
35+
"children": [
36+
(
37+
18446744073709551615,
38+
"5C4hrfjw9DjXZTzV3MwzrrAr9P1MJhSrvWGWqi1eSuyUpnhM",
39+
),
40+
],
41+
"hotkey": "fake hotkey",
42+
"netuid": netuid,
43+
},
44+
)
45+
46+
mocked_sign_and_send_extrinsic.assert_called_once_with(
47+
call=subtensor.substrate.compose_call.return_value,
48+
wallet=fake_wallet,
49+
wait_for_inclusion=True,
50+
wait_for_finalization=False,
51+
period=None,
52+
raise_error=False,
53+
)
54+
55+
assert success is True
56+
assert "Success" in message
57+
58+
59+
def test_root_set_pending_childkey_cooldown_extrinsic(subtensor, mocker, fake_wallet):
60+
"""Verify root_set_pending_childkey_cooldown_extrinsic extrinsic."""
61+
# Preps
62+
cooldown = 100
63+
64+
subtensor.substrate.compose_call = mocker.Mock()
65+
mocked_sign_and_send_extrinsic = mocker.patch.object(
66+
subtensor, "sign_and_send_extrinsic", return_value=(True, "")
67+
)
68+
69+
# Call
70+
success, message = children.root_set_pending_childkey_cooldown_extrinsic(
71+
subtensor=subtensor,
72+
wallet=fake_wallet,
73+
cooldown=cooldown,
74+
)
75+
# Asserts
76+
77+
subtensor.substrate.compose_call.call_count == 2
78+
mocked_sign_and_send_extrinsic.assert_called_once_with(
79+
call=subtensor.substrate.compose_call.return_value,
80+
wallet=fake_wallet,
81+
wait_for_inclusion=True,
82+
wait_for_finalization=False,
83+
period=None,
84+
)
85+
assert success is True
86+
assert "Success" in message

0 commit comments

Comments
 (0)