Skip to content

Commit

Permalink
feat: add more details to account transfer error (#1860)
Browse files Browse the repository at this point in the history
Co-authored-by: El De-dog-lo <[email protected]>
  • Loading branch information
antazoey and fubuloubu authored Jan 11, 2024
1 parent 4e61a70 commit c175387
Show file tree
Hide file tree
Showing 2 changed files with 12 additions and 4 deletions.
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
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

0 comments on commit c175387

Please sign in to comment.