Skip to content

Commit

Permalink
Merge branch 'main' into fix/refactor-networks
Browse files Browse the repository at this point in the history
  • Loading branch information
antazoey authored Oct 27, 2023
2 parents 25335c3 + 84d25ed commit fe9045a
Show file tree
Hide file tree
Showing 2 changed files with 43 additions and 24 deletions.
5 changes: 3 additions & 2 deletions src/ape/managers/networks.py
Original file line number Diff line number Diff line change
Expand Up @@ -305,12 +305,13 @@ def get_network_choices(
):
yield f"::{provider_name}"

elif ecosystem_name == self.default_ecosystem.name:
if ecosystem_name == self.default_ecosystem.name:
yield f":{network_name}:{provider_name}"

elif network_name == ecosystem.default_network:
if network_name == ecosystem.default_network:
yield f"{ecosystem_name}::{provider_name}"

# Always include the full path as an option.
yield f"{ecosystem_name}:{network_name}:{provider_name}"

# Providers were yielded if we reached this point.
Expand Down
62 changes: 40 additions & 22 deletions tests/functional/test_network_manager.py
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,30 @@ def __call__(self, *args, **kwargs) -> int:

chain_id_factory = NewChainID()

DEFAULT_CHOICES = {
"::geth",
"::test",
":goerli",
":goerli:geth",
":sepolia",
":sepolia:geth",
":local",
":mainnet",
":mainnet:geth",
"ethereum",
"ethereum::test",
"ethereum::geth",
"ethereum:goerli",
"ethereum:goerli:geth",
"ethereum:sepolia",
"ethereum:sepolia:geth",
"ethereum:local",
"ethereum:local:geth",
"ethereum:local:test",
"ethereum:mainnet",
"ethereum:mainnet:geth",
}


@pytest.fixture
def get_provider_with_unused_chain_id(networks_connected_to_tester):
Expand Down Expand Up @@ -58,30 +82,24 @@ def network_with_no_providers(ethereum):
network.__dict__["providers"] = providers


def test_get_network_choices(networks, ethereum, mocker):
# Simulate having a provider like foundry installed.
mock_provider = mocker.MagicMock()
ethereum.networks["mainnet-fork"].providers["mock"] = mock_provider
ethereum.networks["local"].providers["mock"] = mock_provider

# Ensure the provider shows up both mainnet fork and local
# (There was once a bug where it was skipped!)
expected = {":mainnet-fork:mock", ":local:mock"}

actual = {c for c in networks.get_network_choices()}
expected = DEFAULT_CHOICES.union(expected)
assert expected.issubset(actual)


def test_get_network_choices_filter_ecosystem(networks):
actual = {c for c in networks.get_network_choices(ecosystem_filter="ethereum")}
all_choices = {
"::geth",
"::test",
":goerli",
":goerli:geth",
":sepolia",
":sepolia:geth",
":local",
":mainnet",
":mainnet:geth",
"ethereum",
"ethereum:goerli",
"ethereum:goerli:geth",
"ethereum:sepolia",
"ethereum:sepolia:geth",
"ethereum:local",
"ethereum:local:geth",
"ethereum:local:test",
"ethereum:mainnet",
"ethereum:mainnet:geth",
}
assert all_choices.issubset(actual)
assert DEFAULT_CHOICES.issubset(actual)


def test_get_network_choices_filter_network(networks):
Expand Down

0 comments on commit fe9045a

Please sign in to comment.