Skip to content

Commit

Permalink
test: all fixes
Browse files Browse the repository at this point in the history
  • Loading branch information
antazoey committed Nov 26, 2024
1 parent 667ea07 commit e22f8b6
Show file tree
Hide file tree
Showing 3 changed files with 31 additions and 5 deletions.
14 changes: 12 additions & 2 deletions ape_infura/provider.py
Original file line number Diff line number Diff line change
Expand Up @@ -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

Expand Down Expand Up @@ -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 not find earliest blocks.
continue
else:
if (
"proofOfAuthorityData" in block
Expand Down
6 changes: 5 additions & 1 deletion tests/conftest.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,8 @@

from ape_infura import NETWORKS

NETWORK_SKIPS = ("starknet",)


@pytest.fixture
def accounts():
Expand All @@ -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)
Expand Down
16 changes: 14 additions & 2 deletions tests/test_provider.py
Original file line number Diff line number Diff line change
Expand Up @@ -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):
Expand Down

0 comments on commit e22f8b6

Please sign in to comment.