Skip to content

Commit c81c030

Browse files
committed
Tests
1 parent e6e987f commit c81c030

File tree

3 files changed

+61
-13
lines changed

3 files changed

+61
-13
lines changed

bittensor/core/extrinsics/asyncex/transfer.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -53,7 +53,7 @@ async def _do_transfer(
5353
else:
5454
call_params["keep_alive"] = False
5555
else:
56-
call_params["amount"] = amount.rao
56+
call_params["value"] = amount.rao
5757
if keep_alive:
5858
call_function = "transfer_keep_alive"
5959
else:

tests/unit_tests/extrinsics/asyncex/test_transfer.py

Lines changed: 27 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -3,12 +3,32 @@
33
from bittensor.utils.balance import Balance
44

55

6+
@pytest.mark.parametrize(
7+
"amount,keep_alive,call_function,call_params",
8+
[
9+
(
10+
Balance(1),
11+
True,
12+
"transfer_keep_alive",
13+
{"dest": "SS58PUBLICKEY", "value": Balance(1).rao},
14+
),
15+
(None, True, "transfer_all", {"dest": "SS58PUBLICKEY", "keep_alive": True}),
16+
(None, False, "transfer_all", {"dest": "SS58PUBLICKEY", "keep_alive": False}),
17+
(
18+
Balance(1),
19+
False,
20+
"transfer_allow_death",
21+
{"dest": "SS58PUBLICKEY", "value": Balance(1).rao},
22+
),
23+
],
24+
)
625
@pytest.mark.asyncio
7-
async def test_do_transfer_success(subtensor, fake_wallet, mocker):
26+
async def test_do_transfer_success(
27+
subtensor, fake_wallet, mocker, amount, keep_alive, call_function, call_params
28+
):
829
"""Tests _do_transfer when the transfer is successful."""
930
# Preps
10-
fake_destination = "destination_address"
11-
fake_amount = mocker.Mock(autospec=Balance, rao=1000)
31+
fake_destination = "SS58PUBLICKEY"
1232
fake_block_hash = "fake_block_hash"
1333

1434
mocker.patch.object(subtensor.substrate, "compose_call")
@@ -24,16 +44,17 @@ async def test_do_transfer_success(subtensor, fake_wallet, mocker):
2444
subtensor=subtensor,
2545
wallet=fake_wallet,
2646
destination=fake_destination,
27-
amount=fake_amount,
47+
amount=amount,
48+
keep_alive=keep_alive,
2849
wait_for_inclusion=True,
2950
wait_for_finalization=True,
3051
)
3152

3253
# Asserts
3354
subtensor.substrate.compose_call.assert_awaited_once_with(
3455
call_module="Balances",
35-
call_function="transfer_keep_alive",
36-
call_params={"dest": fake_destination, "value": fake_amount.rao},
56+
call_function=call_function,
57+
call_params=call_params,
3758
)
3859

3960
subtensor.sign_and_send_extrinsic.assert_awaited_once_with(

tests/unit_tests/extrinsics/test_transfer.py

Lines changed: 33 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1,12 +1,34 @@
11
from bittensor.core.extrinsics.transfer import _do_transfer
22
from bittensor.utils.balance import Balance
33

4-
5-
def test_do_transfer_is_success_true(subtensor, fake_wallet, mocker):
4+
import pytest
5+
6+
7+
@pytest.mark.parametrize(
8+
"amount,keep_alive,call_function,call_params",
9+
[
10+
(
11+
Balance(1),
12+
True,
13+
"transfer_keep_alive",
14+
{"dest": "SS58PUBLICKEY", "value": Balance(1).rao},
15+
),
16+
(None, True, "transfer_all", {"dest": "SS58PUBLICKEY", "keep_alive": True}),
17+
(None, False, "transfer_all", {"dest": "SS58PUBLICKEY", "keep_alive": False}),
18+
(
19+
Balance(1),
20+
False,
21+
"transfer_allow_death",
22+
{"dest": "SS58PUBLICKEY", "value": Balance(1).rao},
23+
),
24+
],
25+
)
26+
def test_do_transfer_is_success_true(
27+
subtensor, fake_wallet, mocker, amount, keep_alive, call_function, call_params
28+
):
629
"""Successful do_transfer call."""
730
# Prep
831
fake_dest = "SS58PUBLICKEY"
9-
fake_transfer_balance = Balance(1)
1032
fake_wait_for_inclusion = True
1133
fake_wait_for_finalization = True
1234

@@ -18,16 +40,17 @@ def test_do_transfer_is_success_true(subtensor, fake_wallet, mocker):
1840
subtensor,
1941
fake_wallet,
2042
fake_dest,
21-
fake_transfer_balance,
43+
amount,
44+
keep_alive,
2245
fake_wait_for_inclusion,
2346
fake_wait_for_finalization,
2447
)
2548

2649
# Asserts
2750
subtensor.substrate.compose_call.assert_called_once_with(
2851
call_module="Balances",
29-
call_function="transfer_keep_alive",
30-
call_params={"dest": fake_dest, "value": fake_transfer_balance.rao},
52+
call_function=call_function,
53+
call_params=call_params,
3154
)
3255
subtensor.sign_and_send_extrinsic.assert_called_once_with(
3356
call=subtensor.substrate.compose_call.return_value,
@@ -45,6 +68,7 @@ def test_do_transfer_is_success_false(subtensor, fake_wallet, mocker):
4568
# Prep
4669
fake_dest = "SS58PUBLICKEY"
4770
fake_transfer_balance = Balance(1)
71+
keep_alive = True
4872
fake_wait_for_inclusion = True
4973
fake_wait_for_finalization = True
5074

@@ -57,6 +81,7 @@ def test_do_transfer_is_success_false(subtensor, fake_wallet, mocker):
5781
fake_wallet,
5882
fake_dest,
5983
fake_transfer_balance,
84+
keep_alive,
6085
fake_wait_for_inclusion,
6186
fake_wait_for_finalization,
6287
)
@@ -83,6 +108,7 @@ def test_do_transfer_no_waits(subtensor, fake_wallet, mocker):
83108
# Prep
84109
fake_dest = "SS58PUBLICKEY"
85110
fake_transfer_balance = Balance(1)
111+
keep_alive = True
86112
fake_wait_for_inclusion = False
87113
fake_wait_for_finalization = False
88114

@@ -96,6 +122,7 @@ def test_do_transfer_no_waits(subtensor, fake_wallet, mocker):
96122
fake_wallet,
97123
fake_dest,
98124
fake_transfer_balance,
125+
keep_alive,
99126
fake_wait_for_inclusion,
100127
fake_wait_for_finalization,
101128
)

0 commit comments

Comments
 (0)