Skip to content

Commit

Permalink
Move infura key to monkeypatch env
Browse files Browse the repository at this point in the history
  • Loading branch information
njgheorghita committed Jul 12, 2019
1 parent c4e93c2 commit 730a8f2
Show file tree
Hide file tree
Showing 7 changed files with 12 additions and 22 deletions.
12 changes: 0 additions & 12 deletions ethpm/backends/registry.py
Original file line number Diff line number Diff line change
@@ -1,7 +1,6 @@
from collections import (
namedtuple,
)
import os
from urllib import (
parse,
)
Expand All @@ -16,20 +15,13 @@
from ethpm.backends.base import (
BaseURIBackend,
)
from ethpm.constants import (
ETHPM_INFURA_API_KEY,
)
from ethpm.exceptions import (
CannotHandleURI,
ValidationError,
)
from ethpm.validation.uri import (
validate_registry_uri,
)
from web3 import Web3
from web3.exceptions import (
InfuraKeyNotFound,
)

# TODO: Update registry ABI once ERC is finalized.
REGISTRY_ABI = fetch_standard_registry_abi()
Expand All @@ -44,10 +36,6 @@ class RegistryURIBackend(BaseURIBackend):
"""

def __init__(self) -> None:
try:
from web3.auto.infura.endpoints import load_api_key
except InfuraKeyNotFound:
os.environ['WEB3_INFURA_PROJECT_ID'] = ETHPM_INFURA_API_KEY
from web3.auto.infura import w3
self.w3 = w3

Expand Down
4 changes: 0 additions & 4 deletions ethpm/constants.py
Original file line number Diff line number Diff line change
Expand Up @@ -6,10 +6,6 @@

IPFS_GATEWAY_PREFIX = "https://ipfs.io/ipfs/"

# TODO Deprecate in favor of a better scheme for fetching registry URIs.
# Please play nice and don't use this key for any shenanigans, thanks!
ETHPM_INFURA_API_KEY = "4f1a358967c7474aae6f8f4a7698aefc"

INFURA_GATEWAY_MULTIADDR = "/dns4/ipfs.infura.io/tcp/5001/https/"

GITHUB_API_AUTHORITY = "api.github.com"
Expand Down
4 changes: 2 additions & 2 deletions tests/ethpm/_utils/test_backend_utils.py
Original file line number Diff line number Diff line change
Expand Up @@ -42,7 +42,7 @@ def test_get_resolvable_backends_for_supported_uris(dummy_ipfs_backend, uri, bac
),
)
def test_get_translatable_backends_for_supported_uris(
dummy_ipfs_backend, uri, backends
dummy_ipfs_backend, uri, backends, infura_env
):
good_backends = get_translatable_backends_for_uri(uri)
assert good_backends == backends
Expand All @@ -65,6 +65,6 @@ def test_get_translatable_backends_for_supported_uris(
"https://github.com/ethpm/ethpm-spec/examples/owned/1.0.0.json#content_hash",
),
)
def test_resolve_uri_contents_raises_exception_for_unsupported_schemes(uri):
def test_resolve_uri_contents_raises_exception_for_unsupported_schemes(uri, infura_env):
with pytest.raises(CannotHandleURI):
resolve_uri_contents(uri)
4 changes: 2 additions & 2 deletions tests/ethpm/backends/test_http_backends.py
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@
"https://api.github.com/repos/ethpm/py-ethpm/git/blobs/a7232a93f1e9e75d606f6c1da18aa16037e03480", # noqa: E501
),
)
def test_github_over_https_backend_fetch_uri_contents(uri, owned_contract, w3):
def test_github_over_https_backend_fetch_uri_contents(uri, owned_contract, w3, infura_env):
# these tests may occassionally fail CI as a result of their network requests
backend = GithubOverHTTPSBackend()
assert backend.base_uri == GITHUB_API_AUTHORITY
Expand All @@ -30,7 +30,7 @@ def test_github_over_https_backend_fetch_uri_contents(uri, owned_contract, w3):
assert owned_package.name == "owned"


def test_github_over_https_backend_raises_error_with_invalid_content_hash(w3):
def test_github_over_https_backend_raises_error_with_invalid_content_hash(w3, infura_env):
invalid_uri = "https://api.github.com/repos/ethpm/py-ethpm/git/blobs/a7232a93f1e9e75d606f6c1da18aa16037e03123" # noqa: E501
with pytest.raises(HTTPError):
Package.from_uri(invalid_uri, w3)
6 changes: 6 additions & 0 deletions tests/ethpm/conftest.py
Original file line number Diff line number Diff line change
Expand Up @@ -40,6 +40,12 @@ def pytest_addoption(parser):
parser.addoption("--integration", action="store_true", default=False)


@pytest.fixture
def infura_env(monkeypatch):
# Please play nice and don't use this key for any shenanigans, thanks!
monkeypatch.setenv("WEB3_INFURA_PROJECT_ID", '4f1a358967c7474aae6f8f4a7698aefc')


@pytest.fixture
def package_names():
return PACKAGE_NAMES
Expand Down
2 changes: 1 addition & 1 deletion tests/ethpm/test_package_init_from_registry_uri.py
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,6 @@
"bzz://da6adeeb4589d8652bbe5679aae6b6409ec85a20e92a8823c7c99e25dba9493d",
),
)
def test_package_init_with_unsupported_uris_raises_exception(uri, w3):
def test_package_init_with_unsupported_uris_raises_exception(uri, w3, infura_env):
with pytest.raises(CannotHandleURI):
Package.from_uri(uri, w3)
2 changes: 1 addition & 1 deletion tests/ethpm/test_package_init_from_uri.py
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,6 @@ def test_package_from_uri_with_valid_uri(dummy_ipfs_backend, w3):
"ipfsQmTKB75Y73zhNbD3Y73xeXGjYrZHmaXXNxoZqGCagu7r8u/readme/",
),
)
def test_package_from_uri_rejects_invalid_ipfs_uri(invalid, w3):
def test_package_from_uri_rejects_invalid_ipfs_uri(invalid, w3, infura_env):
with pytest.raises(CannotHandleURI):
Package.from_uri(invalid, w3)

0 comments on commit 730a8f2

Please sign in to comment.