diff --git a/src/ape/api/providers.py b/src/ape/api/providers.py index eff2e305c0..2783b5aa09 100644 --- a/src/ape/api/providers.py +++ b/src/ape/api/providers.py @@ -1433,7 +1433,7 @@ def prepare_transaction(self, txn: TransactionAPI) -> TransactionAPI: elif gas_limit == "max": txn.gas_limit = self.max_gas - elif gas_limit is not None: + elif gas_limit is not None and isinstance(gas_limit, int): txn.gas_limit = gas_limit if txn.required_confirmations is None: diff --git a/tests/functional/test_ecosystem.py b/tests/functional/test_ecosystem.py index 00ed82ff11..0ab36bdc6b 100644 --- a/tests/functional/test_ecosystem.py +++ b/tests/functional/test_ecosystem.py @@ -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) +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 diff --git a/tests/functional/test_provider.py b/tests/functional/test_provider.py index a93a71fe6b..feeac64cd1 100644 --- a/tests/functional/test_provider.py +++ b/tests/functional/test_provider.py @@ -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): @@ -253,9 +254,11 @@ def test_get_code(eth_tester_provider, vyper_contract_instance): ) -def test_prepare_static_tx_with_max_gas(eth_tester_provider, vyper_contract_instance, owner): - tx = vyper_contract_instance.setNumber.as_transaction(123, sender=owner, type=0) - assert tx.type == 0 - assert tx.gas_limit == eth_tester_provider.max_gas +@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