def test_builder_deployment_type_complex(escrow_package):
    escrow, w3 = escrow_package
    escrow_dep_type = deployment_type(
        contract_instance="Escrow",
        contract_type="Escrow",
        deployment_bytecode={
            "bytecode":
            "0x608060405234801561001057600080fd5b5060405160208061045383398101604081815291516002819055336000818152602081815285822084905583855294519294919390927fddf252ad1be2c89b69c2b068fc378daa952ba7f163c4a11628f55a4df523b3ef929181900390910190a3506103d2806100816000396000f3006080604052600436106100775763ffffffff7c0100000000000000000000000000000000000000000000000000000000600035041663095ea7b3811461007c57806318160ddd146100b457806323b872dd146100db57806370a0823114610105578063a9059cbb14610126578063dd62ed3e1461014a575b600080fd5b34801561008857600080fd5b506100a0600160a060020a0360043516602435610171565b604080519115158252519081900360200190f35b3480156100c057600080fd5b506100c96101d8565b60408051918252519081900360200190f35b3480156100e757600080fd5b506100a0600160a060020a03600435811690602435166044356101de565b34801561011157600080fd5b506100c9600160a060020a03600435166102c9565b34801561013257600080fd5b506100a0600160a060020a03600435166024356102e4565b34801561015657600080fd5b506100c9600160a060020a036004358116906024351661037b565b336000818152600160209081526040808320600160a060020a038716808552908352818420869055815186815291519394909390927f8c5be1e5ebec7d5bd14f71427d1e84f3dd0314c0f7b2291e5b200ac8c7c3b925928290030190a35060015b92915050565b60025481565b600160a060020a03831660009081526020819052604081205482118015906102295750600160a060020a03841660009081526001602090815260408083203384529091529020548211155b80156102355750600082115b156102be57600160a060020a0380841660008181526020818152604080832080548801905593881680835284832080548890039055600182528483203384528252918490208054879003905583518681529351929391927fddf252ad1be2c89b69c2b068fc378daa952ba7f163c4a11628f55a4df523b3ef9281900390910190a35060016102c2565b5060005b9392505050565b600160a060020a031660009081526020819052604090205490565b3360009081526020819052604081205482118015906103035750600082115b15610373573360008181526020818152604080832080548790039055600160a060020a03871680845292819020805487019055805186815290519293927fddf252ad1be2c89b69c2b068fc378daa952ba7f163c4a11628f55a4df523b3ef929181900390910190a35060016101d2565b5060006101d2565b600160a060020a039182166000908152600160209081526040808320939094168252919091522054905600a165627a7a72305820cf9d6a3f751ca1e6b9bc2324e42633a4cde513d64c3e6cc32d6359629249e90200290000000000000000000000000000000000000000000000000000000000000001"  # noqa: E501
        },
        runtime_bytecode={
            "bytecode":
            "0x6080604052600436106100775763ffffffff7c0100000000000000000000000000000000000000000000000000000000600035041663095ea7b3811461007c57806318160ddd146100b457806323b872dd146100db57806370a0823114610105578063a9059cbb14610126578063dd62ed3e1461014a575b600080fd5b34801561008857600080fd5b506100a0600160a060020a0360043516602435610171565b604080519115158252519081900360200190f35b3480156100c057600080fd5b506100c96101d8565b60408051918252519081900360200190f35b3480156100e757600080fd5b506100a0600160a060020a03600435811690602435166044356101de565b34801561011157600080fd5b506100c9600160a060020a03600435166102c9565b34801561013257600080fd5b506100a0600160a060020a03600435166024356102e4565b34801561015657600080fd5b506100c9600160a060020a036004358116906024351661037b565b336000818152600160209081526040808320600160a060020a038716808552908352818420869055815186815291519394909390927f8c5be1e5ebec7d5bd14f71427d1e84f3dd0314c0f7b2291e5b200ac8c7c3b925928290030190a35060015b92915050565b60025481565b600160a060020a03831660009081526020819052604081205482118015906102295750600160a060020a03841660009081526001602090815260408083203384529091529020548211155b80156102355750600082115b156102be57600160a060020a0380841660008181526020818152604080832080548801905593881680835284832080548890039055600182528483203384528252918490208054879003905583518681529351929391927fddf252ad1be2c89b69c2b068fc378daa952ba7f163c4a11628f55a4df523b3ef9281900390910190a35060016102c2565b5060005b9392505050565b600160a060020a031660009081526020819052604090205490565b3360009081526020819052604081205482118015906103035750600082115b15610373573360008181526020818152604080832080548790039055600160a060020a03871680845292819020805487019055805186815290519293927fddf252ad1be2c89b69c2b068fc378daa952ba7f163c4a11628f55a4df523b3ef929181900390910190a35060016101d2565b5060006101d2565b600160a060020a039182166000908152600160209081526040808320939094168252919091522054905600a165627a7a72305820cf9d6a3f751ca1e6b9bc2324e42633a4cde513d64c3e6cc32d6359629249e9020029"  # noqa: E501
        },
        compiler={
            "name": "solc",
            "version": "0.4.24+commit.e67f0147.Emscripten.clang",
            "settings": {
                "optimize": True
            },
        },
    )
    safesendlib_dep_type = deployment_type(contract_instance="SafeSendLib",
                                           contract_type="SafeSendLib")
    manifest = build(
        {},
        package_name("escrow"),
        version("1.0.0"),
        manifest_version("ethpm/3"),
        escrow_dep_type(
            block_uri=
            "blockchain://1111111111111111111111111111111111111111111111111111111111111111/block/1234567890abcdef1234567890abcdef1234567890abcdef1234567890abcdef",  # noqa: E501
            address=escrow.deployments.get_instance("Escrow").address,
        ),
        # dep_type with block uri
        safesendlib_dep_type(
            block_uri=
            "blockchain://1111111111111111111111111111111111111111111111111111111111111111/block/1234567890abcdef1234567890abcdef1234567890abcdef1234567890abcdef",  # noqa: E501
            address=escrow.deployments.get_instance("SafeSendLib").address,
        ),
        # simple deployment
        deployment(
            block_uri=
            "blockchain://1234567890123456789012345678901234567890123456789012345678901234/block/1234567890abcdef1234567890abcdef1234567890abcdef1234567890abcdef",  # noqa: E501
            contract_instance="Escrow",
            contract_type="Escrow",
            address=escrow.deployments.get_instance("Escrow").address,
        ),
        # simple deployment
        deployment(
            block_uri=
            "blockchain://1234567890123456789012345678901234567890123456789012345678901234/block/1234567890abcdef1234567890abcdef1234567890abcdef1234567890abcdef",  # noqa: E501
            contract_instance="SafeSendLib",
            contract_type="SafeSendLib",
            address=escrow.deployments.get_instance("SafeSendLib").address,
        ),
        validate(),
    )
    assert len(manifest["deployments"].keys()) == 2
    assert len(list(manifest["deployments"].values())[0]) == 2
    assert len(list(manifest["deployments"].values())[1]) == 2
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
Esempio n. 3
0
def test_builder_with_manifest_validation():
    with pytest.raises(ValidationError, match="_invalid_package_name"):
        build(
            {},
            package_name("_invalid_package_name"),
            manifest_version("2"),
            version("1.0.0"),
            validate(),
        )
