Skip to content

Commit

Permalink
feat: support for non-mainnet named mainnet networks (#2320)
Browse files Browse the repository at this point in the history
  • Loading branch information
antazoey authored Oct 16, 2024
1 parent 77ed224 commit bfa6a85
Show file tree
Hide file tree
Showing 4 changed files with 39 additions and 3 deletions.
2 changes: 1 addition & 1 deletion src/ape/api/networks.py
Original file line number Diff line number Diff line change
Expand Up @@ -875,7 +875,7 @@ def ecosystem_config(self) -> PluginConfig:
The configuration of the network. See :class:`~ape.managers.config.ConfigManager`
for more information on plugin configurations.
"""
return self.config_manager.get_config(self.ecosystem.name)
return self.ecosystem.config

@property
def config(self) -> PluginConfig:
Expand Down
6 changes: 6 additions & 0 deletions src/ape_ethereum/ecosystem.py
Original file line number Diff line number Diff line change
Expand Up @@ -147,6 +147,12 @@ class NetworkConfig(PluginConfig):
base_fee_multiplier: float = 1.0
"""A multiplier to apply to a transaction base fee."""

is_mainnet: Optional[bool] = None
"""
Set to ``True`` to declare as a mainnet or ``False`` to ensure
it isn't detected as one.
"""

request_headers: dict = {}
"""Optionally config extra request headers whenever using this network."""

Expand Down
28 changes: 27 additions & 1 deletion tests/functional/test_network_api.py
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,8 @@
from ape.api.networks import ForkedNetworkAPI, NetworkAPI, create_network_type
from ape.api.providers import ProviderAPI
from ape.exceptions import NetworkError, ProviderNotFoundError
from ape_ethereum import EthereumConfig
from ape_ethereum import Ethereum, EthereumConfig
from ape_ethereum.ecosystem import BaseEthereumConfig, NetworkConfig, create_network_config
from ape_ethereum.transactions import TransactionType


Expand Down Expand Up @@ -260,3 +261,28 @@ def test_is_mainnet(ethereum):
assert not ethereum.local.is_mainnet
assert ethereum.mainnet.is_mainnet
assert not ethereum.mainnet_fork.is_mainnet


def test_is_mainnet_from_config(project):
"""
Simulate an EVM plugin with a weird named mainnet that properly
configured it.
"""
chain_id = 9191919191919919121177171
ecosystem_name = "ismainnettest"
network_name = "primarynetwork"
network_type = create_network_type(chain_id, chain_id)

class MyConfig(BaseEthereumConfig):
primarynetwork: NetworkConfig = create_network_config(is_mainnet=True)

class MyEcosystem(Ethereum):
name: str = ecosystem_name

@property
def config(self):
return MyConfig()

ecosystem = MyEcosystem()
network = network_type(name=network_name, ecosystem=ecosystem)
assert network.is_mainnet
6 changes: 5 additions & 1 deletion tests/functional/test_project.py
Original file line number Diff line number Diff line change
Expand Up @@ -890,7 +890,9 @@ def clean():

# Top-level match.
for base in (source_path, str(source_path), "Contract", "Contract.json"):
assert pm.sources.lookup(base) == source_path, f"Failed to lookup {base}"
# Using stem in case it returns `Contract.__mock__`, which is
# added / removed as part of other tests (running x-dist).
assert pm.sources.lookup(base).stem == source_path.stem, f"Failed to lookup {base}"

# Nested: 1st level
for closest in (
Expand All @@ -901,6 +903,8 @@ def clean():
):
actual = pm.sources.lookup(closest)
expected = nested_source_a
# Using stem in case it returns `Contract.__mock__`, which is
# added / removed as part of other tests (running x-dist).
assert actual.stem == expected.stem, f"Failed to lookup {closest}"

# Nested: 2nd level
Expand Down

0 comments on commit bfa6a85

Please sign in to comment.