def test_threadsafe_methods(sandbox):
    party = blocking_setup(sandbox, Simple)

    with simple_client(url=sandbox, party=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)

        client.submit(
            [exercise(cid, "Archive") for cid in contracts_to_delete])

        client.submit_exercise(operator_cid, "PublishMany", dict(count=3))

        print(client.find_active("*"))
示例#2
0
def test_complicated_map_support():
    with sandbox(MapSupport) as proc:
        with simple_client(url=proc.url, party='Test') as client:
            client.ready()
            client.submit_create(
                'MapSupport.ComplicatedSample',
                {
                    'party': 'Test',
                    # Note: Python `dict`s are not hashable, so the only way to write this out
                    # is to create a special dict as a key
                    'keyIsMap': {
                        frozendict(A='b'): 'mmm'
                    },
                    'keyIsRecord': {
                        frozendict(x=2, y=4): 'rrr'
                    },
                    'keyIsRecordWithTypeParam': {
                        frozendict(x=2, y=4): 'rrr'
                    },
                    'keyIsVariant': {
                        frozendict(Apple=''): 'ttt'
                    }
                })

            logging.info(client.find_active('*'))
    def test_event_handler_exceptions(self):
        with sandbox(daml_path=DAML_PATH) as proc:
            with simple_client(proc.url, SAMPLE_PARTY) as client:
                def throw_error(event: ReadyEvent):
                    raise MagicException(event.ledger_id)

                client.add_ledger_ready(throw_error)
                client.ready()
 def test_record_dotted_fields_submit(self):
     with sandbox(daml_path=DottedFields) as proc:
         with simple_client(url=proc.url, party='Test') as client:
             client.ready()
             client.submit_create('DottedFields.American', {
                 'person': 'Test',
                 'address.address': '1 Test Place',
                 'address.city': 'Somewhere',
                 'address.state': 'ZZ',
                 'address.zip': '99999'
             })
             print(client.find_active('DottedFields.American'))
示例#5
0
def test_simple_client_api(sandbox):
    party = blocking_setup(sandbox, PostOffice)

    logging.info('Creating client...')
    with simple_client(url=sandbox, party=party) as client:
        client.ready()
        logging.info('Submitting...')
        client.submit_create('Main:PostmanRole', {'postman': party})
        logging.info('getting contracts')
        contracts = client.find_active('*')
        logging.info('got the contracts')

    assert 1 == len(contracts)
 def test_map_support(self):
     with sandbox(daml_path=DAML_FILE) as proc:
         with simple_client(url=proc.url, party='Test') as client:
             client.ready()
             client.submit_create('MapSupport.Sample', {
                 'party': 'Test',
                 'mappings': {
                     65: 'A',
                     97: 'a'
                 },
                 'text': None
             })
             print(client.find_active('*'))
def test_simple_client_api(sandbox):
    party = blocking_setup(sandbox, PostOffice)

    logging.info("Creating client...")
    with simple_client(url=sandbox, party=party) as client:
        client.ready()
        logging.info("Submitting...")
        client.submit_create("Main:PostmanRole", {"postman": party})
        logging.info("getting contracts")
        contracts = client.find_active("*")
        logging.info("got the contracts")

    assert 1 == len(contracts)
示例#8
0
def test_map_support():
    with sandbox(MapSupport) as proc:
        with simple_client(url=proc.url, party='Test') as client:
            client.ready()
            client.submit_create('MapSupport.Sample', {
                'party': 'Test',
                'mappings': {
                    '65': 'A',
                    '97': 'a'
                },
                'text': None
            })

            logging.info(client.find_active('*'))
示例#9
0
def test_simple_client_api():
    party = 'abc'

    LOG.info('Creating sandbox...')
    with sandbox(daml_path=DAML_FILE) as proc:
        LOG.info('Creating client...')
        with simple_client(url=proc.url, party=party) as client:
            client.ready()
            LOG.info('Submitting...')
            client.submit_create('Main.PostmanRole', {'postman': party})
            LOG.info('getting contracts')
            contracts = client.find_active('*')
            LOG.info('got the contracts')

    assert 1 == len(contracts)
    def test_variant_dotted_fields_submit(self):
        with sandbox(daml_path=DottedFields) as proc:
            with simple_client(url=proc.url, party='Test') as client:
                client.ready()
                client.submit_create('DottedFields.Person', {
                    'person': 'Test',
                    'address.US.address': '1 Test Place',
                    'address.US.city': 'Somewhere',
                    'address.US.state': 'ZZ',
                    'address.US.zip': '99999',
                    'address.UK.address': '',
                    'address.UK.locality': '',
                    'address.UK.city': '',
                    'address.UK.state': '',
                    'address.UK.postcode': '',

                })
                print(client.find_active('DottedFields.Person'))
示例#11
0
    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)

                client.submit([exercise(cid, 'Archive') for cid in contracts_to_delete])

                client.submit_exercise(operator_cid, 'PublishMany', dict(count=3))

                print(client.find_active('*'))
示例#12
0
def test_simple_flask_integration():
    setup_default_logger(logging.INFO)
    with sandbox(daml_path=DAML_PATH) as proc:
        with simple_client(proc.url, SAMPLE_PARTY) as client:
            # seed the ledger with some initial state
            client.add_ledger_ready(create_initial_state)

            LOG.info('Waiting for the client to be ready...')
            client.ready()
            LOG.info('Client is ready.')

            # now start a Flask app
            LOG.info('Starting up the flask app...')
            main_thread = Thread(target=run_flask_app, args=(client, 9999))
            main_thread.start()

            returned_data = run_flask_test(9999)
            assert returned_data == {'postman': SAMPLE_PARTY}

            main_thread.join(30)
            if main_thread.is_alive():
                raise Exception(
                    'The Flask thread should have terminated, but did not.')
示例#13
0
import dazl
import pickle
import time

with dazl.simple_client('http://localhost:6865', 'boy') as client:
    client.ready()
    client.submit_create_and_exercise(
        'ContactRelatedContracts.PersonalContract', {
            'userPartyId': 'boy',
            'personalDetails': {
                'name': 'Alice',
                'phoneNo': '00000',
                'address': 'address',
                'pincode': '110014'
            }
        }, 'CreateContactConfirmationContract', {})

with dazl.simple_client('http://localhost:6865', 'towerGuard') as client:
    client.ready()
    client.submit_create_and_exercise(
        'ContactRelatedContracts.PersonalContract', {
            'userPartyId': 'towerGuard',
            'personalDetails': {
                'name': 'Himesh',
                'phoneNo': '00000',
                'address': 'address',
                'pincode': '110014'
            }
        }, 'CreateContactConfirmationContract', {})

with dazl.simple_client('http://localhost:6865', 'gateGuard') as client:
示例#14
0
from dazl import simple_client


with simple_client() as client:
    client.ready()
    client.submit_create('Sample.HelloRole', {'party': client.party})
    cid, cdata = client.find_one('Sample.HelloRole')
    client.submit_exercise(cid, 'SayHello', {
        'to': 'Bob',
        'message': 'Hello World'
    })