-
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
1 parent
63bf049
commit 8a06f33
Showing
13 changed files
with
164 additions
and
20 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,26 @@ | ||
import requests | ||
|
||
from ethpm.backends.base import BaseURIBackend | ||
from ethpm.constants import GITHUB_AUTHORITY | ||
from ethpm.utils.uri import is_valid_github_uri | ||
from ethpm.validation import validate_github_uri_contents | ||
|
||
|
||
class GithubOverHTTPSBackend(BaseURIBackend): | ||
""" | ||
Base class for all URIs pointing to a content-addressed Github URI. | ||
""" | ||
|
||
def can_handle_uri(self, uri: str) -> bool: | ||
return is_valid_github_uri(uri) | ||
|
||
def fetch_uri_contents(self, uri: str) -> bytes: | ||
http_uri, validation_hash = uri.split("#") | ||
response = requests.get(http_uri) | ||
response.raise_for_status() | ||
validate_github_uri_contents(response.content, validation_hash) | ||
return response.content | ||
|
||
@property | ||
def base_uri(self) -> str: | ||
return GITHUB_AUTHORITY |
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
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 |
---|---|---|
@@ -0,0 +1,20 @@ | ||
import pytest | ||
import requests_mock | ||
|
||
from ethpm.backends.http import GithubOverHTTPSBackend | ||
from ethpm.constants import GITHUB_AUTHORITY | ||
|
||
|
||
@pytest.mark.parametrize( | ||
"uri", | ||
( | ||
"https://raw.githubusercontent.com/ethpm/ethpm-spec/481739f6138907db88602558711e9d3c1301c269/examples/owned/contracts/Owned.sol#bfdea1fa5f33c30fee8443c5ffa1020027f8813e0007bb6f82aaa2843a7fdd60", # noqa: E501 | ||
), | ||
) | ||
def test_github_over_https_backend_fetch_uri_contents(uri, owned_contract): | ||
backend = GithubOverHTTPSBackend() | ||
assert backend.base_uri == GITHUB_AUTHORITY | ||
with requests_mock.Mocker() as m: | ||
m.get(requests_mock.ANY, text=owned_contract) | ||
response = backend.fetch_uri_contents(uri) | ||
assert response.startswith(b"pragma") |
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,6 +1,3 @@ | ||
import json | ||
import os | ||
|
||
import pytest | ||
from solc import compile_source | ||
|
||
|
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