Example #1
0
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_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 test_serialize_exercise(dar_fixture):
    sut = ProtobufSerializer(dar_fixture.lookup)

    tref = dar_fixture.lookup.data_type_name("Pending:AccountRequest")
    cid = ContractId(tref, "#1:0")
    command = ExerciseCommand(cid, "CreateAccount", dict(accountId=42))

    expected = G_Command()
    expected.exercise.contract_id = "#1:0"
    expected.exercise.template_id.MergeFrom(
        dar_fixture.get_identifier("Pending:AccountRequest"))
    expected.exercise.choice = "CreateAccount"
    expected.exercise.choice_argument.record.fields.append(
        G_RecordField(label="accountId", value=G_Value(int64=42)))
    actual = sut.serialize_command(command)

    assert expected == actual
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})