示例#1
0
async def test_acs(sandbox):
    async with connect_with_new_party(url=sandbox, dar=PostOffice, party_count=4) as (
        postman,
        p1,
        p2,
        p3,
    ):
        event = await postman.connection.create("Main:PostmanRole", {"postman": postman.party})
        await postman.connection.exercise(
            event.contract_id, "InviteParticipant", {"party": p1.party, "address": "P1"}
        )
        await postman.connection.exercise(
            event.contract_id, "InviteParticipant", {"party": p2.party, "address": "P2"}
        )
        await postman.connection.exercise(
            event.contract_id, "InviteParticipant", {"party": p3.party, "address": "P3"}
        )

        logging.info("Accepting roles...")
        await gather(*[accept_roles(sandbox, party) for party in (p1.party, p2.party, p3.party)])
        logging.info("Roles accepted.")

        async with ACS(postman.connection, {"Main:AuthorRole": {}, "Main:ReceiverRole": {}}) as acs:
            snapshot = acs.read_immediately()

            authors = snapshot.matching_contracts("Main:AuthorRole")
            receivers = snapshot.matching_contracts("Main:ReceiverRole")

            assert 3 == len(authors)
            assert 3 == len(receivers)
            logging.info("Authors: %r", authors)
            logging.info("Receivers: %r", receivers)
示例#2
0
async def test_protocol_ledger_api(sandbox):
    # first, administrative stuff--upload the DAR and allocate two parties that we'll use later
    async with connect_with_new_party(url=sandbox, dar=PostOffice, party_count=2) as (postman, p1):
        event = await postman.connection.create("Main:PostmanRole", {"postman": postman.party})
        result = await postman.connection.exercise(
            event.contract_id, "InviteParticipant", {"party": p1.party, "address": "Somewhere!"}
        )
        logging.info("Result of inviting a participant: %s", result)

        # Stream results for Main:InviteAuthorRole, and then Main:InviteReceiverRole. Then break the
        # stream once we find the first contract.
        #
        # We do NOT use query() here, because in a distributed ledger setting, the result of the
        # postman inviting participants may not yet have been observed by the clients. Instead, use
        # stream() since it remains open until explicitly closed. We break the never-ending iterator
        # as soon as we see one of each contract.
        async with p1.connection.stream("Main:InviteAuthorRole") as query:
            async for event in query:
                result = await p1.connection.exercise(event.contract_id, "AcceptInviteAuthorRole")
                logging.info("The result of AcceptInviteAuthorRole: %s", result)
                break

        async with p1.connection.stream("Main:InviteReceiverRole") as query:
            async for event in query:
                result = await p1.connection.exercise(event.contract_id, "AcceptInviteReceiverRole")
                logging.info("The result of AcceptInviteReceiverRole: %s", result)
                break

    logging.info("Done!")
示例#3
0
async def test_create(sandbox):
    async with connect_with_new_party(url=sandbox, dar=KitchenSink,
                                      admin=True) as p:
        suppliers_party_info = await p.connection.allocate_party()
        await p.connection.create(
            "KitchenSink.Warehouse:Warehouse",
            {
                "warehouse": p.party,
                "suppliers": suppliers_party_info.party,
                "location": "Somewhere",
            },
        )
示例#4
0
async def test_exercise_by_key(sandbox):
    async with connect_with_new_party(url=sandbox, dar=KitchenSink) as p:
        await p.connection.create(
            "KitchenSink.Retailer:Retailer",
            {
                "retailer": p.party,
                "name": "Kitchen Sinks R Us",
                "website": "kitchensinksrus.local",
            },
        )

        result = await p.connection.exercise_by_key(
            "KitchenSink.Retailer:Retailer",
            "UpdateWebsite",
            p.party,
            {"newWebsite": "kitchensinksrus.com"},
        )

        logging.info("Choice result: %r", result.result)
async def test_acs(sandbox):
    async with connect_with_new_party(url=sandbox, dar=PostOffice) as p:
        await p.connection.create("Main:PostmanRole", {"postman": p.party})
        snapshot = None  # type: Optional[Snapshot]
        snapshot_loop_count = 0

        with pytest.raises(ConnectionClosedError):
            async for state, s in snapshots(p.connection, "Main:PostmanRole"):
                # once we get one snapshot successfully, remember that we did, and kill our connection
                if state == RUNNING:
                    snapshot_loop_count += 1
                    snapshot = s

                    # ok so now we got the snapshot; kill the connection
                    await p.connection.close()

        # we should have only run the loop once
        assert snapshot_loop_count == 1

        # the snapshot should also not be empty
        assert snapshot
示例#6
0
async def test_acs_can_async_read(sandbox):
    async with connect_with_new_party(url=sandbox, dar=PostOffice) as p:
        async with ACS(p.connection, {"Main:PostmanRole"}) as acs:
            await acs.read()

    assert True