예제 #1
0
def test_github_over_https_backend_fetch_uri_contents(uri, owned_contract, w3):
    # these tests may occassionally fail CI as a result of their network requests
    backend = GithubOverHTTPSBackend()
    assert backend.base_uri == GITHUB_API_AUTHORITY
    # integration with Package.from_uri
    owned_package = Package.from_uri(uri, w3)
    assert owned_package.name == "owned"
예제 #2
0
    def get_package_from_uri(self, manifest_uri: URI) -> Package:
        """
        Returns a `Package <https://github.com/ethpm/py-ethpm/blob/master/ethpm/package.py>`__
        instance built with the Manifest stored at the URI.
        If you want to use a specific IPFS backend, set ``ETHPM_IPFS_BACKEND_CLASS``
        to your desired backend. Defaults to Infura IPFS backend.

        * Parameters:
            * ``uri``: Must be a valid content-addressed URI
        """
        return Package.from_uri(manifest_uri, self.web3)
예제 #3
0
    def install(self, uri: str):
        """
        Install packages from chain or files and put it in packages directory.
        """
        self._create_ethpm_packages_dir()
        self._initialize_w3()

        is_file = True
        for prefix in ("ipfs://", "https://", "ethpm://", "erc1319://"):
            if uri.startswith(prefix):
                is_file = False
                break

        if is_file:
            package = Package.from_file(Path(uri), self.w3)
        else:
            package = Package.from_uri(uri, self.w3)

        self._write_manifests_to_filesystem(package.name, package.version, package.manifest)
        self.package = package
def test_package_from_uri_rejects_invalid_ipfs_uri(invalid, w3):
    with pytest.raises(CannotHandleURI):
        Package.from_uri(invalid, w3)
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)
예제 #6
0
def dependencies(dummy_ipfs_backend, piper_coin_manifest, w3):
    deps = piper_coin_manifest["build_dependencies"]
    dep_pkgs = {dep: Package.from_uri(uri, w3) for dep, uri in deps.items()}
    return Dependencies(dep_pkgs)
예제 #7
0
def test_github_over_https_backend_raises_error_with_invalid_content_hash(w3):
    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)
예제 #8
0
def test_package_from_uri_with_valid_uri(w3):
    package = Package.from_uri(VALID_IPFS_PKG, w3)
    assert package.name == "standard-token"
    assert isinstance(package, Package)
예제 #9
0
def test_package_init_with_unsupported_uris_raises_exception(uri, w3):
    with pytest.raises(CannotHandleURI):
        Package.from_uri(uri, w3)
def test_package_init_from_registry_uri(w3_with_registry):
    w3, address, registry = w3_with_registry
    valid_registry_uri = "ercXXX://%s/owned?version=1.0.0" % address
    pkg = Package.from_uri(valid_registry_uri, w3)
    assert isinstance(pkg, Package)
    assert pkg.name == "owned"
예제 #11
0
def test_github_over_https_backend_raises_error_with_invalid_content_hash(w3):
    invalid_uri = "https://raw.githubusercontent.com/ethpm/ethpm-spec/3945c47dedb04930ee12c0281494a1b5bdd692a0/examples/owned/1.0.0.json#01cbc2a69a9f86e9d9e7b87475e2ba2619404dc8d6ee3cb3a8acf3176c2ca111"  # noqa: E501
    with pytest.raises(ValidationError):
        Package.from_uri(invalid_uri, w3)