From 84d25ed41faa176ebe07a72e4deadf385e6e0ea7 Mon Sep 17 00:00:00 2001 From: antazoey Date: Fri, 27 Oct 2023 11:55:13 -0500 Subject: [PATCH] fix: missing choices (#1706) --- src/ape/managers/networks.py | 5 +- tests/functional/test_network_manager.py | 62 +++++++++++++++--------- 2 files changed, 43 insertions(+), 24 deletions(-) diff --git a/src/ape/managers/networks.py b/src/ape/managers/networks.py index 64cf8ae044..131d4c4dfd 100644 --- a/src/ape/managers/networks.py +++ b/src/ape/managers/networks.py @@ -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. diff --git a/tests/functional/test_network_manager.py b/tests/functional/test_network_manager.py index 85b20dbf73..b6548e9d6c 100644 --- a/tests/functional/test_network_manager.py +++ b/tests/functional/test_network_manager.py @@ -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): @@ -55,30 +79,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):