generated from ApeWorX/project-template
-
-
Notifications
You must be signed in to change notification settings - Fork 13
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
5 changed files
with
31 additions
and
28 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,32 +1,34 @@ | ||
import pytest | ||
import websocket # type: ignore | ||
from ape import networks | ||
from ape.utils import ZERO_ADDRESS | ||
|
||
from ape_alchemy import NETWORKS | ||
from ape_alchemy.provider import Alchemy | ||
|
||
|
||
@pytest.mark.parametrize( | ||
"ecosystem,network", | ||
[ | ||
("ethereum", "mainnet"), | ||
("ethereum", "goerli"), | ||
("ethereum", "sepolia"), | ||
("arbitrum", "mainnet"), | ||
("arbitrum", "goerli"), | ||
("base", "mainnet"), | ||
("base", "goerli"), | ||
("optimism", "mainnet"), | ||
("optimism", "goerli"), | ||
("polygon", "mainnet"), | ||
("polygon", "mumbai"), | ||
], | ||
) | ||
def test_alchemy(ecosystem, network): | ||
ecosystem_cls = networks.get_ecosystem(ecosystem) | ||
network_cls = ecosystem_cls.get_network(network) | ||
@pytest.fixture(params=[(name, net) for name, values in NETWORKS.items() for net in values]) | ||
def provider(request): | ||
ecosystem_cls = networks.get_ecosystem(request.param[0]) | ||
network_cls = ecosystem_cls.get_network(request.param[1]) | ||
with network_cls.use_provider("alchemy") as provider: | ||
assert provider.http_uri.startswith("https") | ||
assert provider.ws_uri.startswith("wss") | ||
assert isinstance(provider, Alchemy) | ||
assert provider.get_balance(ZERO_ADDRESS) > 0 | ||
assert provider.get_block(0) | ||
yield provider | ||
|
||
|
||
def test_http(provider): | ||
assert isinstance(provider, Alchemy) | ||
assert provider.http_uri.startswith("https") | ||
assert provider.get_balance(ZERO_ADDRESS) > 0 | ||
assert provider.get_block(0) | ||
|
||
|
||
def test_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}") |