Skip to content

Commit 0b10f03

Browse files
authored
fix: transfer amount less than or equal to the balance. (#36)
* fix: transfer amount less than or equal to the balance. * feat: perform a test to ensure the balance is sufficient for the full amount. * feat: fix code style
1 parent 020d245 commit 0b10f03

File tree

2 files changed

+22
-1
lines changed

2 files changed

+22
-1
lines changed

cdp/wallet_address.py

+1-1
Original file line numberDiff line numberDiff line change
@@ -336,7 +336,7 @@ def _ensure_sufficient_balance(self, amount: Decimal, asset_id: str) -> None:
336336
"""
337337
current_balance = self.balance(asset_id)
338338

339-
if amount < current_balance:
339+
if amount <= current_balance:
340340
return
341341

342342
raise InsufficientFundsError(expected=amount, exact=current_balance)

tests/test_wallet_address.py

+21
Original file line numberDiff line numberDiff line change
@@ -999,3 +999,24 @@ def test_deploy_multi_token_broadcast_api_error(mock_smart_contract, wallet_addr
999999
mock_smart_contract.create.assert_called_once()
10001000
mock_smart_contract_instance.sign.assert_called_once_with(wallet_address_with_key.key)
10011001
mock_smart_contract_instance.broadcast.assert_called_once()
1002+
1003+
1004+
@patch("cdp.Cdp.api_clients")
1005+
def test_ensure_sufficient_balance_sufficient_full_amount(
1006+
mock_api_clients, wallet_address_factory, balance_model_factory
1007+
):
1008+
"""Test the ensure_sufficient_balance method with sufficient full amount balance."""
1009+
wallet_address = wallet_address_factory()
1010+
balance_model = balance_model_factory(
1011+
amount="1500000000000000000", network_id="base-sepolia", asset_id="eth", decimals=18
1012+
)
1013+
1014+
mock_get_balance = Mock()
1015+
mock_get_balance.return_value = balance_model
1016+
mock_api_clients.external_addresses.get_external_address_balance = mock_get_balance
1017+
1018+
wallet_address._ensure_sufficient_balance(Decimal("1.5"), "eth")
1019+
1020+
mock_get_balance.assert_called_once_with(
1021+
network_id=wallet_address.network_id, address_id=wallet_address.address_id, asset_id="eth"
1022+
)

0 commit comments

Comments
 (0)