diff --git a/src/ape/api/config.py b/src/ape/api/config.py index d4560a451d..0c2e5cbd7a 100644 --- a/src/ape/api/config.py +++ b/src/ape/api/config.py @@ -221,7 +221,7 @@ def validate_model(cls, model): if fixed_deps: fixed_model["dependencies"] = fixed_deps - # field: contracs_folder: Handle if given Path object. + # field: contracts_folder: Handle if given Path object. if "contracts_folder" in fixed_model and isinstance(fixed_model["contracts_folder"], Path): fixed_model["contracts_folder"] = str(fixed_model["contracts_folder"]) @@ -330,9 +330,9 @@ def get_plugin_config(self, name: str) -> Optional[PluginConfig]: # Already decoded. return cfg - for plugin_name, config_class in self.plugin_manager.config_class: + for plugin_name, config_class in self._get_config_plugin_classes(): cls: type[PluginConfig] = config_class # type: ignore - if plugin_name != name: + if plugin_name.replace("-", "_") != name: continue if cls != ConfigDict: @@ -347,6 +347,10 @@ def get_plugin_config(self, name: str) -> Optional[PluginConfig]: return None + def _get_config_plugin_classes(self): + # NOTE: Abstracted for easily mocking in tests. + return self.plugin_manager.config_class + def get_custom_ecosystem_config(self, name: str) -> Optional[PluginConfig]: name = name.replace("-", "_") if not (networks := self.get_plugin_config("networks")): diff --git a/tests/functional/test_config.py b/tests/functional/test_config.py index 87efd0e0e8..1e9e76111c 100644 --- a/tests/functional/test_config.py +++ b/tests/functional/test_config.py @@ -8,7 +8,7 @@ from ape.exceptions import ConfigError from ape.managers.config import CONFIG_FILE_NAME, merge_configs from ape.types import GasLimit -from ape_ethereum.ecosystem import NetworkConfig +from ape_ethereum.ecosystem import EthereumConfig, NetworkConfig from ape_networks import CustomNetwork from tests.functional.conftest import PROJECT_WITH_LONG_CONTRACTS_FOLDER @@ -314,3 +314,35 @@ def test_custom_network(): assert network.name == "mytestnet" assert network.chain_id == chain_id assert network.ecosystem == "ethereum" + + +def test_get_config(config): + actual = config.get_config("ethereum") + assert isinstance(actual, EthereumConfig) + + +def test_get_config_hyphen_in_plugin_name(config): + """ + Tests against a bug noticed with ape-polygon-zkevm installed + on Ape 0.8.0 release where the config no longer worked. + """ + + class CustomConfig(PluginConfig): + x: int = 123 + + mock_cfg_with_hyphens = CustomConfig + original_method = config.local_project.config._get_config_plugin_classes + + # Hack in the fake plugin to test the behavior. + def hacked_in_method(): + yield from [*list(original_method()), ("mock-plugin", mock_cfg_with_hyphens)] + + config.local_project.config._get_config_plugin_classes = hacked_in_method + + try: + cfg = config.get_config("mock-plugin") + assert isinstance(cfg, CustomConfig) + assert cfg.x == 123 + + finally: + config.local_project.config._get_config_plugin_classes = original_method diff --git a/tests/functional/test_ecosystem.py b/tests/functional/test_ecosystem.py index 618c512af1..070b54bf41 100644 --- a/tests/functional/test_ecosystem.py +++ b/tests/functional/test_ecosystem.py @@ -974,7 +974,21 @@ def test_default_network_name_when_not_set_and_no_local_uses_only( with project.temp_config(networks={"custom": [net]}): ecosystem = project.network_manager.get_ecosystem(ecosystem_name) - assert ecosystem.default_network_name == only_network + actual = ecosystem.default_network_name + + if actual == LOCAL_NETWORK_NAME: + # For some reason, this test is flake-y. Offer more info + # to try and debug when this happens (intermittent CI failure). + all_nets = ", ".join([x.name for x in ecosystem.networks]) + pytest.fail( + f"assert '{LOCAL_NETWORK_NAME}' == '{only_network}'. More info below:\n" + f"ecosystem_name={ecosystem.name}\n" + f"networks={all_nets}\n" + f"type={type(ecosystem)}" + ) + else: + # This should pass. + assert ecosystem.default_network_name == only_network def test_decode_custom_error(chain, ethereum):