def test_builder_with_standard_token_manifest(standard_token_package,
                                              dummy_ipfs_backend, monkeypatch):
    root, expected_manifest, compiler_output = standard_token_package
    ipfs_backend = get_ipfs_backend()

    monkeypatch.chdir(root)
    manifest = build(
        {},
        package_name("standard-token"),
        manifest_version("ethpm/3"),
        version("1.0.0"),
        pin_source("StandardToken", compiler_output, ipfs_backend),
        pin_source("Token", compiler_output, ipfs_backend),
        contract_type("StandardToken",
                      compiler_output,
                      abi=True,
                      devdoc=True,
                      source_id=True),
        contract_type("Token",
                      compiler_output,
                      abi=True,
                      devdoc=True,
                      userdoc=True,
                      source_id=True),
        validate(),
    )
    assert manifest == expected_manifest
示例#2
0
文件: uri.py 项目: davesque/py-ethpm
def get_manifest_from_content_addressed_uri(uri: str) -> Dict[str, Any]:
    """
    Return manifest data stored at a content addressed URI.
    """
    parse_result = parse.urlparse(uri)
    scheme = parse_result.scheme

    if scheme == IPFS_SCHEME:
        ipfs_backend = get_ipfs_backend()
        if ipfs_backend.can_handle_uri(uri):
            raw_manifest_data = ipfs_backend.fetch_uri_contents(uri)
            manifest_data = to_text(raw_manifest_data)
            return json.loads(manifest_data)
        else:
            raise TypeError(
                "The IPFS Backend: {0} cannot handle the given URI: {1}.".format(
                    type(ipfs_backend).__name__, uri
                )
            )

    if scheme in INTERNET_SCHEMES:
        raise UriNotSupportedError("Internet URIs are not yet supported.")

    if scheme in SWARM_SCHEMES:
        raise UriNotSupportedError("Swarm URIs are not yet supported.")

    raise UriNotSupportedError("The URI scheme:{0} is not supported.".format(scheme))
示例#3
0
    def from_ipfs(cls, ipfs_uri: str) -> "Package":
        """
        Instantiate and return a Package object from an IPFS URI pointing to a manifest.
        """
        ipfs_backend = get_ipfs_backend()
        if ipfs_backend.can_handle_uri(ipfs_uri):
            raw_package_data = ipfs_backend.fetch_uri_contents(ipfs_uri)
            package_data = json.loads(to_text(raw_package_data))
        else:
            raise TypeError(
                "The URI Backend: {0} cannot handle the given URI: {1}.".format(
                    type(ipfs_backend).__name__, ipfs_uri
                )
            )

        return cls(package_data)
示例#4
0
def test_pin_assets_to_dummy_backend(dummy_ipfs_backend, ethpm_spec_dir, owned_manifest_path):
    # Test pinning a file
    backend = get_ipfs_backend()
    hashes = backend.pin_assets(owned_manifest_path)
    asset_data = hashes[0]
    assert asset_data["Name"] == "v3.json"
    assert asset_data["Hash"] == "QmcxvhkJJVpbxEAa6cgW3B6XwPJb79w9GpNUv2P2THUzZR"
    assert asset_data["Size"] == "478"
    # Test pinning a directory
    dir_data = backend.pin_assets(ethpm_spec_dir / "examples" / "standard-token" / "contracts")
    dir_names = [result["Name"] for result in dir_data]
    dir_hashes = [result["Hash"] for result in dir_data]
    dir_sizes = [result["Size"] for result in dir_data]
    assert len(dir_data) == 2
    assert "StandardToken.sol" in dir_names
    assert "QmUofKBtNJVaqoSAtnHfrarJyyLm1oMUTAK4yCtnmYMJVy" in dir_hashes
    assert "2949" in dir_sizes
示例#5
0
def test_pin_assets_to_dummy_backend(dummy_ipfs_backend):
    # Test pinning a file
    backend = get_ipfs_backend()
    hashes = backend.pin_assets(OWNED_MANIFEST_PATH)
    asset_data = hashes[0]
    assert asset_data["Name"] == "1.0.0.json"
    assert asset_data["Hash"] == "QmbeVyFLSuEUxiXKwSsEjef6icpdTdA4kGG9BcrJXKNKUW"
    assert asset_data["Size"] == "443"
    # Test pinning a directory
    dir_data = backend.pin_assets(V2_PACKAGES_DIR / "standard-token" / "contracts")
    dir_names = [result["Name"] for result in dir_data]
    dir_hashes = [result["Hash"] for result in dir_data]
    dir_sizes = [result["Size"] for result in dir_data]
    assert len(dir_data) == 2
    assert "StandardToken.sol" in dir_names
    assert "QmRJHLmPVct2rbBpdGjP3xkXbF7romQigtmcs8TRfV1yC7" in dir_hashes
    assert "2865" in dir_sizes
def test_pin_assets_to_dummy_backend(dummy_ipfs_backend):
    # Test pinning a file
    backend = get_ipfs_backend()
    hashes = backend.pin_assets(OWNED_MANIFEST_PATH)
    asset_data = hashes[0]
    assert asset_data["Name"] == "1.0.0.json"
    assert asset_data["Hash"] == "QmYogrz6sKuyMW8NHUdw1kEy9Tn15R3GaF9T14S4zwb4bR"
    assert asset_data["Size"] == "433"
    # Test pinning a directory
    dir_data = backend.pin_assets(ASSETS_DIR / "standard-token" / "contracts")
    dir_names = [result["Name"] for result in dir_data]
    dir_hashes = [result["Hash"] for result in dir_data]
    dir_sizes = [result["Size"] for result in dir_data]
    assert len(dir_data) == 2
    assert "StandardToken.sol" in dir_names
    assert "QmRJHLmPVct2rbBpdGjP3xkXbF7romQigtmcs8TRfV1yC7" in dir_hashes
    assert "2865" in dir_sizes
