Skip to content

Commit

Permalink
feat: stop estimating gas in tests [APE-1020] (#16)
Browse files Browse the repository at this point in the history
  • Loading branch information
antazoey authored Jun 13, 2023
1 parent 705a869 commit 96c497a
Show file tree
Hide file tree
Showing 3 changed files with 34 additions and 22 deletions.
39 changes: 17 additions & 22 deletions ape_arbitrum/ecosystem.py
Original file line number Diff line number Diff line change
Expand Up @@ -5,10 +5,10 @@
from ape.api.networks import LOCAL_NETWORK_NAME
from ape.exceptions import ApeException
from ape.types import TransactionSignature
from ape.utils import DEFAULT_LOCAL_TRANSACTION_ACCEPTANCE_TIMEOUT
from ape_ethereum.ecosystem import Ethereum, NetworkConfig
from ape_ethereum.transactions import DynamicFeeTransaction, StaticFeeTransaction, TransactionType
from eth_typing import HexStr
from eth_utils import add_0x_prefix, decode_hex
from eth_utils import decode_hex

NETWORKS = {
# chain_id, network_id
Expand All @@ -31,9 +31,13 @@ def _create_network_config(
)


def _create_local_config(default_provider: Optional[str] = None) -> NetworkConfig:
def _create_local_config(default_provider: Optional[str] = None, **kwargs) -> NetworkConfig:
return _create_network_config(
required_confirmations=0, block_time=0, default_provider=default_provider
required_confirmations=0,
default_provider=default_provider,
transaction_acceptance_timeout=DEFAULT_LOCAL_TRANSACTION_ACCEPTANCE_TIMEOUT,
gas_limit="max",
**kwargs,
)


Expand Down Expand Up @@ -62,7 +66,7 @@ def create_transaction(self, **kwargs) -> TransactionAPI:
:class:`~ape.api.transactions.TransactionAPI`
"""

transaction_type = _get_transaction_type(kwargs.get("type"))
transaction_type = self.get_transaction_type(kwargs.get("type"))
kwargs["type"] = transaction_type.value
txn_class = _get_transaction_cls(transaction_type)

Expand Down Expand Up @@ -90,23 +94,14 @@ def create_transaction(self, **kwargs) -> TransactionAPI:

return txn_class.parse_obj(kwargs)


def _get_transaction_type(_type: Optional[Union[int, str, bytes]]) -> TransactionType:
if not _type:
return TransactionType.STATIC

if _type is None:
_type = TransactionType.STATIC.value
elif isinstance(_type, int):
_type = f"0{_type}"
elif isinstance(_type, bytes):
_type = _type.hex()

suffix = _type.replace("0x", "")
if len(suffix) == 1:
_type = f"{_type.rstrip(suffix)}0{suffix}"

return TransactionType(add_0x_prefix(HexStr(_type)))
def get_transaction_type(self, _type: Optional[Union[int, str, bytes]]) -> TransactionType:
if _type is None:
version = TransactionType.STATIC
elif not isinstance(_type, int):
version = TransactionType(self.conversion_manager.convert(_type, int))
else:
version = TransactionType(_type)
return version


def _get_transaction_cls(transaction_type: TransactionType) -> Type[TransactionAPI]:
Expand Down
5 changes: 5 additions & 0 deletions tests/conftest.py
Original file line number Diff line number Diff line change
Expand Up @@ -15,3 +15,8 @@ def accounts():
@pytest.fixture
def Contract():
return ape.Contract


@pytest.fixture
def arbitrum(networks):
return networks.arbitrum
12 changes: 12 additions & 0 deletions tests/test_ecosystem.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
import pytest
from ape_ethereum.transactions import TransactionType


def test_gas_limit(arbitrum):
assert arbitrum.config.local.gas_limit == "max"


@pytest.mark.parametrize("type", (0, "0x0"))
def test_create_transaction(arbitrum, type):
txn = arbitrum.create_transaction(type=type)
assert txn.type == TransactionType.STATIC.value

0 comments on commit 96c497a

Please sign in to comment.