diff --git a/ape_infura/provider.py b/ape_infura/provider.py index ad1cac0..d56f76f 100644 --- a/ape_infura/provider.py +++ b/ape_infura/provider.py @@ -97,8 +97,15 @@ def uri(self) -> str: key = self.__get_random_api_key() - prefix = f"{ecosystem_name}-" if ecosystem_name != "ethereum" else "" - network_uri = f"https://{prefix}{network_name}.infura.io/v3/{key}" + if ecosystem_name == "bsc" and "opbnb" in network_name: + sub_network = network_name.split("-")[-1] if "-" in network_name else "mainnet" + prefix = f"opbnb-{sub_network}" + else: + prefix = f"{ecosystem_name}-" if ecosystem_name != "ethereum" else "" + prefix = f"{prefix}{network_name}" + + network_uri = f"https://{prefix}.infura.io/v3/{key}" + self.network_uris[(ecosystem_name, network_name)] = network_uri return network_uri @@ -151,6 +158,9 @@ def _needs_poa_middleware(self) -> bool: block = self.web3.eth.get_block(block_id) # type: ignore except ExtraDataLengthError: return True + except Exception: + # Some nodes are "light" and may find earliest blocks. + continue else: if ( "proofOfAuthorityData" in block diff --git a/tests/conftest.py b/tests/conftest.py index bdd2149..b82a585 100644 --- a/tests/conftest.py +++ b/tests/conftest.py @@ -3,6 +3,8 @@ from ape_infura import NETWORKS +NETWORK_SKIPS = ("starknet",) + @pytest.fixture def accounts(): @@ -20,7 +22,9 @@ def networks(): # NOTE: Using a `str` as param for better pytest test-case name generation. -@pytest.fixture(params=[f"{e}:{n}" for e, values in NETWORKS.items() for n in values]) +@pytest.fixture( + params=[f"{e}:{n}" for e, values in NETWORKS.items() if e not in NETWORK_SKIPS for n in values] +) def provider(networks, request): ecosystem, network = request.param.split(":") ecosystem_cls = networks.get_ecosystem(ecosystem) diff --git a/tests/test_provider.py b/tests/test_provider.py index 4b51118..07156fd 100644 --- a/tests/test_provider.py +++ b/tests/test_provider.py @@ -13,12 +13,24 @@ def test_infura_http(provider): ecosystem = provider.network.ecosystem.name network = provider.network.name + + if network in ("opbnb-testnet",): + pytest.skip("This network is weird and has missing trie node errors") + assert isinstance(provider, Infura) assert provider.http_uri.startswith("https") assert provider.get_balance(ZERO_ADDRESS) > 0 - assert provider.get_block(0) ecosystem_uri = "" if ecosystem == "ethereum" else f"{ecosystem}-" - assert f"https://{ecosystem_uri}{network}.infura.io/v3/" in provider.uri + if "opbnb" in network: + expected = ( + "https://opbnb-mainnet.infura.io/v3/" + if network == "opbnb" + else f"https://{network}.infura.io/v3/" + ) + else: + expected = f"https://{ecosystem_uri}{network}.infura.io/v3/" + + assert expected in provider.uri def test_infura_ws(provider):