|
1 | 1 | import pytest
|
2 |
| -from ape import networks |
| 2 | +import websocket |
3 | 3 | from ape.utils import ZERO_ADDRESS
|
4 | 4 |
|
5 | 5 | from ape_infura.provider import Infura
|
6 | 6 |
|
7 | 7 |
|
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