Skip to content

Commit

Permalink
fix: update testnet to goerli (#5)
Browse files Browse the repository at this point in the history
  • Loading branch information
antazoey authored Oct 12, 2022
1 parent a239d09 commit dcc743e
Show file tree
Hide file tree
Showing 4 changed files with 71 additions and 33 deletions.
2 changes: 1 addition & 1 deletion ape_arbitrum/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -21,10 +21,10 @@ def ecosystems():
def networks():
for network_name, network_params in NETWORKS.items():
yield "arbitrum", network_name, create_network_type(*network_params)
yield "arbitrum", f"{network_name}-fork", NetworkAPI

# NOTE: This works for development providers, as they get chain_id from themselves
yield "arbitrum", LOCAL_NETWORK_NAME, NetworkAPI
yield "arbitrum", "mainnet-fork", NetworkAPI


@plugins.register(plugins.ProviderPlugin)
Expand Down
99 changes: 69 additions & 30 deletions ape_arbitrum/ecosystem.py
Original file line number Diff line number Diff line change
@@ -1,5 +1,9 @@
from typing import Optional, Type, Union, cast

from ape.api import TransactionAPI
from ape.api.config import PluginConfig
from ape.api.networks import LOCAL_NETWORK_NAME
from ape.exceptions import ApeException
from ape.types import TransactionSignature
from ape_ethereum.ecosystem import Ethereum, NetworkConfig
from ape_ethereum.transactions import StaticFeeTransaction, TransactionType
Expand All @@ -9,52 +13,59 @@
NETWORKS = {
# chain_id, network_id
"mainnet": (42161, 42161),
"testnet": (421611, 421611),
"goerli": (421613, 421613),
}


class ApeArbitrumError(ApeException):
"""
Raised in the ape-arbitrum plugin.
"""


def _create_network_config(
required_confirmations: int = 1, block_time: int = 1, **kwargs
) -> NetworkConfig:
# Helper method to isolate `type: ignore` comments.
return NetworkConfig(
required_confirmations=required_confirmations, block_time=block_time, **kwargs
) # type: ignore


def _create_local_config(default_provider: Optional[str] = None) -> NetworkConfig:
return _create_network_config(
required_confirmations=0, block_time=0, default_provider=default_provider
)


class ArbitrumConfig(PluginConfig):
mainnet: NetworkConfig = NetworkConfig(required_confirmations=1, block_time=1) # type: ignore
local: NetworkConfig = NetworkConfig(default_provider="test") # type: ignore
default_network: str = "mainnet"
mainnet: NetworkConfig = _create_network_config()
mainnet_fork: NetworkConfig = _create_local_config()
goerli: NetworkConfig = _create_network_config()
goerli_fork: NetworkConfig = _create_local_config()
local: NetworkConfig = _create_local_config(default_provider="test")
default_network: str = LOCAL_NETWORK_NAME


class Arbitrum(Ethereum):
@property
def config(self) -> ArbitrumConfig: # type: ignore
return self.config_manager.get_config("arbitrum") # type: ignore
return cast(ArbitrumConfig, self.config_manager.get_config("arbitrum"))

def create_transaction(self, **kwargs) -> TransactionAPI:
"""
Returns a transaction using the given constructor kwargs.
Overridden because does not support
**kwargs: Kwargs for the transaction class.
Returns:
:class:`~ape.api.transactions.TransactionAPI`
"""

transaction_types = {
TransactionType.STATIC: StaticFeeTransaction,
}

if "type" in kwargs:
type_kwarg = kwargs["type"]
if type_kwarg is None:
type_kwarg = TransactionType.STATIC.value
elif isinstance(type_kwarg, int):
type_kwarg = f"0{type_kwarg}"
elif isinstance(type_kwarg, bytes):
type_kwarg = type_kwarg.hex()

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

version_str = add_0x_prefix(HexStr(type_kwarg))
version = TransactionType(version_str)
else:
version = TransactionType.STATIC

txn_class = transaction_types[version]
kwargs["type"] = version.value
transaction_type = _get_transaction_type(kwargs.get("type"))
kwargs["type"] = transaction_type.value
txn_class = _get_transaction_cls(transaction_type)

if "required_confirmations" not in kwargs or kwargs["required_confirmations"] is None:
# Attempt to use default required-confirmations from `ape-config.yaml`.
Expand All @@ -78,4 +89,32 @@ def create_transaction(self, **kwargs) -> TransactionAPI:
s=bytes(kwargs["s"]),
)

return txn_class(**kwargs) # type: ignore
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_cls(transaction_type: TransactionType) -> Type[TransactionAPI]:
transaction_types = {
TransactionType.STATIC: StaticFeeTransaction,
}
if transaction_type not in transaction_types:
raise ApeArbitrumError(f"Transaction type '{transaction_type}' not supported.")

return transaction_types[transaction_type]
1 change: 0 additions & 1 deletion pyproject.toml
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,6 @@ include = '\.pyi?$'

[tool.pytest.ini_options]
addopts = """
-n auto
-p no:ape_test
--cov-branch
--cov-report term
Expand Down
2 changes: 1 addition & 1 deletion setup.py
Original file line number Diff line number Diff line change
Expand Up @@ -64,7 +64,7 @@
url="https://github.com/ApeWorX/ape-arbitrum",
include_package_data=True,
install_requires=[
"eth-ape>=0.5.0,<0.6",
"eth-ape>=0.5.2,<0.6",
],
python_requires=">=3.8,<4",
extras_require=extras_require,
Expand Down

0 comments on commit dcc743e

Please sign in to comment.