Skip to content

Commit

Permalink
test: add integration test
Browse files Browse the repository at this point in the history
  • Loading branch information
antazoey committed Oct 5, 2023
1 parent d31eb25 commit f043e95
Show file tree
Hide file tree
Showing 3 changed files with 34 additions and 29 deletions.
3 changes: 2 additions & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -58,5 +58,6 @@ To connect to Infura from a Python script, use the `networks` top-level manager:
from ape import networks

with networks.parse_network_choice("ethereum:mainnet:infura") as provider:
...
# Also, access the websocket URI:
print(provider.ws_uri)
```
10 changes: 10 additions & 0 deletions tests/conftest.py
Original file line number Diff line number Diff line change
@@ -1,6 +1,8 @@
import ape
import pytest

from ape_infura import NETWORKS


@pytest.fixture
def accounts():
Expand All @@ -15,3 +17,11 @@ def Contract():
@pytest.fixture
def networks():
return ape.networks


@pytest.fixture(params=[(name, net) for name, values in NETWORKS.items() for net in values])
def provider(networks, request):
ecosystem_cls = networks.get_ecosystem(request.param[0])
network_cls = ecosystem_cls.get_network(request.param[1])
with network_cls.use_provider("infura") as provider:
yield provider
50 changes: 22 additions & 28 deletions tests/test_provider.py
Original file line number Diff line number Diff line change
@@ -1,34 +1,28 @@
import pytest
from ape import networks
import websocket # type: ignore
from ape.utils import ZERO_ADDRESS

from ape_infura.provider import Infura


@pytest.mark.parametrize(
"ecosystem,network",
[
("ethereum", "mainnet"),
("ethereum", "goerli"),
("ethereum", "sepolia"),
("arbitrum", "mainnet"),
("arbitrum", "goerli"),
("optimism", "mainnet"),
("optimism", "goerli"),
("polygon", "mainnet"),
("polygon", "mumbai"),
("linea", "mainnet"),
("linea", "goerli"),
],
)
def test_infura(ecosystem, network):
ecosystem_cls = networks.get_ecosystem(ecosystem)
network_cls = ecosystem_cls.get_network(network)
with network_cls.use_provider("infura") as provider:
assert isinstance(provider, Infura)
assert provider.http_uri.startswith("https")
assert provider.ws_uri.startswith("wss")
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
def test_infura_http(provider):
ecosystem = provider.network.ecosystem.name
network = provider.network.name
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


def test_infura_ws(provider):
assert provider.ws_uri.startswith("wss")

try:
ws = websocket.WebSocket()
ws.connect(provider.ws_uri)
ws.close()

except Exception as err:
pytest.fail(f"Websocket URI not accessible. Reason: {err}")

0 comments on commit f043e95

Please sign in to comment.