Skip to content

Commit

Permalink
test: t driven investigation
Browse files Browse the repository at this point in the history
  • Loading branch information
antazoey committed Sep 28, 2023
1 parent b7f7f5c commit f7b5ffb
Show file tree
Hide file tree
Showing 3 changed files with 24 additions and 5 deletions.
2 changes: 1 addition & 1 deletion src/ape/api/providers.py
Original file line number Diff line number Diff line change
Expand Up @@ -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:
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)
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: 7 additions & 4 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 @@ -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

0 comments on commit f7b5ffb

Please sign in to comment.