Refactor wallet transaction handling and introduce tonapi module

- Removed wallet transaction and transfer logic from the wallet domain.
- Introduced a new tonapi module to handle transactions and balance checks.
- Updated tests to reflect the new structure and ensure functionality remains intact.
- Added functionality for sending TON and USDT transfers through the tonapi module.
- Improved error handling and validation for payment balances.
- Cleaned up and organized imports across the codebase.
This commit is contained in:
bohd4nx
2026-05-20 23:42:24 +03:00
parent ae164d4fe7
commit 01a5befd87
38 changed files with 137 additions and 158 deletions
+7 -7
View File
@@ -1,4 +1,4 @@
"""Unit tests for get_wallet() — wallet address/state with separate TON and USDT balances."""
"""Verify wallet inspection returns friendly TON and USDT balances from Tonapi."""
from unittest.mock import AsyncMock, MagicMock, patch
@@ -19,9 +19,9 @@ async def test_get_wallet_returns_wallet_info(client: FragmentClient) -> None:
mock_wallet.address.to_str.return_value = FAKE_ADDRESS
with (
patch("pyfragment.domains.wallet.info.TonapiClient") as mock_tonapi,
patch("pyfragment.domains.wallet.info.WALLET_CLASSES") as mock_classes,
patch("pyfragment.domains.wallet.info.get_usdt_balance", AsyncMock(return_value=12.3456)),
patch("pyfragment.domains.tonapi.info.TonapiClient") as mock_tonapi,
patch("pyfragment.domains.tonapi.info.WALLET_CLASSES") as mock_classes,
patch("pyfragment.domains.tonapi.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)
@@ -45,9 +45,9 @@ async def test_get_wallet_balance_is_zero(client: FragmentClient) -> None:
mock_wallet.address.to_str.return_value = FAKE_ADDRESS
with (
patch("pyfragment.domains.wallet.info.TonapiClient") as mock_tonapi,
patch("pyfragment.domains.wallet.info.WALLET_CLASSES") as mock_classes,
patch("pyfragment.domains.wallet.info.get_usdt_balance", AsyncMock(return_value=0.0)),
patch("pyfragment.domains.tonapi.info.TonapiClient") as mock_tonapi,
patch("pyfragment.domains.tonapi.info.WALLET_CLASSES") as mock_classes,
patch("pyfragment.domains.tonapi.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)