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

feat: add more details to account transfer error #1860

Merged
merged 7 commits into from
Jan 11, 2024
Merged
Show file tree
Hide file tree
Changes from 3 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
6 changes: 4 additions & 2 deletions src/ape/api/accounts.py
Original file line number Diff line number Diff line change
Expand Up @@ -353,8 +353,10 @@ def prepare_transaction(self, txn: TransactionAPI) -> TransactionAPI:

if txn.total_transfer_value > self.balance:
raise AccountsError(
"Transfer value meets or exceeds account balance.\n"
"Are you using the correct provider/account combination?\n"
f"Transfer value meets or exceeds account balance "
f"for account '{self.address}' on chain '{self.provider.chain_id}' "
f"using provider '{self.provider.name}'.\n"
"Are you using the correct account / chain / provider combination?\n"
f"(transfer_value={txn.total_transfer_value}, balance={self.balance})."
)

Expand Down
3 changes: 2 additions & 1 deletion src/ape_run/_cli.py
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@

from ape import networks, project
from ape.cli import ConnectedProviderCommand, verbosity_option
from ape.cli.options import _VERBOSITY_VALUES, _create_verbosity_kwargs
from ape.cli.options import _VERBOSITY_VALUES, _create_verbosity_kwargs, network_option
from ape.exceptions import ApeException, handle_ape_exception
from ape.logging import logger
from ape.utils import get_relative_path, use_temp_sys_path
Expand Down Expand Up @@ -252,6 +252,7 @@ def _launch_console(self):
default=False,
help="Drop into interactive console session after running",
)
@network_option()
antazoey marked this conversation as resolved.
Show resolved Hide resolved
def cli(interactive):
"""
Run scripts from the "scripts/" folder of a project. A script must either define a ``main()``
Expand Down
10 changes: 8 additions & 2 deletions tests/functional/test_accounts.py
Original file line number Diff line number Diff line change
Expand Up @@ -291,8 +291,14 @@ def test_send_transaction_with_bad_nonce(sender, receiver):
sender.transfer(receiver, "1 gwei", type=0, nonce=0)


def test_send_transaction_without_enough_funds(sender, receiver):
with pytest.raises(AccountsError, match="Transfer value meets or exceeds account balance"):
def test_send_transaction_without_enough_funds(sender, receiver, eth_tester_provider, convert):
expected = (
rf"Transfer value meets or exceeds account balance for account '{sender.address}' .*"
rf"on chain '{eth_tester_provider.chain_id}' using provider '{eth_tester_provider.name}'\."
rf"\nAre you using the correct account / chain \/ provider combination\?"
rf"\n\(transfer_value=\d+, balance=\d+\)\."
)
with pytest.raises(AccountsError, match=expected):
sender.transfer(receiver, "10000000000000 ETH")


Expand Down
Loading