Example #1
0
def test_deployment_addresses_from_dependencies():
    math_manifest = ethpm.get_manifest("ipfs://testipfs-math")
    assert ethpm.get_deployment_addresses(math_manifest, "Math", MAINNET_GENESIS_HASH)

    # math is a dependency of complex, the deployment should not be inherited
    complex_manifest = ethpm.get_manifest("ipfs://testipfs-complex")
    assert not ethpm.get_deployment_addresses(complex_manifest, "Math", MAINNET_GENESIS_HASH)
Example #2
0
def test_get_manifest_from_ipfs():
    path = _get_data_folder().joinpath("ethpm/zeppelin.snakecharmers.eth")
    if path.exists():
        shutil.rmtree(path)
    ethpm.get_manifest("erc1319://zeppelin.snakecharmers.eth:1/[email protected]")
    assert _get_data_folder().joinpath("ethpm/zeppelin.snakecharmers.eth").exists()
    ethpm.get_manifest("erc1319://zeppelin.snakecharmers.eth:1/[email protected]")
    assert _get_data_folder().joinpath("ethpm/zeppelin.snakecharmers.eth").exists()
Example #3
0
    def _deprecated_init(
        self,
        name: str,
        address: Optional[str] = None,
        abi: Optional[List] = None,
        manifest_uri: Optional[str] = None,
        owner: Optional[AccountsType] = None,
    ) -> None:
        if manifest_uri and abi:
            raise ValueError(
                "Contract requires either abi or manifest_uri, but not both")
        if manifest_uri is not None:
            manifest = ethpm.get_manifest(manifest_uri)
            abi = manifest["contract_types"][name]["abi"]
            if address is None:
                address_list = ethpm.get_deployment_addresses(manifest, name)
                if not address_list:
                    raise ContractNotFound(
                        f"'{manifest['package_name']}' manifest does not contain"
                        f" a deployment of '{name}' on this chain")
                if len(address_list) > 1:
                    raise ValueError(
                        f"'{manifest['package_name']}' manifest contains more than one "
                        f"deployment of '{name}' on this chain, you must specify an address:"
                        f" {', '.join(address_list)}")
                address = address_list[0]
            name = manifest["contract_types"][name]["contract_name"]
        elif not address:
            raise TypeError(
                "Address cannot be None unless creating object from manifest")

        build = {"abi": abi, "contractName": name, "type": "contract"}
        _ContractBase.__init__(self, None, build, {})  # type: ignore
        _DeployedContractBase.__init__(self, address, owner, None)
def test_contract_types():
    contract_types = ethpm.get_manifest(
        "ipfs://testipfs-complex")["contract_types"]
    assert "ComplexNothing" in contract_types
    assert "abi" in contract_types["ComplexNothing"]
    assert contract_types["ComplexNothing"][
        "source_path"] == "contracts/Complex.sol"
def test_deployment_addresses_genesis_hash(network):
    manifest = ethpm.get_manifest("ipfs://testipfs-complex")
    ropsten = ethpm.get_deployment_addresses(manifest, "ComplexNothing",
                                             ROPSTEN_GENESIS_HASH)
    assert len(ropsten) == 1
    network.connect("ropsten")
    assert ropsten == ethpm.get_deployment_addresses(manifest,
                                                     "ComplexNothing")
def test_meta_brownie():
    manifest = ethpm.get_manifest(
        "ethpm://zeppelin.snakecharmers.eth:1/[email protected]")
    assert manifest["meta_brownie"] == {
        "registry_address": "zeppelin.snakecharmers.eth",
        "manifest_uri":
        "ipfs://QmWqn5uYx9LvV4aqj2qZ5FiFZykmS3LGdLpod7XLjxPVYr",
    }
def test_get_deployment_addresses_active_network():
    manifest = ethpm.get_manifest("ipfs://testipfs-complex")
    mainnet_addresses = ethpm.get_deployment_addresses(manifest,
                                                       "ComplexNothing",
                                                       MAINNET_GENESIS_HASH)
    assert len(mainnet_addresses) == 2
    ropsten_addresses = ethpm.get_deployment_addresses(manifest,
                                                       "ComplexNothing",
                                                       ROPSTEN_GENESIS_HASH)
    assert len(ropsten_addresses) == 1
    assert ropsten_addresses[0] not in mainnet_addresses
