Skip to content

Commit

Permalink
refactor: config for nets (#1981)
Browse files Browse the repository at this point in the history
  • Loading branch information
antazoey authored and NotPeopling2day committed Apr 16, 2024
1 parent 4e2e527 commit 66c035b
Show file tree
Hide file tree
Showing 4 changed files with 18 additions and 18 deletions.
20 changes: 10 additions & 10 deletions src/ape/api/networks.py
Original file line number Diff line number Diff line change
Expand Up @@ -795,7 +795,7 @@ def __repr__(self) -> str:
return f"<{name}>" if name else f"{type(self)}"

@property
def config(self) -> PluginConfig:
def ecosystem_config(self) -> PluginConfig:
"""
The configuration of the network. See :class:`~ape.managers.config.ConfigManager`
for more information on plugin configurations.
Expand All @@ -804,11 +804,11 @@ def config(self) -> PluginConfig:
return self.config_manager.get_config(self.ecosystem.name)

@property
def _network_config(self) -> PluginConfig:
def config(self) -> PluginConfig:
name_options = {self.name, self.name.replace("-", "_"), self.name.replace("_", "-")}
cfg: Any
for opt in name_options:
if cfg := self.config.get(opt):
if cfg := self.ecosystem_config.get(opt):
if isinstance(cfg, dict):
return cfg

Expand All @@ -824,7 +824,7 @@ def _network_config(self) -> PluginConfig:

@cached_property
def gas_limit(self) -> GasLimit:
return self._network_config.get("gas_limit", "auto")
return self.config.get("gas_limit", "auto")

@cached_property
def auto_gas_multiplier(self) -> float:
Expand All @@ -838,7 +838,7 @@ def base_fee_multiplier(self) -> float:
"""
A multiplier to apply to a transaction base fee.
"""
return self._network_config.get("base_fee_multiplier", 1.0)
return self.config.get("base_fee_multiplier", 1.0)

@property
def chain_id(self) -> int:
Expand Down Expand Up @@ -869,7 +869,7 @@ def required_confirmations(self) -> int:
refer to the number of blocks that have been added since the
transaction's block.
"""
return self._network_config.get("required_confirmations", 0)
return self.config.get("required_confirmations", 0)

@property
def block_time(self) -> int:
Expand All @@ -884,7 +884,7 @@ def block_time(self) -> int:
block_time: 15
"""

return self._network_config.get("block_time", 0)
return self.config.get("block_time", 0)

@property
def transaction_acceptance_timeout(self) -> int:
Expand All @@ -893,7 +893,7 @@ def transaction_acceptance_timeout(self) -> int:
Does not include waiting for block-confirmations. Defaults to two minutes.
Local networks use smaller timeouts.
"""
return self._network_config.get(
return self.config.get(
"transaction_acceptance_timeout", DEFAULT_TRANSACTION_ACCEPTANCE_TIMEOUT
)

Expand Down Expand Up @@ -1113,7 +1113,7 @@ def default_provider_name(self) -> Optional[str]:
# Was set programatically.
return provider

elif provider_from_config := self._network_config.get("default_provider"):
elif provider_from_config := self.config.get("default_provider"):
# The default is found in the Network's config class.
return provider_from_config

Expand Down Expand Up @@ -1239,7 +1239,7 @@ def upstream_provider(self) -> "UpstreamProvider":
exists.
"""

config_choice: str = self._network_config.get("upstream_provider")
config_choice: str = self.config.get("upstream_provider")
if provider_name := config_choice or self.upstream_network.default_provider_name:
return self.upstream_network.get_provider(provider_name)

Expand Down
4 changes: 2 additions & 2 deletions src/ape_ethereum/ecosystem.py
Original file line number Diff line number Diff line change
Expand Up @@ -356,8 +356,8 @@ def default_transaction_type(self) -> TransactionType:

for name in networks_to_check:
network = self.get_network(name)
ecosystem_default = network.config.DEFAULT_TRANSACTION_TYPE
result: int = network._network_config.get("default_transaction_type", ecosystem_default)
ecosystem_default = network.ecosystem_config.DEFAULT_TRANSACTION_TYPE
result: int = network.config.get("default_transaction_type", ecosystem_default)
return TransactionType(result)

return TransactionType(DEFAULT_TRANSACTION_TYPE)
Expand Down
2 changes: 1 addition & 1 deletion src/ape_ethereum/provider.py
Original file line number Diff line number Diff line change
Expand Up @@ -552,7 +552,7 @@ def get_receipt(
except TimeExhausted as err:
raise TransactionNotFoundError(txn_hash, error_messsage=str(err)) from err

ecosystem_config = self.network.config.model_dump(by_alias=True, mode="json")
ecosystem_config = self.network.ecosystem_config.model_dump(by_alias=True, mode="json")
network_config: Dict = ecosystem_config.get(self.network.name, {})
max_retries = network_config.get("max_get_transaction_retries", DEFAULT_MAX_RETRIES_TX)
txn = {}
Expand Down
10 changes: 5 additions & 5 deletions tests/functional/test_network_api.py
Original file line number Diff line number Diff line change
Expand Up @@ -72,7 +72,7 @@ def test_forked_networks(ethereum):
# Just make sure it doesn't fail when trying to access.
assert mainnet_fork.upstream_provider
# Ensure has default configurations.
cfg = mainnet_fork.config.mainnet_fork
cfg = mainnet_fork.ecosystem_config.mainnet_fork
assert cfg.default_transaction_type == TransactionType.DYNAMIC
assert cfg.block_time == 0
assert cfg.default_provider is None
Expand All @@ -86,7 +86,7 @@ def test_forked_network_with_config(temp_config, ethereum):
"ethereum": {"mainnet_fork": {"default_transaction_type": TransactionType.STATIC.value}}
}
with temp_config(data):
cfg = ethereum.mainnet_fork.config.mainnet_fork
cfg = ethereum.mainnet_fork.ecosystem_config.mainnet_fork
assert cfg.default_transaction_type == TransactionType.STATIC
assert cfg.block_time == 0
assert cfg.default_provider is None
Expand All @@ -108,7 +108,7 @@ def test_config_custom_networks_default(ethereum, custom_networks_config):
present.
"""
network = ethereum.apenet
cfg = network.config.apenet
cfg = network.ecosystem_config.apenet
assert cfg.default_transaction_type == TransactionType.DYNAMIC


Expand All @@ -121,7 +121,7 @@ def test_config_custom_networks(
}
with temp_config(data):
network = ethereum.apenet
ethereum_config = network.config
ethereum_config = network.ecosystem_config
cfg_by_attr = ethereum_config.apenet
assert cfg_by_attr.default_transaction_type == TransactionType.STATIC

Expand All @@ -143,7 +143,7 @@ def test_config_networks_from_custom_ecosystem(
with temp_config(data):
custom_ecosystem = networks.get_ecosystem("custom-ecosystem")
network = custom_ecosystem.get_network("apenet")
ethereum_config = network.config
ethereum_config = network.ecosystem_config
cfg_by_attr = ethereum_config.apenet
assert cfg_by_attr.default_transaction_type == TransactionType.STATIC

Expand Down

0 comments on commit 66c035b

Please sign in to comment.