Esempio n. 4
0
def test_to_disk_with_invalid_args_raises_exception(manifest_dir,
                                                    write_to_disk_fn):
    with pytest.raises(ManifestBuildingError):
        build(
            {},
            package_name("package"),
            manifest_version("2"),
            version("1.0.0"),
            write_to_disk_fn,
        )
Esempio n. 5
0
def test_to_disk_uses_default_manifest_name(manifest_dir):
    build(
        {},
        package_name("package"),
        manifest_version("2"),
        version("1.0.0"),
        write_to_disk(manifest_root_dir=manifest_dir),
    )
    actual_manifest = (manifest_dir / "1.0.0.json").read_text()
    assert actual_manifest == MINIFIED_MANIFEST
Esempio n. 6
0
def test_builder_simple_with_package(w3):
    package = build(
        {},
        package_name("package"),
        manifest_version("2"),
        version("1.0.0"),
        as_package(w3),
    )
    assert isinstance(package, Package)
    assert package.version == "1.0.0"
Esempio n. 7
0
def test_builder_with_invalid_uri():
    with pytest.raises(ValidationError,
                       match="is not a supported content-addressed URI"):
        build(
            {},
            package_name("package"),
            version("1.0.0"),
            manifest_version("2"),
            build_dependency("package", "www.google.com"),
        )
Esempio n. 8
0
def test_builder_to_disk_uses_default_cwd(manifest_dir, monkeypatch):
    monkeypatch.chdir(manifest_dir)
    build(
        {},
        package_name("package"),
        manifest_version("2"),
        version("1.0.0"),
        write_to_disk(),
    )
    actual_manifest = (manifest_dir / "1.0.0.json").read_text()
    assert actual_manifest == MINIFIED_MANIFEST
def test_to_disk_writes_minified_manifest_as_default(manifest_dir):
    build(
        {},
        package_name("package"),
        manifest_version("ethpm/3"),
        version("1.0.0"),
        write_to_disk(manifest_root_dir=manifest_dir,
                      manifest_name="1.0.0.json"),
        validate(),
    )
    actual_manifest = (manifest_dir / "1.0.0.json").read_text()
    assert actual_manifest == MINIFIED_MANIFEST
