Skip to content

Commit d43f47d

Browse files
committed
test: add integration tes
1 parent d31eb25 commit d43f47d

File tree

3 files changed

+46
-29
lines changed

3 files changed

+46
-29
lines changed

README.md

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -58,5 +58,6 @@ To connect to Infura from a Python script, use the `networks` top-level manager:
5858
from ape import networks
5959

6060
with networks.parse_network_choice("ethereum:mainnet:infura") as provider:
61-
...
61+
# Also, access the websocket URI:
62+
print(provider.ws_uri)
6263
```

tests/conftest.py

Lines changed: 22 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,20 @@
11
import ape
22
import pytest
33

4+
NETWORKS = [
5+
("ethereum", "mainnet"),
6+
("ethereum", "goerli"),
7+
("ethereum", "sepolia"),
8+
("arbitrum", "mainnet"),
9+
("arbitrum", "goerli"),
10+
("optimism", "mainnet"),
11+
("optimism", "goerli"),
12+
("polygon", "mainnet"),
13+
("polygon", "mumbai"),
14+
("linea", "mainnet"),
15+
("linea", "goerli"),
16+
]
17+
418

519
@pytest.fixture
620
def accounts():
@@ -15,3 +29,11 @@ def Contract():
1529
@pytest.fixture
1630
def networks():
1731
return ape.networks
32+
33+
34+
@pytest.fixture(params=NETWORKS)
35+
def provider(networks, request):
36+
ecosystem_cls = networks.get_ecosystem(request.param[0])
37+
network_cls = ecosystem_cls.get_network(request.param[1])
38+
with network_cls.use_provider("infura") as provider:
39+
yield provider

tests/test_provider.py

Lines changed: 22 additions & 28 deletions
Original file line numberDiff line numberDiff line change
@@ -1,34 +1,28 @@
11
import pytest
2-
from ape import networks
2+
import websocket
33
from ape.utils import ZERO_ADDRESS
44

55
from ape_infura.provider import Infura
66

77

8-
@pytest.mark.parametrize(
9-
"ecosystem,network",
10-
[
11-
("ethereum", "mainnet"),
12-
("ethereum", "goerli"),
13-
("ethereum", "sepolia"),
14-
("arbitrum", "mainnet"),
15-
("arbitrum", "goerli"),
16-
("optimism", "mainnet"),
17-
("optimism", "goerli"),
18-
("polygon", "mainnet"),
19-
("polygon", "mumbai"),
20-
("linea", "mainnet"),
21-
("linea", "goerli"),
22-
],
23-
)
24-
def test_infura(ecosystem, network):
25-
ecosystem_cls = networks.get_ecosystem(ecosystem)
26-
network_cls = ecosystem_cls.get_network(network)
27-
with network_cls.use_provider("infura") as provider:
28-
assert isinstance(provider, Infura)
29-
assert provider.http_uri.startswith("https")
30-
assert provider.ws_uri.startswith("wss")
31-
assert provider.get_balance(ZERO_ADDRESS) > 0
32-
assert provider.get_block(0)
33-
ecosystem_uri = "" if ecosystem == "ethereum" else f"{ecosystem}-"
34-
assert f"https://{ecosystem_uri}{network}.infura.io/v3/" in provider.uri
8+
def test_infura_http(provider):
9+
ecosystem = provider.network.ecosystem.name
10+
network = provider.network.name
11+
assert isinstance(provider, Infura)
12+
assert provider.http_uri.startswith("https")
13+
assert provider.get_balance(ZERO_ADDRESS) > 0
14+
assert provider.get_block(0)
15+
ecosystem_uri = "" if ecosystem == "ethereum" else f"{ecosystem}-"
16+
assert f"https://{ecosystem_uri}{network}.infura.io/v3/" in provider.uri
17+
18+
19+
def test_infura_ws(provider):
20+
assert provider.ws_uri.startswith("wss")
21+
22+
try:
23+
ws = websocket.WebSocket()
24+
ws.connect(provider.ws_uri)
25+
ws.close()
26+
27+
except Exception as err:
28+
pytest.fail(f"Websocket URI not accessible. Reason: {err}")

0 commit comments

Comments
 (0)