Example #8
0
    def from_ethpm(
        cls,
        name: str,
        manifest_uri: str,
        address: Optional[str] = None,
        owner: Optional[AccountsType] = None,
    ) -> "Contract":
        """
        Create a new `Contract` object from an ethPM manifest.

        Arguments
        ---------
        name : str
            Name of the contract.
        manifest_uri : str
            erc1319 registry URI where the manifest is located
        address : str optional
            Address where the contract is deployed. Only required if the
            manifest contains more than one deployment with the given name
            on the active chain.
        owner : Account, optional
            Contract owner. If set, transactions without a `from` field
            will be performed using this account.
        """
        manifest = ethpm.get_manifest(manifest_uri)

        if address is None:
            address_list = ethpm.get_deployment_addresses(manifest, name)
            if not address_list:
                raise ContractNotFound(
                    f"'{manifest['package_name']}' manifest does not contain"
                    f" a deployment of '{name}' on this chain"
                )
            if len(address_list) > 1:
                raise ValueError(
                    f"'{manifest['package_name']}' manifest contains more than one "
                    f"deployment of '{name}' on this chain, you must specify an address:"
                    f" {', '.join(address_list)}"
                )
            address = address_list[0]

        manifest["contract_types"][name]["contract_name"]
        build = {
            "abi": manifest["contract_types"][name]["abi"],
            "contractName": name,
            "natspec": manifest["contract_types"][name]["natspec"],
            "type": "contract",
        }

        self = cls.__new__(cls)
        _ContractBase.__init__(self, None, build, manifest["sources"])  # type: ignore
        _DeployedContractBase.__init__(self, address, owner)
        _add_deployment(self)
        return self
Example #9
0
def test_pin_and_get(dep_project):
    package_config = ETHPM_CONFIG.copy()
    package_config["settings"]["include_dependencies"] = False
    manifest, uri = ethpm.create_manifest(dep_project._path, package_config, True)

    process = ethpm.process_manifest(manifest, uri)
    get = ethpm.get_manifest(uri)

    for key in list(process) + list(get):
        if type(process[key]) is str:
            assert process[key] == get[key]
            continue
        for k in list(process[key]) + list(get[key]):
            assert process[key][k] == get[key][k]
Example #10
0
def from_ethpm(uri: str) -> "TempProject":

    """
    Generates a TempProject from an ethPM package.
    """

    manifest = get_manifest(uri)
    compiler_config = {
        "evm_version": None,
        "solc": {"version": None, "optimize": True, "runs": 200},
        "vyper": {"version": None},
    }
    project = TempProject(manifest["package_name"], manifest["sources"], compiler_config)
    if web3.isConnected():
        for contract_name in project.keys():
            for address in get_deployment_addresses(manifest, contract_name):
                project[contract_name].at(address)
    return project
Example #11
0
def _install_from_ethpm(uri: str) -> str:
    manifest = get_manifest(uri)
    org = manifest["meta_brownie"]["registry_address"]
    repo = manifest["package_name"]
    version = manifest["version"]

    install_path = _get_data_folder().joinpath(f"packages/{org}")
    install_path.mkdir(exist_ok=True)
    install_path = install_path.joinpath(f"{repo}@{version}")
    if install_path.exists():
        raise FileExistsError("Package is aleady installed")

    try:
        new(str(install_path), ignore_existing=True)
        ethpm.install_package(install_path, uri)
        project = load(install_path)
        project.close()
    except Exception as e:
        shutil.rmtree(install_path)
        raise e

    return f"{org}/{repo}@{version}"
Example #12
0
def test_dependency_paths():
    sources = ethpm.get_manifest("ipfs://testipfs-complex")["sources"]
    assert "contracts/Complex.sol" in sources
    assert "contracts/math/Math.sol" in sources
    assert "contracts/utils/Arrays.sol" in sources
Example #13
0
def test_get_mock_manifests():
    ethpm.get_manifest("ipfs://testipfs-math")
    ethpm.get_manifest("ipfs://testipfs-utils")
    ethpm.get_manifest("ipfs://testipfs-complex")