Skip to content

Commit

Permalink
fix: bypass balance check impersonated accounts (#2209)
Browse files Browse the repository at this point in the history
  • Loading branch information
antazoey authored Aug 12, 2024
1 parent f1bf080 commit bce0c18
Show file tree
Hide file tree
Showing 2 changed files with 17 additions and 1 deletion.
5 changes: 4 additions & 1 deletion src/ape/api/accounts.py
Original file line number Diff line number Diff line change
Expand Up @@ -393,7 +393,10 @@ def prepare_transaction(self, txn: TransactionAPI) -> TransactionAPI:

txn = self.provider.prepare_transaction(txn)

if txn.total_transfer_value > self.balance:
if (
txn.sender not in self.account_manager.test_accounts._impersonated_accounts
and txn.total_transfer_value > self.balance
):
raise AccountsError(
f"Transfer value meets or exceeds account balance "
f"for account '{self.address}' on chain '{self.provider.chain_id}' "
Expand Down
13 changes: 13 additions & 0 deletions tests/functional/test_accounts.py
Original file line number Diff line number Diff line change
Expand Up @@ -356,6 +356,19 @@ def test_send_transaction_without_enough_funds(sender, receiver, eth_tester_prov
sender.transfer(receiver, "10000000000000 ETH")


def test_send_transaction_without_enough_funds_impersonated_account(
receiver, accounts, eth_tester_provider, convert
):
address = "0x4838B106FCe9647Bdf1E7877BF73cE8B0BAD5f97" # Not a test account!
impersonated_account = ImpersonatedAccount(raw_address=address)
accounts.test_accounts._impersonated_accounts[address] = impersonated_account

# Basically, it failed anywhere else besides the AccountsError you get from not
# enough balance.
with pytest.raises(SignatureError):
impersonated_account.transfer(receiver, "10000000000000 ETH")


def test_send_transaction_sets_defaults(sender, receiver):
receipt = sender.transfer(receiver, "1 GWEI", gas_limit=None, required_confirmations=None)
assert receipt.gas_limit > 0
Expand Down

0 comments on commit bce0c18

Please sign in to comment.