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: issue with custom errors on estimate gas and static fee txns [APE-1421] #1680

Merged
merged 15 commits into from
Sep 29, 2023
9 changes: 8 additions & 1 deletion src/ape/api/providers.py
Original file line number Diff line number Diff line change
Expand Up @@ -1420,7 +1420,8 @@ def prepare_transaction(self, txn: TransactionAPI) -> TransactionAPI:
txn.max_fee = int(self.base_fee * multiplier + txn.max_priority_fee)
# else: Assume user specified the correct amount or txn will fail and waste gas

if txn.gas_limit is None:
gas_limit = self.network.gas_limit if txn.gas_limit is None else txn.gas_limit
if gas_limit in (None, "auto"):
multiplier = self.network.auto_gas_multiplier
if multiplier != 1.0:
gas = min(int(self.estimate_gas_cost(txn) * multiplier), self.max_gas)
Expand All @@ -1429,6 +1430,12 @@ def prepare_transaction(self, txn: TransactionAPI) -> TransactionAPI:

txn.gas_limit = gas

elif gas_limit == "max":
txn.gas_limit = self.max_gas
antazoey marked this conversation as resolved.
Show resolved Hide resolved

elif gas_limit is not None and isinstance(gas_limit, int):
txn.gas_limit = gas_limit

if txn.required_confirmations is None:
txn.required_confirmations = self.network.required_confirmations
elif not isinstance(txn.required_confirmations, int) or txn.required_confirmations < 0:
Expand Down
16 changes: 16 additions & 0 deletions tests/functional/test_ecosystem.py
Original file line number Diff line number Diff line change
Expand Up @@ -307,3 +307,19 @@ def test_decode_return_data_non_empty_padding_bytes(ethereum):
)
with pytest.raises(DecodingError):
ethereum.decode_returndata(abi, raw_data)


@pytest.mark.parametrize("type_", TransactionType)
antazoey marked this conversation as resolved.
Show resolved Hide resolved
def test_create_transaction_uses_network_gas_limit(type_, ethereum, eth_tester_provider, owner):
tx = ethereum.create_transaction(type=type_.value, sender=owner.address)
assert tx.type == type_
assert tx.gas_limit == eth_tester_provider.max_gas


@pytest.mark.parametrize("type_", TransactionType)
def test_encode_transaction(type_, ethereum, vyper_contract_instance, owner, eth_tester_provider):
abi = vyper_contract_instance.contract_type.methods[0]
actual = ethereum.encode_transaction(
vyper_contract_instance.address, abi, sender=owner.address, type=type_.value
)
assert actual.gas_limit == eth_tester_provider.max_gas
11 changes: 11 additions & 0 deletions tests/functional/test_provider.py
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@
from ape.exceptions import BlockNotFoundError, ContractLogicError, TransactionNotFoundError
from ape.types import LogFilter
from ape.utils import DEFAULT_TEST_CHAIN_ID
from ape_ethereum.transactions import TransactionType


def test_uri(eth_tester_provider):
Expand Down Expand Up @@ -251,3 +252,13 @@ def test_get_code(eth_tester_provider, vyper_contract_instance):
assert eth_tester_provider.get_code(address) == eth_tester_provider.get_code(
address, block_id=1
)


@pytest.mark.parametrize("type_", TransactionType)
def test_prepare_static_tx_with_max_gas(type_, eth_tester_provider, ethereum, owner):
tx = ethereum.create_transaction(type=type_.value, sender=owner.address)
tx.gas_limit = None # Undo set from validator
assert tx.gas_limit is None, "Test setup failed - couldn't clear tx gas limit."

actual = eth_tester_provider.prepare_transaction(tx)
assert actual.gas_limit == eth_tester_provider.max_gas
Loading