Example #1
0
def normalize_integration_type(
        itype: 'IntegrationTypeInfo', runtime: str,
        daml_model_info: 'Optional[DamlModelInfo]') -> 'IntegrationTypeInfo':

    if itype.runtime:
        LOG.warn(f'Explicit integration type runtime {itype.runtime} ignored'
                 f' for integration ID {itype.id}. This field does not need to'
                 f' be specified.')

    updates = {
        # Runtime is currently fixed at python direct, and is
        # controlled by the ddit build process anyway, so makes sense
        # to populate here.
        'runtime': runtime
    }

    if itype.instance_template:
        if daml_model_info is None:
            # This could be fixed by adding another option to
            # explicitly bind a Daml model even when ddit is not
            # managind the Daml model build.
            die(f'Instance templates cannot be used with --skip-dar-build, due to lack of'
                f'Daml model info.')

        if itype.instance_template == '*':
            die(f'Integration type instance templates cannot be a wildcard and must'
                f' explicitly specify a template.')

        package = package_ref(parse_type_con_name(itype.instance_template))

        if package == '*':
            updates[
                'instance_template'] = f'{daml_model_info.main_package_id}:{itype.instance_template}'

    return replace(itype, **updates)
def test_contract_id():
    name = parse_type_con_name("0000deadbeef0000:MyMod:MyName")
    cid = ContractId(name, "#4:8")

    expected = '{"cid": "#4:8"}'
    actual = json.dumps({"cid": cid}, cls=JSONEncoder)
    assert expected == actual
def test_exercise_command_with_provided_arg():
    cid = ContractId(parse_type_con_name("Mod:Tmpl"), "#0:0")

    cmd_v8 = v8.ExerciseCommand(cid, "DoSomethingWithArg", {"ok": True})

    with pytest.warns(DeprecationWarning):
        cmd_v7 = v7.ExerciseCommand(cid, "DoSomethingWithArg", {"ok": True})
    with pytest.warns(DeprecationWarning):
        c_argument_deprecated = cmd_v7.arguments

    assert cmd_v8.contract_id == cmd_v7.contract_id
    assert cmd_v8.choice == cmd_v7.choice
    assert cmd_v8.argument == cmd_v7.argument == c_argument_deprecated
    assert cmd_v8 == cmd_v7
Example #4
0
def ensure_package_id(daml_model: 'Optional[DamlModelInfo]',
                      template: str) -> str:

    if template == '*':
        return template

    package = package_ref(parse_type_con_name(template))

    if package != '*':
        return template

    if daml_model is None:
        raise Exception(
            f'No default model {package} known when ensuring package ID: {template}'
        )
    else:
        return f'{daml_model.main_package_id}:{template}'
Example #5
0
# Copyright (c) 2017-2021 Digital Asset (Switzerland) GmbH and/or its affiliates. All rights reserved.
# SPDX-License-Identifier: Apache-2.0

from unittest import TestCase

from dazl.client.commands import CommandBuilder, CommandDefaults, CommandPayload, create
from dazl.damlast.lookup import parse_type_con_name
from dazl.ledger import CreateCommand, ExerciseCommand
from dazl.prim import ContractId, Party
import pytest

SOME_TEMPLATE_NAME = parse_type_con_name("Sample:Untyped")
SOME_PARTY = Party("SomeParty")
SOME_CONTRACT_ID = ContractId(SOME_TEMPLATE_NAME, "#0:0")
DEFAULTS = CommandDefaults(
    default_party=SOME_PARTY,
    default_ledger_id="some_ledger",
    default_workflow_id="some_workflow",
    default_application_id="some_app",
    default_command_id="some_commands",
)


class TestCommandBuilderTest(TestCase):
    """
    Tests for the various ways that helper objects are converted to :class:`CommandPayload`.
    """
    def test_single_create_untyped(self):
        with pytest.warns(DeprecationWarning):
            expr = create("Sample:Untyped", {"arg": 1})
Example #6
0
# Copyright (c) 2017-2021 Digital Asset (Switzerland) GmbH and/or its affiliates. All rights reserved.
# SPDX-License-Identifier: Apache-2.0

from datetime import datetime, timezone

from dazl.damlast.lookup import parse_type_con_name
from dazl.prim import ContractId, to_datetime

DUMMY_TEMPLATE_ID = parse_type_con_name("00:DummyModule:DummyTemplate")


def test_contract_id_as_dict_key():
    cid_a = ContractId(DUMMY_TEMPLATE_ID, "1")
    cid_b = ContractId(DUMMY_TEMPLATE_ID, "1")
    test_dict = dict()
    test_dict[cid_a] = "hello world"

    assert test_dict[cid_b] == "hello world"


def test_simple_date_parse():
    expected = datetime(2018, 8, 7, 23, 17, 31, 143080, tzinfo=timezone.utc)
    actual = to_datetime("2018-08-07T23:17:31.143080Z")
    assert expected == actual


def test_simple_date_parse_with_nanos():
    expected = datetime(2018, 8, 7, 23, 17, 31, 143080, tzinfo=timezone.utc)
    actual = to_datetime("2018-08-07T23:17:31.143080698Z")
    assert expected == actual
Example #7
0
def test_damlast_parse_type_con_name():
    name = parse_type_con_name("*")

    assert package_ref(name) == "*"
    assert package_local_name(name) == "*"
Example #8
0
def test_damlast_parse_type_con_name_package_only():
    name = parse_type_con_name("abc123def456abc123def456:*")

    assert package_ref(name) == "abc123def456abc123def456"
    assert package_local_name(name) == "*"
Example #9
0
def test_damlast_parse_type_con_name_fully_qualified():
    name = parse_type_con_name(
        "abc123def456abc123def456:SomeModule:SomeEntity")

    assert package_ref(name) == "abc123def456abc123def456"
    assert package_local_name(name) == "SomeModule:SomeEntity"
Example #10
0
def test_damlast_parse_type_con_name_unknown_package():
    name = parse_type_con_name("SomeModule:SomeEntity")

    assert package_ref(name) == "*"
    assert package_local_name(name) == "SomeModule:SomeEntity"
Example #11
0
from dazl.damlast.lookup import parse_type_con_name
from dazl.query import EMPTY, Filter, parse_query
import pytest

SuperCoolTmpl = parse_type_con_name("SuperCool:Tmpl")
ReallyCoolTmpl = parse_type_con_name("ReallyCool:Tmpl")


@pytest.mark.parametrize("server_side_filters", [False, True])
def test_empty_query(server_side_filters):
    actual = parse_query(server_side_filters=server_side_filters)
    assert actual is None


@pytest.mark.parametrize("server_side_filters", [False, True])
def test_single_template(server_side_filters):
    expected = {SuperCoolTmpl: EMPTY}
    actual = parse_query("SuperCool:Tmpl",
                         server_side_filters=server_side_filters)

    assert expected == actual


@pytest.mark.parametrize(
    "queries",
    [
        ["SuperCool:Tmpl", "ReallyCool:Tmpl"],
        [["SuperCool:Tmpl", "ReallyCool:Tmpl"]],
        [{"SuperCool:Tmpl", "ReallyCool:Tmpl"}],
        [{
            "SuperCool:Tmpl": {},