mirror of
https://github.com/bohd4nx/FragmentAPI.git
synced 2026-07-25 06:14:29 +00:00
363e0719ab
- Updated version in pyproject.toml to 2026.2.3. - Refactored wallet utilities: - Moved `clean_decode` and `process_transaction` to `transaction.py`. - Created `balance.py` for balance-related functions. - Created `info.py` for wallet information retrieval. - Created `transfer.py` for sending TON and USDT transfers. - Updated tests to reflect new module structure and imports. - Added new API utility functions for handling Fragment API requests.
61 lines
2.4 KiB
Python
61 lines
2.4 KiB
Python
"""Unit tests for get_wallet() — wallet address/state with separate TON and USDT balances."""
|
|
|
|
from unittest.mock import AsyncMock, MagicMock, patch
|
|
|
|
import pytest
|
|
|
|
from pyfragment import FragmentClient, WalletInfo
|
|
from tests.shared import FAKE_ADDRESS, FAKE_BALANCE_NANOTON
|
|
|
|
# Wallet mocked tests (TON and USDT balances are returned separately)
|
|
|
|
|
|
@pytest.mark.asyncio
|
|
async def test_get_wallet_returns_wallet_info(client: FragmentClient) -> None:
|
|
mock_wallet = MagicMock()
|
|
mock_wallet.refresh = AsyncMock()
|
|
mock_wallet.balance = FAKE_BALANCE_NANOTON
|
|
mock_wallet.state = MagicMock(value="active")
|
|
mock_wallet.address.to_str.return_value = FAKE_ADDRESS
|
|
|
|
with (
|
|
patch("pyfragment.utils.wallet.info.TonapiClient") as mock_tonapi,
|
|
patch("pyfragment.utils.wallet.info.WALLET_CLASSES") as mock_classes,
|
|
patch("pyfragment.utils.wallet.info.get_usdt_balance", AsyncMock(return_value=12.3456)),
|
|
):
|
|
mock_tonapi.return_value.__aenter__ = AsyncMock(return_value=MagicMock())
|
|
mock_tonapi.return_value.__aexit__ = AsyncMock(return_value=False)
|
|
mock_classes["V5R1"].from_mnemonic.return_value = (mock_wallet, MagicMock(), None, None)
|
|
|
|
result = await client.get_wallet()
|
|
|
|
assert isinstance(result, WalletInfo)
|
|
assert result.address == FAKE_ADDRESS
|
|
assert result.state == "active"
|
|
assert result.ton_balance == round(FAKE_BALANCE_NANOTON / 1_000_000_000, 4)
|
|
assert result.usdt_balance == 12.3456
|
|
|
|
|
|
@pytest.mark.asyncio
|
|
async def test_get_wallet_balance_is_zero(client: FragmentClient) -> None:
|
|
mock_wallet = MagicMock()
|
|
mock_wallet.refresh = AsyncMock()
|
|
mock_wallet.balance = 0
|
|
mock_wallet.state = MagicMock(value="uninit")
|
|
mock_wallet.address.to_str.return_value = FAKE_ADDRESS
|
|
|
|
with (
|
|
patch("pyfragment.utils.wallet.info.TonapiClient") as mock_tonapi,
|
|
patch("pyfragment.utils.wallet.info.WALLET_CLASSES") as mock_classes,
|
|
patch("pyfragment.utils.wallet.info.get_usdt_balance", AsyncMock(return_value=0.0)),
|
|
):
|
|
mock_tonapi.return_value.__aenter__ = AsyncMock(return_value=MagicMock())
|
|
mock_tonapi.return_value.__aexit__ = AsyncMock(return_value=False)
|
|
mock_classes["V5R1"].from_mnemonic.return_value = (mock_wallet, MagicMock(), None, None)
|
|
|
|
result = await client.get_wallet()
|
|
|
|
assert result.ton_balance == 0.0
|
|
assert result.usdt_balance == 0.0
|
|
assert result.state == "uninit"
|