Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix: transfer amount less than or equal to the balance. #36

Merged
merged 3 commits into from
Oct 29, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion cdp/wallet_address.py
Original file line number Diff line number Diff line change
Expand Up @@ -336,7 +336,7 @@ def _ensure_sufficient_balance(self, amount: Decimal, asset_id: str) -> None:
"""
current_balance = self.balance(asset_id)

if amount < current_balance:
if amount <= current_balance:
return

raise InsufficientFundsError(expected=amount, exact=current_balance)
Expand Down
21 changes: 21 additions & 0 deletions tests/test_wallet_address.py
Original file line number Diff line number Diff line change
Expand Up @@ -999,3 +999,24 @@ def test_deploy_multi_token_broadcast_api_error(mock_smart_contract, wallet_addr
mock_smart_contract.create.assert_called_once()
mock_smart_contract_instance.sign.assert_called_once_with(wallet_address_with_key.key)
mock_smart_contract_instance.broadcast.assert_called_once()

riflecode marked this conversation as resolved.
Show resolved Hide resolved

@patch("cdp.Cdp.api_clients")
def test_ensure_sufficient_balance_sufficient_full_amount(
mock_api_clients, wallet_address_factory, balance_model_factory
):
"""Test the ensure_sufficient_balance method with sufficient full amount balance."""
wallet_address = wallet_address_factory()
balance_model = balance_model_factory(
amount="1500000000000000000", network_id="base-sepolia", asset_id="eth", decimals=18
)

mock_get_balance = Mock()
mock_get_balance.return_value = balance_model
mock_api_clients.external_addresses.get_external_address_balance = mock_get_balance

wallet_address._ensure_sufficient_balance(Decimal("1.5"), "eth")

mock_get_balance.assert_called_once_with(
network_id=wallet_address.network_id, address_id=wallet_address.address_id, asset_id="eth"
)
Loading