|
| 1 | +import typing |
| 2 | + |
| 3 | +from bittensor_wallet import Wallet |
| 4 | +import pytest |
| 5 | + |
1 | 6 | from bittensor.utils.balance import Balance
|
2 | 7 | from bittensor import logging
|
3 | 8 |
|
| 9 | +if typing.TYPE_CHECKING: |
| 10 | + from bittensor.core.subtensor_api import SubtensorApi |
| 11 | + |
4 | 12 | logging.set_trace()
|
5 | 13 |
|
6 | 14 |
|
7 |
| -def test_transfer(subtensor, alice_wallet): |
| 15 | +def test_transfer(subtensor: "SubtensorApi", alice_wallet): |
8 | 16 | """
|
9 | 17 | Test the transfer mechanism on the chain
|
10 | 18 |
|
@@ -47,3 +55,90 @@ def test_transfer(subtensor, alice_wallet):
|
47 | 55 | )
|
48 | 56 |
|
49 | 57 | print("✅ Passed test_transfer")
|
| 58 | + |
| 59 | + |
| 60 | +def test_transfer_all(subtensor: "Subtensor", alice_wallet): |
| 61 | + # create two dummy accounts we can drain |
| 62 | + dummy_account_1 = Wallet(path="/tmp/bittensor-dummy-account-1") |
| 63 | + dummy_account_2 = Wallet(path="/tmp/bittensor-dummy-account-2") |
| 64 | + dummy_account_1.create_new_coldkey(use_password=False, overwrite=True) |
| 65 | + dummy_account_2.create_new_coldkey(use_password=False, overwrite=True) |
| 66 | + |
| 67 | + # fund the first dummy account |
| 68 | + assert subtensor.transfer( |
| 69 | + alice_wallet, |
| 70 | + dest=dummy_account_1.coldkeypub.ss58_address, |
| 71 | + amount=Balance.from_tao(2.0), |
| 72 | + wait_for_finalization=True, |
| 73 | + wait_for_inclusion=True, |
| 74 | + ) |
| 75 | + # Account details before transfer |
| 76 | + existential_deposit = subtensor.get_existential_deposit() |
| 77 | + assert subtensor.transfer( |
| 78 | + wallet=dummy_account_1, |
| 79 | + dest=dummy_account_2.coldkeypub.ss58_address, |
| 80 | + amount=None, |
| 81 | + transfer_all=True, |
| 82 | + wait_for_finalization=True, |
| 83 | + wait_for_inclusion=True, |
| 84 | + keep_alive=True, |
| 85 | + ) |
| 86 | + balance_after = subtensor.get_balance(dummy_account_1.coldkeypub.ss58_address) |
| 87 | + assert balance_after == existential_deposit |
| 88 | + assert subtensor.transfer( |
| 89 | + wallet=dummy_account_2, |
| 90 | + dest=alice_wallet.coldkeypub.ss58_address, |
| 91 | + amount=None, |
| 92 | + transfer_all=True, |
| 93 | + wait_for_inclusion=True, |
| 94 | + wait_for_finalization=True, |
| 95 | + keep_alive=False, |
| 96 | + ) |
| 97 | + balance_after = subtensor.get_balance(dummy_account_2.coldkeypub.ss58_address) |
| 98 | + assert balance_after == Balance(0) |
| 99 | + |
| 100 | + |
| 101 | +@pytest.mark.asyncio |
| 102 | +async def test_async_transfer(async_subtensor: "SubtensorApi", alice_wallet): |
| 103 | + # create two dummy accounts we can drain |
| 104 | + dummy_account_1 = Wallet(path="/tmp/bittensor-dummy-account-3") |
| 105 | + dummy_account_2 = Wallet(path="/tmp/bittensor-dummy-account-4") |
| 106 | + dummy_account_1.create_new_coldkey(use_password=False, overwrite=True) |
| 107 | + dummy_account_2.create_new_coldkey(use_password=False, overwrite=True) |
| 108 | + |
| 109 | + # fund the first dummy account |
| 110 | + assert await async_subtensor.transfer( |
| 111 | + alice_wallet, |
| 112 | + dest=dummy_account_1.coldkeypub.ss58_address, |
| 113 | + amount=Balance.from_tao(2.0), |
| 114 | + wait_for_finalization=True, |
| 115 | + wait_for_inclusion=True, |
| 116 | + ) |
| 117 | + # Account details before transfer |
| 118 | + existential_deposit = await async_subtensor.get_existential_deposit() |
| 119 | + assert await async_subtensor.transfer( |
| 120 | + wallet=dummy_account_1, |
| 121 | + dest=dummy_account_2.coldkeypub.ss58_address, |
| 122 | + amount=None, |
| 123 | + transfer_all=True, |
| 124 | + wait_for_finalization=True, |
| 125 | + wait_for_inclusion=True, |
| 126 | + keep_alive=True, |
| 127 | + ) |
| 128 | + balance_after = await async_subtensor.get_balance( |
| 129 | + dummy_account_1.coldkeypub.ss58_address |
| 130 | + ) |
| 131 | + assert balance_after == existential_deposit |
| 132 | + assert await async_subtensor.transfer( |
| 133 | + wallet=dummy_account_2, |
| 134 | + dest=alice_wallet.coldkeypub.ss58_address, |
| 135 | + amount=None, |
| 136 | + transfer_all=True, |
| 137 | + wait_for_inclusion=True, |
| 138 | + wait_for_finalization=True, |
| 139 | + keep_alive=False, |
| 140 | + ) |
| 141 | + balance_after = await async_subtensor.get_balance( |
| 142 | + dummy_account_2.coldkeypub.ss58_address |
| 143 | + ) |
| 144 | + assert balance_after == Balance(0) |
0 commit comments