Repository: oceanprotocol/ocean.py (language: python)

Issue:
Refactor example_config.py
### Background

Config has become _way_ better in the last month or so, thanks to great work by @calina-c. 

Now, [`example_config.py`](https://github.com/oceanprotocol/ocean.py/blob/main/ocean_lib/example_config.py) has a few quick-win simplifications that will further help UX and maintenance.

### TODOs
- [x] [`ExampleConfig`](https://github.com/oceanprotocol/ocean.py/blob/e5e640e855645a3d939649c2ef7c2c075e39e3c1/ocean_lib/example_config.py#L80), is now just a one-liner to `get_config_dict(network_name)`. So, deprecate `ExampleConfig` and replace calls to it (in READMEs etc) with calls to `get_config_dict().
- [x] In `get_config_dict()`, rename `config_helper` to `config_dict`
- [x] `CONFIG_NETWORK_HELPER` is currently a dict of dicts. But each inner dict always has just a single entry, so a dict isn't needed. Flatten to make it just one dictd. 
- [x] Rename `CONFIG_NETWORK_HELPER` to something more precise, e.g. `PROVIDER_PER_NETWORK`




Discussion / hints:

Fix patch:
diff --git a/READMEs/data-nfts-and-datatokens-flow.md b/READMEs/data-nfts-and-datatokens-flow.md
index 9eb1b6518..8e662bf35 100644
--- a/READMEs/data-nfts-and-datatokens-flow.md
+++ b/READMEs/data-nfts-and-datatokens-flow.md
@@ -25,9 +25,9 @@ In the Python console:
 from ocean_lib.web3_internal.utils import connect_to_network
 connect_to_network("development")
 
-from ocean_lib.example_config import ExampleConfig
+from ocean_lib.example_config import get_config_dict
 from ocean_lib.ocean.ocean import Ocean
-config = ExampleConfig.get_config("development")
+config = get_config_dict("development")
 ocean = Ocean(config)
 
 # Create Alice's wallet
diff --git a/READMEs/parameters.md b/READMEs/parameters.md
index 7f8eed40f..18f5cd633 100644
--- a/READMEs/parameters.md
+++ b/READMEs/parameters.md
@@ -10,7 +10,7 @@ We can set any config parameter using the config dictionary.
 An `Ocean` instance will hold a `config_dict` that holds various config parameters. These parameters need to get set. This is set based on what's input to `Ocean` constructor:
 
 1.  dict input: `Ocean({'METADATA_CACHE_URI':..})`
-2.  use boilerplate from ExampleConfig
+2.  use boilerplate from example config
 
 Here are examples.
 
diff --git a/READMEs/services.md b/READMEs/services.md
index 02455e296..0d459fa58 100644
--- a/READMEs/services.md
+++ b/READMEs/services.md
@@ -16,14 +16,14 @@ We now describe how to use these.
 
 ## 1. Set config values for services
 
-Here we set the config  dict. You can use boilerplate from ExampleConfig.
+Here we set the config  dict. You can use boilerplate from example config.
 
 ```python
 import os
-from ocean_lib.example_config import ExampleConfig
+from ocean_lib.example_config import get_config_dict
 
 # configure the components
-config = ExampleConfig.get_config()
+config = get_config_dict()
 ```
 
 Now you're ready to use the services! 🐳 The marketplace tutorial will use them in more detail.
diff --git a/READMEs/simple-remote.md b/READMEs/simple-remote.md
index a02c90917..55fef5fe9 100644
--- a/READMEs/simple-remote.md
+++ b/READMEs/simple-remote.md
@@ -50,9 +50,9 @@ from ocean_lib.web3_internal.utils import connect_to_network
 connect_to_network("mumbai")
 
 import os
-from ocean_lib.example_config import ExampleConfig
+from ocean_lib.example_config import get_config_dict
 from ocean_lib.ocean.ocean import Ocean
-config = ExampleConfig.get_config("mumbai")
+config = get_config_dict("mumbai")
 ocean = Ocean(config)
 
 from brownie.network import accounts
diff --git a/ocean_lib/example_config.py b/ocean_lib/example_config.py
index 0cd10ff65..fce1b36ca 100644
--- a/ocean_lib/example_config.py
+++ b/ocean_lib/example_config.py
@@ -6,8 +6,6 @@
 import copy
 import logging
 
-from enforce_typing import enforce_types
-
 logging.basicConfig(level=logging.INFO)
 
 DEFAULT_METADATA_CACHE_URI = "http://172.15.0.5:5000"
@@ -21,70 +19,37 @@
     "DOWNLOADS_PATH": "consume-downloads",
 }
 
-CONFIG_NETWORK_HELPER = {
-    "mainnet": {
-        "PROVIDER_URL": "https://v4.provider.mainnet.oceanprotocol.com",
-    },
-    "goerli": {
-        "PROVIDER_URL": "https://v4.provider.goerli.oceanprotocol.com",
-    },
-    "bsc": {
-        "PROVIDER_URL": "https://v4.provider.bsc.oceanprotocol.com",
-    },
-    "polygon": {
-        "PROVIDER_URL": "https://v4.provider.polygon.oceanprotocol.com",
-    },
-    "energyweb": {
-        "PROVIDER_URL": "https://v4.provider.energyweb.oceanprotocol.com",
-    },
-    "moonriver": {
-        "PROVIDER_URL": "https://v4.provider.moonriver.oceanprotocol.com",
-    },
-    "moonbase": {
-        "PROVIDER_URL": "https://v4.provider.moonbase.oceanprotocol.com",
-    },
-    "development": {
-        "PROVIDER_URL": DEFAULT_PROVIDER_URL,
-    },
-    "celoalfajores": {
-        "PROVIDER_URL": "https://provider.celoalfajores.oceanprotocol.com",
-    },
-    "mumbai": {
-        "PROVIDER_URL": "https://v4.provider.mumbai.oceanprotocol.com",
-    },
+PROVIDER_PER_NETWORK = {
+    "mainnet": "https://v4.provider.mainnet.oceanprotocol.com",
+    "goerli": "https://v4.provider.goerli.oceanprotocol.com",
+    "bsc": "https://v4.provider.bsc.oceanprotocol.com",
+    "polygon": "https://v4.provider.polygon.oceanprotocol.com",
+    "energyweb": "https://v4.provider.energyweb.oceanprotocol.com",
+    "moonriver": "https://v4.provider.moonriver.oceanprotocol.com",
+    "moonbase": "https://v4.provider.moonbase.oceanprotocol.com",
+    "development": DEFAULT_PROVIDER_URL,
+    "celoalfajores": "https://provider.celoalfajores.oceanprotocol.com",
+    "mumbai": "https://v4.provider.mumbai.oceanprotocol.com",
 }
 
 
-@enforce_types
-def get_config_dict(network_name: str) -> dict:
-    if network_name not in CONFIG_NETWORK_HELPER:
+def get_config_dict(network_name=None) -> dict:
+    """Return config dict containing default values for a given network.
+    Chain ID is determined by querying the RPC specified by network_url.
+    """
+    if not network_name:
+        network_name = "development"
+
+    if network_name not in PROVIDER_PER_NETWORK:
         raise ValueError("The chain id for the specific RPC could not be fetched!")
 
-    config_helper = copy.deepcopy(config_defaults)
-    config_helper.update(CONFIG_NETWORK_HELPER[network_name])
-    config_helper["NETWORK_NAME"] = network_name
+    config_dict = copy.deepcopy(config_defaults)
+    config_dict["PROVIDER_URL"] = PROVIDER_PER_NETWORK[network_name]
+    config_dict["NETWORK_NAME"] = network_name
 
     if network_name != "development":
-        config_helper["METADATA_CACHE_URI"] = METADATA_CACHE_URI
+        config_dict["METADATA_CACHE_URI"] = METADATA_CACHE_URI
     else:
-        config_helper[
-            "ADDRESS_FILE"
-        ] = "~/.ocean/ocean-contracts/artifacts/address.json"
-
-    return config_helper
-
-
-class ExampleConfig:
-    @staticmethod
-    @enforce_types
-    def get_config(network_name=None) -> dict:
-        """Return config dict containing default values for a given network.
-        Chain ID is determined by querying the RPC specified by network_url.
-        """
-
-        if not network_name:
-            network_name = "development"
-
-        config_dict = get_config_dict(network_name)
+        config_dict["ADDRESS_FILE"] = "~/.ocean/ocean-contracts/artifacts/address.json"
 
-        return config_dict
+    return config_dict


Test patch:
diff --git a/READMEs/get-test-OCEAN.md b/READMEs/get-test-OCEAN.md
index 42489f881..74d07878f 100644
--- a/READMEs/get-test-OCEAN.md
+++ b/READMEs/get-test-OCEAN.md
@@ -67,9 +67,9 @@ In a bash console:
 In a Python console:
 
 ```python
-from ocean_lib.example_config import ExampleConfig
+from ocean_lib.example_config import get_config_dict
 from ocean_lib.ocean.ocean import Ocean
-config = ExampleConfig.get_config("development")  # or any network id configured in your brownie network-config.yaml file
+config = get_config_dict("development")  # or any network id configured in your brownie network-config.yaml file
 ocean = Ocean(config)
 
 # create an ERC20 object of OCEAN token
diff --git a/conftest_ganache.py b/conftest_ganache.py
index 7c15df120..d37cbb299 100644
--- a/conftest_ganache.py
+++ b/conftest_ganache.py
@@ -7,6 +7,7 @@
 from web3.main import Web3
 
 from ocean_lib.aquarius.aquarius import Aquarius
+from ocean_lib.example_config import get_config_dict
 from ocean_lib.models.data_nft import DataNFT
 from ocean_lib.models.data_nft_factory import DataNFTFactoryContract
 from ocean_lib.models.datatoken import Datatoken
@@ -19,7 +20,6 @@
     get_another_consumer_wallet,
     get_consumer_ocean_instance,
     get_consumer_wallet,
-    get_example_config,
     get_factory_deployer_wallet,
     get_file1,
     get_file2,
@@ -72,7 +72,7 @@ def setup_all(request, config, ocean_token):
 
 @pytest.fixture
 def config():
-    return get_example_config()
+    return get_config_dict()
 
 
 @pytest.fixture
diff --git a/ocean_lib/models/test/conftest.py b/ocean_lib/models/test/conftest.py
index 1bde09c89..8e50d506f 100644
--- a/ocean_lib/models/test/conftest.py
+++ b/ocean_lib/models/test/conftest.py
@@ -9,7 +9,7 @@
 from web3.main import Web3
 
 from conftest_ganache import *
-from ocean_lib.example_config import ExampleConfig
+from ocean_lib.example_config import get_config_dict
 from ocean_lib.ocean.util import get_address_of_type, get_ocean_token_address
 from tests.resources.helper_functions import get_ganache_wallet
 
@@ -104,7 +104,7 @@ class _Info:
         pass
 
     info = _Info()
-    config = ExampleConfig.get_config()
+    config = get_config_dict()
 
     info.private_key = os.environ.get(private_key_name)
     info.wallet = accounts.add(info.private_key)
diff --git a/ocean_lib/test/test_example_config.py b/ocean_lib/test/test_example_config.py
index 330fcc587..6e1da8248 100644
--- a/ocean_lib/test/test_example_config.py
+++ b/ocean_lib/test/test_example_config.py
@@ -8,7 +8,7 @@
     DEFAULT_METADATA_CACHE_URI,
     DEFAULT_PROVIDER_URL,
     METADATA_CACHE_URI,
-    ExampleConfig,
+    get_config_dict,
 )
 from ocean_lib.models.data_nft_factory import DataNFTFactoryContract
 from ocean_lib.ocean.util import get_address_of_type
@@ -19,7 +19,7 @@
 def test_ganache_example_config():
     """Tests the config structure of ganache network."""
 
-    config = ExampleConfig.get_config()
+    config = get_config_dict()
 
     assert config["METADATA_CACHE_URI"] == DEFAULT_METADATA_CACHE_URI
     assert config["PROVIDER_URL"] == DEFAULT_PROVIDER_URL
@@ -29,7 +29,7 @@ def test_ganache_example_config():
 def test_polygon_example_config():
     """Tests the config structure of Polygon network."""
 
-    config = ExampleConfig.get_config("polygon")
+    config = get_config_dict("polygon")
 
     assert config["METADATA_CACHE_URI"] == METADATA_CACHE_URI
     assert config["PROVIDER_URL"] == "https://v4.provider.polygon.oceanprotocol.com"
@@ -39,7 +39,7 @@ def test_polygon_example_config():
 def test_bsc_example_config():
     """Tests the config structure of BSC network."""
 
-    config = ExampleConfig.get_config("bsc")
+    config = get_config_dict("bsc")
 
     assert config["METADATA_CACHE_URI"] == METADATA_CACHE_URI
     assert config["PROVIDER_URL"] == "https://v4.provider.bsc.oceanprotocol.com"
@@ -49,7 +49,7 @@ def test_bsc_example_config():
 def test_moonbeam_alpha_example_config(monkeypatch):
     """Tests the config structure of Moonbeam Alpha network."""
 
-    config = ExampleConfig.get_config("moonbase")
+    config = get_config_dict("moonbase")
 
     assert config["METADATA_CACHE_URI"] == METADATA_CACHE_URI
     assert config["PROVIDER_URL"] == "https://v4.provider.moonbase.oceanprotocol.com"
@@ -57,7 +57,7 @@ def test_moonbeam_alpha_example_config(monkeypatch):
 
 @pytest.mark.unit
 def test_get_address_of_type(monkeypatch):
-    config = ExampleConfig.get_config("polygon")
+    config = get_config_dict("polygon")
 
     data_nft_factory = get_address_of_type(config, DataNFTFactoryContract.CONTRACT_NAME)
     addresses = get_contracts_addresses(config)
diff --git a/ocean_lib/web3_internal/test/conftest.py b/ocean_lib/web3_internal/test/conftest.py
index ebdb029be..b928abb44 100644
--- a/ocean_lib/web3_internal/test/conftest.py
+++ b/ocean_lib/web3_internal/test/conftest.py
@@ -12,7 +12,7 @@
 import pytest
 
 from conftest_ganache import *
-from ocean_lib.example_config import ExampleConfig
+from ocean_lib.example_config import get_config_dict
 from ocean_lib.models.test.conftest import *  # noqa: F401 F403
 
 # Other things to set up, specific to here...
@@ -20,4 +20,4 @@
 
 @pytest.fixture
 def example_config():
-    return ExampleConfig.get_config()
+    return get_config_dict()
diff --git a/tests/resources/helper_functions.py b/tests/resources/helper_functions.py
index b5532d178..874fa513b 100644
--- a/tests/resources/helper_functions.py
+++ b/tests/resources/helper_functions.py
@@ -17,7 +17,7 @@
 from enforce_typing import enforce_types
 from web3 import Web3
 
-from ocean_lib.example_config import ExampleConfig
+from ocean_lib.example_config import get_config_dict
 from ocean_lib.models.data_nft import DataNFT
 from ocean_lib.models.data_nft_factory import DataNFTFactoryContract
 from ocean_lib.models.datatoken import Datatoken
@@ -31,10 +31,6 @@
 _NETWORK = "ganache"
 
 
-def get_example_config():
-    return ExampleConfig.get_config()
-
-
 @enforce_types
 def get_wallet(index: int):
     return accounts.add(os.getenv(f"TEST_PRIVATE_KEY{index}"))
@@ -68,7 +64,7 @@ def get_factory_deployer_wallet(config):
     if not private_key:
         return None
 
-    config = get_example_config()
+    config = get_config_dict()
     return accounts.add(private_key)
 
 
@@ -81,7 +77,7 @@ def get_ganache_wallet():
 @enforce_types
 def generate_wallet():
     """Generates wallets on the fly with funds."""
-    config = get_example_config()
+    config = get_config_dict()
     secret = secrets.token_hex(32)
     private_key = "0x" + secret
 
@@ -100,7 +96,7 @@ def generate_wallet():
 
 @enforce_types
 def get_publisher_ocean_instance(use_provider_mock=False) -> Ocean:
-    config_dict = ExampleConfig.get_config()
+    config_dict = get_config_dict()
     data_provider = DataProviderMock if use_provider_mock else None
     ocn = Ocean(config_dict, data_provider=data_provider)
     account = get_publisher_wallet()
@@ -110,7 +106,7 @@ def get_publisher_ocean_instance(use_provider_mock=False) -> Ocean:
 
 @enforce_types
 def get_consumer_ocean_instance(use_provider_mock: bool = False) -> Ocean:
-    config = ExampleConfig.get_config()
+    config = get_config_dict()
     data_provider = DataProviderMock if use_provider_mock else None
     ocn = Ocean(config, data_provider=data_provider)
     account = get_consumer_wallet()
@@ -120,7 +116,7 @@ def get_consumer_ocean_instance(use_provider_mock: bool = False) -> Ocean:
 
 @enforce_types
 def get_another_consumer_ocean_instance(use_provider_mock: bool = False) -> Ocean:
-    config = ExampleConfig.get_config()
+    config = get_config_dict()
     data_provider = DataProviderMock if use_provider_mock else None
     ocn = Ocean(config, data_provider=data_provider)
     account = get_another_consumer_wallet()