Beispiel #1
0
def test_builder_with_alias_and_select_contract_types(owned_package_devdoc):
    _, _, compiler_output = owned_package_devdoc

    manifest = build(
        BASE_MANIFEST,
        contract_type(
            "Owned",
            compiler_output,
            alias="OwnedAlias",
            abi=True,
            natspec=True,
            deployment_bytecode=True,
            runtime_bytecode=True,
            compiler=True,
        ),
        validate(),
    )

    contract_type_data = normalize_contract_type(
        compiler_output["Owned.sol"]["Owned"])
    expected = assoc(
        BASE_MANIFEST,
        "contract_types",
        {"OwnedAlias": assoc(contract_type_data, "contract_type", "Owned")},
    )
    assert manifest == expected
Beispiel #2
0
def test_builder_with_default_contract_types(owned_package):
    _, _, compiler_output = owned_package

    manifest = build(BASE_MANIFEST, contract_type("Owned", compiler_output),
                     validate())

    contract_type_data = normalize_contract_type(
        compiler_output["Owned.sol"]["Owned"])
    expected = assoc(BASE_MANIFEST, "contract_types",
                     {"Owned": contract_type_data})
    assert manifest == expected
Beispiel #3
0
def test_builder_without_alias_and_with_select_contract_types(owned_package):
    _, _, compiler_output = owned_package

    manifest = build(BASE_MANIFEST,
                     contract_type("Owned", compiler_output, abi=True),
                     validate())

    contract_type_data = normalize_contract_type(
        compiler_output["Owned.sol"]["Owned"])
    selected_data = {
        k: v
        for k, v in contract_type_data.items() if k != "deployment_bytecode"
    }
    expected = assoc(BASE_MANIFEST, "contract_types", {"Owned": selected_data})
    assert manifest == expected
def test_builder_with_default_contract_types(owned_package):
    _, _, compiler_output = owned_package

    manifest = build(BASE_MANIFEST, contract_type("Owned", compiler_output),
                     validate())

    contract_type_data = normalize_contract_type(
        compiler_output["Owned.sol"]["Owned"], "Owned.sol")
    compilers_data = contract_type_data.pop('compiler')
    compilers_data["contractTypes"] = ["Owned"]
    expected_with_contract_type = assoc(BASE_MANIFEST, "contractTypes",
                                        {"Owned": contract_type_data})
    expected = assoc(expected_with_contract_type, "compilers",
                     [compilers_data])
    assert manifest == expected
Beispiel #5
0
def test_builder_with_single_alias_kwarg(owned_package):
    _, _, compiler_output = owned_package

    manifest = build(
        BASE_MANIFEST,
        contract_type("Owned", compiler_output, alias="OwnedAlias"),
        validate(),
    )

    contract_type_data = normalize_contract_type(
        compiler_output["Owned.sol"]["Owned"])
    expected = assoc(
        BASE_MANIFEST,
        "contract_types",
        {"OwnedAlias": assoc(contract_type_data, "contract_type", "Owned")},
    )
    assert manifest == expected
def test_builder_without_alias_and_with_select_contract_types(owned_package):
    _, _, compiler_output = owned_package

    manifest = build(
        BASE_MANIFEST,
        contract_type("Owned", compiler_output, abi=True, source_id=True),
        validate())

    contract_type_data = normalize_contract_type(
        compiler_output["Owned.sol"]["Owned"], "Owned.sol")
    omitted_fields = ("deploymentBytecode", "userdoc", "devdoc", "compiler")
    selected_data = {
        k: v
        for k, v in contract_type_data.items() if k not in omitted_fields
    }
    expected = assoc(BASE_MANIFEST, "contractTypes", {"Owned": selected_data})
    assert manifest == expected
def test_builder_manages_duplicate_compilers(owned_package):
    _, _, compiler_output = owned_package

    manifest = build(
        BASE_MANIFEST,
        contract_type(
            "Owned",
            compiler_output,
            abi=True,
            compiler=True,
            source_id=True,
        ),
        contract_type(
            "Owned",
            compiler_output,
            alias="OwnedAlias",
            abi=True,
            compiler=True,
            source_id=True,
        ),
        validate(),
    )
    contract_type_data = normalize_contract_type(
        compiler_output["Owned.sol"]["Owned"], "Owned.sol")
    compiler_data = contract_type_data.pop("compiler")
    contract_type_data.pop('deploymentBytecode')
    contract_type_data.pop('devdoc')
    contract_type_data.pop('userdoc')
    compiler_data_with_contract_types = assoc(compiler_data, 'contractTypes',
                                              ['Owned', 'OwnedAlias'])
    expected_with_contract_types = assoc(
        BASE_MANIFEST,
        "contractTypes",
        {
            "Owned": assoc(contract_type_data, "contractType", "Owned"),
            "OwnedAlias": assoc(contract_type_data, "contractType", "Owned"),
        },
    )
    expected_with_contract_types['contractTypes']['Owned'].pop("contractType")
    expected = assoc(expected_with_contract_types, 'compilers',
                     [compiler_data_with_contract_types])
    assert manifest == expected