Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat: add support for .http_uri and .ws_uri in ProviderAPI v0.6.19 [APE-1380] #59

Merged
merged 2 commits into from
Oct 5, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion .pre-commit-config.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ repos:
- id: isort

- repo: https://github.com/psf/black
rev: 23.7.0
rev: 23.9.1
hooks:
- id: black
name: black
Expand Down
2 changes: 1 addition & 1 deletion CONTRIBUTING.md
Original file line number Diff line number Diff line change
Expand Up @@ -80,4 +80,4 @@ A pull request represents the start of a discussion, and doesn't necessarily nee
If you are opening a work-in-progress pull request to verify that it passes CI tests, please consider
[marking it as a draft](https://help.github.com/en/github/collaborating-with-issues-and-pull-requests/about-pull-requests#draft-pull-requests).

Join the Ethereum Python [Discord](https://discord.gg/PcEJ54yX) if you have any questions.
Join the ApeWorX [Discord](https://discord.gg/apeworx) if you have any questions.
10 changes: 10 additions & 0 deletions ape_alchemy/provider.py
Original file line number Diff line number Diff line change
Expand Up @@ -83,6 +83,16 @@ def uri(self):
self.network_uris[(ecosystem_name, network_name)] = uri
return uri

@property
def http_uri(self) -> str:
# NOTE: Overriding `Web3Provider.http_uri` implementation
return self.uri

@property
def ws_uri(self) -> str:
# NOTE: Overriding `Web3Provider.ws_uri` implementation
return "ws" + self.uri[4:] # Remove `http` in default URI w/ `ws`

@property
def connection_str(self) -> str:
return self.uri
Expand Down
2 changes: 1 addition & 1 deletion pyproject.toml
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
[build-system]
requires = ["setuptools>=51.1.1", "wheel", "setuptools_scm[toml]>=5.0"]
requires = ["setuptools>=51.1.1", "wheel", "setuptools_scm[toml]>=5.0,<8"]

[tool.mypy]
exclude = "build/"
Expand Down
3 changes: 2 additions & 1 deletion setup.py
Original file line number Diff line number Diff line change
Expand Up @@ -13,9 +13,10 @@
"pytest-cov", # Coverage analyzer plugin
"pytest-mock", # For creating mocks
"hypothesis>=6.2.0,<7.0", # Strategy-based fuzzer
"websocket-client", # Used for web socket integration testing
],
"lint": [
"black>=23.7.0,<24", # auto-formatter and linter
"black>=23.9.1,<24", # auto-formatter and linter
"mypy>=1.5.1,<2", # Static type analyzer
"types-requests", # Needed due to mypy typeshed
"types-setuptools", # Needed due to mypy typeshed
Expand Down
48 changes: 26 additions & 22 deletions tests/test_integration.py
Original file line number Diff line number Diff line change
@@ -1,30 +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 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}")