Esempio n. 10
0
def test_builder_writes_manifest_to_disk(manifest_dir):
    build(
        {},
        package_name("package"),
        manifest_version("2"),
        version("1.0.0"),
        write_to_disk(manifest_root_dir=manifest_dir,
                      manifest_name="1.0.0.json",
                      prettify=True),
    )
    actual_manifest = (manifest_dir / "1.0.0.json").read_text()
    assert actual_manifest == PRETTY_MANIFEST
Esempio n. 11
0
 def get_simple_manifest(self, name: str, version: str) -> Manifest:
     composed_contract_types = self.get_contract_types()
     composed_inline_sources = self.get_source_tree()
     manifest = b.build(
         {},
         b.package_name(name),
         b.version(version),
         b.manifest_version("2"),
         *composed_inline_sources,
         *composed_contract_types,
         b.validate(),
     )
     return manifest
Esempio n. 12
0
def test_builder_pins_manifest_to_provided_ipfs_backend(backend):
    if not pytest.config.getoption("--integration"):
        pytest.skip("Not asked to run integration tests")

    minified_manifest_hash = "QmVwwpt2BAkmWQt4eNnswhWd6bYgLbnUQDMHdVMHotwiqz"
    (manifest, ) = b.build(
        {},
        b.package_name("package"),
        b.manifest_version("2"),
        b.version("1.0.0"),
        b.pin_to_ipfs(backend=backend),
    )
    assert manifest["Hash"] == minified_manifest_hash
    pinned_manifest = backend.fetch_uri_contents(manifest["Hash"])
    assert (
        pinned_manifest ==
        b'{"manifest_version":"2","package_name":"package","version":"1.0.0"}')
Esempio n. 13
0
def create_basic_manifest_from_solc_output(package_name: str, version: str,
                                           project_dir: Path) -> Manifest:
    solc_output = json.loads(
        (project_dir / SOLC_OUTPUT).read_text())["contracts"]
    contract_types = get_contract_types(solc_output)
    built_sources = build_inline_sources(contract_types, solc_output,
                                         project_dir / "contracts")
    built_types = build_contract_types(contract_types, solc_output)
    return b.build(
        {},
        b.package_name(package_name),
        b.manifest_version("ethpm/3"),
        b.version(version),
        *built_sources,
        *built_types,
        b.validate(),
    )
Esempio n. 14
0
def test_builder_with_pinner(owned_package, dummy_ipfs_backend):
    root, expected_manifest, compiler_output = owned_package
    ipfs_backend = get_ipfs_backend()
    pinner = source_pinner(compiler_output, ipfs_backend, root)
    manifest = build(
        {},
        package_name("owned"),
        manifest_version("2"),
        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"),
        pinner("Owned"),
        validate(),
    )

    assert manifest == expected_manifest
Esempio n. 15
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)
    manifest = build(
        {},
        package_name("registry"),
        manifest_version("2"),
        version("1.0.1"),
        pinner("IndexedOrderedSetLib"),
        pinner("PackageDB"),
        pinner("PackageRegistry"),
        pinner("PackageRegistryInterface"),
        pinner("ReleaseDB"),
        pinner("ReleaseValidator"),
        contract_type(
            "IndexedOrderedSetLib",
            compiler_output,
            abi=True,
            deployment_bytecode=True,
            runtime_bytecode=True,
        ),
        contract_type(
            "PackageDB",
            compiler_output,
            abi=True,
            deployment_bytecode=True,
            runtime_bytecode=True,
        ),
        contract_type(
            "PackageRegistry",
            compiler_output,
            abi=True,
            deployment_bytecode=True,
            runtime_bytecode=True,
        ),
        contract_type(
            "PackageRegistryInterface",
            compiler_output,
            abi=True,
            deployment_bytecode=True,
            runtime_bytecode=True,
        ),
        contract_type(
            "ReleaseDB",
            compiler_output,
            abi=True,
            deployment_bytecode=True,
            runtime_bytecode=True,
        ),
        contract_type(
            "ReleaseValidator",
            compiler_output,
            abi=True,
            deployment_bytecode=True,
            runtime_bytecode=True,
        ),
        validate(),
    )
    assert manifest == expected_manifest
Esempio n. 16
0
def gen_manifest_version() -> Callable[..., Manifest]:
    return b.manifest_version("2")
Esempio n. 17
0
def test_builder_with_link_references(registry_package, dummy_ipfs_backend,
                                      monkeypatch):
    root, expected_manifest, compiler_output = registry_package
    monkeypatch.chdir(root)
    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