def run(self, url): set_event_loop(new_event_loop()) self.done = asyncio.Event() self.network.set_config(url=url) # TODO: These should be party allocations instead of just random strings. self.user_parties = frozenset( Party(str(uuid.uuid4())) for _ in range(0, PARTY_COUNT)) operator = self.network.aio_new_party() operator.add_ledger_ready(self.on_ready) operator.add_ledger_created(Simple.OperatorRole, self.on_operator) operator.add_ledger_created(Simple.OperatorNotification, self.on_notification) self.operator_party = operator.party self.network.run_until_complete(self.done.wait())
async def test_some_party_receives_public_contract(sandbox): some_party_cids = [] publisher_cids = [] # TODO: Switch to a Party allocation API when available. all_party = Party(str(uuid.uuid4())) async with async_network(url=sandbox, dars=AllPartyDar) as network: network.set_config(party_groups=[all_party]) some_client = network.aio_new_party() some_client.add_ledger_ready(lambda _: some_client.create( PrivateContract, {"someParty": some_client.party})) publisher_client = network.aio_new_party() publisher_client.add_ledger_ready( lambda _: publisher_client.create(PublicContract, { "publisher": publisher_client.party, "allParty": all_party })) some_client.add_ledger_created(PublicContract, lambda e: some_party_cids.append(e.cid)) some_client.add_ledger_created(PrivateContract, lambda e: some_party_cids.append(e.cid)) publisher_client.add_ledger_created( PublicContract, lambda e: publisher_cids.append(e.cid)) publisher_client.add_ledger_created( PrivateContract, lambda e: publisher_cids.append(e.cid)) network.start() logging.info( "got to the end with some_party contracts: %s and publisher contracts: %s", some_party_cids, publisher_cids, ) assert len(some_party_cids) == 2 assert len(publisher_cids) == 1
def test_api_consistency(): from dazl.client._network_client_impl import _NetworkImpl from dazl.client._party_client_impl import _PartyClientImpl impl = _PartyClientImpl(_NetworkImpl(), Party("party")) apc = AIOPartyClient(impl) tpc = SimplePartyClient(impl) callable_apcs = { key: getattr(apc, key) for key in dir(apc) if not key.startswith("_") and callable(getattr(apc, key)) } callable_tpcs = { key: getattr(tpc, key) for key in dir(tpc) if not key.startswith("_") and callable(getattr(tpc, key)) } assert sorted(set(callable_apcs.keys())) == sorted( set(callable_tpcs.keys()))
# Copyright (c) 2019 Digital Asset (Switzerland) GmbH and/or its affiliates. All rights reserved. # SPDX-License-Identifier: Apache-2.0 from unittest import TestCase from dazl import sandbox, exercise, Party, simple_client from .dars import Simple PARTY = Party('Operator') OperatorRole = 'Simple.OperatorRole' OperatorNotification = 'Simple.OperatorNotification' class TestThreadsafeMethods(TestCase): def test_threadsafe_methods(self): with sandbox(Simple) as proc: with simple_client(proc.url, PARTY) as client: client.ready() client.submit_create(OperatorRole, {'operator': PARTY}) operator_cid, _ = client.find_one(OperatorRole) client.submit_exercise(operator_cid, 'PublishMany', dict(count=5)) notifications = client.find_nonempty(OperatorNotification, {'operator': PARTY}, min_count=5) contracts_to_delete = [] for cid, cdata in notifications.items(): if int(cdata['text']) <= 3: contracts_to_delete.append(cid)
def test_party_config_allows_list(): config = NetworkConfig.parse_kwargs(parties=["Bob"], url="http://nowhere/") assert config.parties[0].party == Party("Bob") assert config.parties[0].url == "http://nowhere/"
def test_party_config_allows_single_string(): config = NetworkConfig.parse_kwargs(parties="Bob", url="http://nowhere/") assert config.parties[0].party == Party("Bob") assert config.parties[0].url == "http://nowhere/"