diff --git a/docs/ethpm.rst b/docs/ethpm.rst index 11a55e3763..7dad8bbaf6 100644 --- a/docs/ethpm.rst +++ b/docs/ethpm.rst @@ -47,7 +47,7 @@ Properties Each ``Package`` exposes the following properties. .. autoclass:: ethpm.Package - :members: name, version, manifest_version, uri, __repr__, build_dependencies, deployments + :members: name, version, manifest_version, uri, __repr__, contract_types, build_dependencies, deployments .. py:attribute:: Package.w3 diff --git a/ethpm/package.py b/ethpm/package.py index 987e21c32d..998e3b6fbb 100644 --- a/ethpm/package.py +++ b/ethpm/package.py @@ -6,6 +6,7 @@ Any, Dict, Generator, + List, Optional, Tuple, Union, @@ -175,7 +176,6 @@ def uri(self) -> Optional[str]: The uri (local file_path / content-addressed URI) of a ``Package``'s manifest. """ return self._uri - @property def contract_types(self) -> List[str]: @@ -187,7 +187,6 @@ def contract_types(self) -> List[str]: else: return ValueError("No contract types found in manifest; {self.__repr__()}.") - @classmethod def from_file(cls, file_path: Path, w3: Web3) -> "Package": """ @@ -214,7 +213,7 @@ def from_uri(cls, uri: URI, w3: Web3) -> "Package": URI schemes supported: - IPFS `ipfs://Qm...` - HTTP `https://api.github.com/repos/:owner/:repo/git/blobs/:file_sha` - - Registry `ercXXX://registry.eth/greeter?version=1.0.0` + - Registry `erc1319://registry.eth:1/greeter?version=1.0.0` .. code:: python diff --git a/newsfragments/1440.feature.rst b/newsfragments/1440.feature.rst new file mode 100644 index 0000000000..00d85d5cfa --- /dev/null +++ b/newsfragments/1440.feature.rst @@ -0,0 +1 @@ +Add ``contract_types`` property to ``Package`` class. diff --git a/tests/ethpm/test_package_init_from_file.py b/tests/ethpm/test_package_init.py similarity index 73% rename from tests/ethpm/test_package_init_from_file.py rename to tests/ethpm/test_package_init.py index c5ff9bbacd..7fce42ed01 100644 --- a/tests/ethpm/test_package_init_from_file.py +++ b/tests/ethpm/test_package_init.py @@ -9,6 +9,7 @@ Package, ) from ethpm.exceptions import ( + CannotHandleURI, EthPMValidationError, ) @@ -95,3 +96,36 @@ def test_from_file_succeeds_with_valid_manifest(valid_manifest_from_path, w3): def test_from_file_raises_type_error_with_invalid_param_type(): with pytest.raises(TypeError): Package.from_file(1) + + +# +# From URI +# + +VALID_IPFS_PKG = "ipfs://QmeD2s7KaBUoGYTP1eutHBmBkMMMoycdfiyGMx2DKrWXyV" + + +def test_package_from_uri_with_valid_uri(dummy_ipfs_backend, w3): + package = Package.from_uri(VALID_IPFS_PKG, w3) + assert package.name == "safe-math-lib" + assert isinstance(package, Package) + + +@pytest.mark.parametrize( + "uri", + ( + # Invalid + "123", + b"123", + "ipfs://", + "http://QmTKB75Y73zhNbD3Y73xeXGjYrZHmaXXNxoZqGCagu7r8u/readme", + "ipfsQmTKB75Y73zhNbD3Y73xeXGjYrZHmaXXNxoZqGCagu7r8u/readme/", + # Unsupported + "erc111://packages.zeppelin.os/owned", + "bzz://da6adeeb4589d8652bbe5679aae6b6409ec85a20e92a8823c7c99e25dba9493d", + ), +) +@pytest.mark.skipif('WEB3_INFURA_PROJECT_ID' not in os.environ, reason='Infura API key unavailable') +def test_package_from_uri_rejects_invalid_ipfs_uri(uri, w3): + with pytest.raises(CannotHandleURI): + Package.from_uri(uri, w3) diff --git a/tests/ethpm/test_package_init_from_registry_uri.py b/tests/ethpm/test_package_init_from_registry_uri.py deleted file mode 100644 index d1717925b0..0000000000 --- a/tests/ethpm/test_package_init_from_registry_uri.py +++ /dev/null @@ -1,22 +0,0 @@ -import os -import pytest - -from ethpm import ( - Package, -) -from ethpm.exceptions import ( - CannotHandleURI, -) - - -@pytest.mark.parametrize( - "uri", - ( - "erc111://packages.zeppelin.os/owned", - "bzz://da6adeeb4589d8652bbe5679aae6b6409ec85a20e92a8823c7c99e25dba9493d", - ), -) -@pytest.mark.skipif('WEB3_INFURA_PROJECT_ID' not in os.environ, reason='Infura API key unavailable') -def test_package_init_with_unsupported_uris_raises_exception(uri, w3): - with pytest.raises(CannotHandleURI): - Package.from_uri(uri, w3) diff --git a/tests/ethpm/test_package_init_from_uri.py b/tests/ethpm/test_package_init_from_uri.py deleted file mode 100644 index fd395aeaf8..0000000000 --- a/tests/ethpm/test_package_init_from_uri.py +++ /dev/null @@ -1,33 +0,0 @@ -import os -import pytest - -from ethpm import ( - Package, -) -from ethpm.exceptions import ( - CannotHandleURI, -) - -VALID_IPFS_PKG = "ipfs://QmeD2s7KaBUoGYTP1eutHBmBkMMMoycdfiyGMx2DKrWXyV" - - -def test_package_from_uri_with_valid_uri(dummy_ipfs_backend, w3): - package = Package.from_uri(VALID_IPFS_PKG, w3) - assert package.name == "safe-math-lib" - assert isinstance(package, Package) - - -@pytest.mark.parametrize( - "invalid", - ( - "123", - b"123", - "ipfs://", - "http://QmTKB75Y73zhNbD3Y73xeXGjYrZHmaXXNxoZqGCagu7r8u/readme", - "ipfsQmTKB75Y73zhNbD3Y73xeXGjYrZHmaXXNxoZqGCagu7r8u/readme/", - ), -) -@pytest.mark.skipif('WEB3_INFURA_PROJECT_ID' not in os.environ, reason='Infura API key unavailable') -def test_package_from_uri_rejects_invalid_ipfs_uri(invalid, w3): - with pytest.raises(CannotHandleURI): - Package.from_uri(invalid, w3)