示例#7
0
def test_local_ipfs_backend_integration_round_trip(monkeypatch):
    """
    To run this integration test requires an running IPFS node.
    If you want to run these tests, first start your IPFS node, and
    then run pytest with the arg `--integration`.
    """
    if not pytest.config.getoption("--integration"):
        pytest.skip("Not asked to run integration tests")

    monkeypatch.setenv("ETHPM_IPFS_BACKEND_CLASS",
                       "ethpm.backends.ipfs.LocalIPFSBackend")
    backend = get_ipfs_backend()
    [asset_data] = backend.pin_assets(OWNED_MANIFEST_PATH)
    assert asset_data["Name"] == "1.0.0.json"
    assert asset_data[
        "Hash"] == "QmbeVyFLSuEUxiXKwSsEjef6icpdTdA4kGG9BcrJXKNKUW"
    local_manifest = to_bytes(text=OWNED_MANIFEST_PATH.read_text())
    ipfs_manifest = backend.fetch_uri_contents(asset_data["Hash"])
    assert ipfs_manifest == local_manifest
示例#8
0
def test_builder_with_init_manifest(owned_package, dummy_ipfs_backend):
    root, expected_manifest, compiler_output = owned_package
    ipfs_backend = get_ipfs_backend()

    manifest = build(
        init_manifest(package_name="owned", version="1.0.0"),
        authors("Piper Merriam <*****@*****.**>"),
        description(
            "Reusable contracts which implement a privileged 'owner' model for authorization."
        ),
        keywords("authorization"),
        license("MIT"),
        links(documentation=
              "ipfs://QmUYcVzTfSwJoigggMxeo2g5STWAgJdisQsqcXHws7b1FW"),
        pin_source("Owned", compiler_output, ipfs_backend, root),
        validate(),
    )

    assert manifest == expected_manifest
示例#9
0
def test_get_uri_backend_with_env_variable(dummy_ipfs_backend, monkeypatch):
    monkeypatch.setenv(
        "ETHPM_IPFS_BACKEND_CLASS", "ethpm.backends.ipfs.LocalIPFSBackend"
    )
    backend = get_ipfs_backend()
    assert isinstance(backend, LocalIPFSBackend)
示例#10
0
def test_get_ipfs_backend_with_default_backend():
    backend = get_ipfs_backend()
    assert isinstance(backend, InfuraIPFSBackend)
示例#11
0
def test_get_ipfs_backend_default():
    backend = get_ipfs_backend()
    assert isinstance(backend, IPFSGatewayBackend)
示例#12
0
def test_builder_with_link_references(registry_package, dummy_ipfs_backend,
                                      monkeypatch):
    root, expected_manifest, compiler_output = registry_package
    ipfs_backend = get_ipfs_backend()
    monkeypatch.chdir(root)
    pinner = source_pinner(compiler_output, ipfs_backend)
    inliner = source_inliner(compiler_output)
    manifest = build(
        {},
        package_name("solidity-registry"),
        manifest_version("2"),
        version("2.0.0"),
        inliner("Authorized"),
        inliner("IndexedOrderedSetLib"),
        inliner("PackageDB"),
        inliner("PackageRegistry"),
        inliner("PackageRegistryInterface"),
        inliner("ReleaseDB"),
        inliner("ReleaseValidator"),
        contract_type(
            "AuthorityInterface",
            compiler_output,
            abi=True,
            deployment_bytecode=True,
            runtime_bytecode=True,
            natspec=True,
        ),
        contract_type(
            "Authorized",
            compiler_output,
            abi=True,
            deployment_bytecode=True,
            runtime_bytecode=True,
            natspec=True,
            compiler=True,
        ),
        contract_type(
            "AuthorizedInterface",
            compiler_output,
            abi=True,
            deployment_bytecode=True,
            runtime_bytecode=True,
            natspec=True,
        ),
        contract_type(
            "WhitelistAuthority",
            compiler_output,
            abi=True,
            deployment_bytecode=True,
            runtime_bytecode=True,
            natspec=True,
            compiler=True,
        ),
        contract_type(
            "WhitelistAuthorityInterface",
            compiler_output,
            abi=True,
            deployment_bytecode=True,
            runtime_bytecode=True,
            natspec=True,
        ),
        contract_type(
            "IndexedOrderedSetLib",
            compiler_output,
            abi=True,
            deployment_bytecode=True,
            runtime_bytecode=True,
            natspec=True,
            compiler=True,
        ),
        contract_type(
            "PackageDB",
            compiler_output,
            abi=True,
            deployment_bytecode=True,
            runtime_bytecode=True,
            natspec=True,
            compiler=True,
        ),
        contract_type(
            "PackageRegistry",
            compiler_output,
            abi=True,
            deployment_bytecode=True,
            runtime_bytecode=True,
            natspec=True,
            compiler=True,
        ),
        contract_type(
            "PackageRegistryInterface",
            compiler_output,
            abi=True,
            deployment_bytecode=True,
            runtime_bytecode=True,
            natspec=True,
        ),
        contract_type(
            "ReleaseDB",
            compiler_output,
            abi=True,
            deployment_bytecode=True,
            runtime_bytecode=True,
            natspec=True,
            compiler=True,
        ),
        contract_type(
            "ReleaseValidator",
            compiler_output,
            abi=True,
            deployment_bytecode=True,
            runtime_bytecode=True,
            natspec=True,
            compiler=True,
        ),
        validate(),
    )
    assert manifest == expected_manifest