Пример #1
0
async def test_different_accounts(test_suite: ServerTestSuite):
    params1 = test_suite.get_agent_params('agent1')
    params2 = test_suite.get_agent_params('agent2')
    agent1 = Agent(
        server_address=params1['server_address'],
        credentials=params1['credentials'],
        p2p=params1['p2p'],
        timeout=5,
    )
    agent2 = Agent(
        server_address=params2['server_address'],
        credentials=params2['credentials'],
        p2p=params2['p2p'],
        timeout=5,
    )
    await agent1.open()
    await agent2.open()
    try:
        same_resources = [f'resource/{uuid.uuid4().hex}']

        ok1, _ = await agent1.acquire(resources=same_resources,
                                      lock_timeout=10.0)
        ok2, _ = await agent1.acquire(resources=same_resources,
                                      lock_timeout=10.0)

        assert ok1 is True
        assert ok2 is True
    finally:
        await agent1.close()
        await agent2.close()
Пример #2
0
async def test_lock_multiple_time(test_suite: ServerTestSuite):
    params = test_suite.get_agent_params('agent1')
    session1 = Agent(
        server_address=params['server_address'],
        credentials=params['credentials'],
        p2p=params['p2p'],
        timeout=5,
    )
    session2 = Agent(
        server_address=params['server_address'],
        credentials=params['credentials'],
        p2p=params['p2p'],
        timeout=5,
    )
    await session1.open()
    await session2.open()
    try:
        resources1 = [f'resource-{uuid.uuid4().hex}']
        timeout = 5.0
        ok, _ = await session1.acquire(resources=resources1,
                                       lock_timeout=timeout)
        assert ok is True

        resources2 = [f'resource-{uuid.uuid4().hex}']
        ok, _ = await session1.acquire(resources=resources2,
                                       lock_timeout=timeout)
        assert ok is True
        # session1 must unlock previously locked resources on new acquire call
        ok, _ = await session2.acquire(resources=resources1,
                                       lock_timeout=timeout)
        assert ok is True
    finally:
        await session1.close()
        await session2.close()
Пример #3
0
async def test_schema_loading(agent1: Agent, agent2: Agent):
    await agent1.open()
    await agent2.open()
    try:
        seed1 = '000000000000000000000000Steward1'
        did1, verkey1 = await agent1.wallet.did.create_and_store_my_did(
            seed=seed1)
        schema_name = 'schema_' + uuid.uuid4().hex
        schema_id, anoncred_schema = await agent1.wallet.anoncreds.issuer_create_schema(
            did1, schema_name, '1.0', ['attr1', 'attr2', 'attr3'])
        ledger1 = agent1.ledger('default')

        ok, schema = await ledger1.register_schema(schema=anoncred_schema,
                                                   submitter_did=did1)
        assert ok is True
        assert schema.seq_no > 0

        seed2 = '000000000000000000000000Trustee0'
        did2, verkey2 = await agent2.wallet.did.create_and_store_my_did(
            seed=seed2)
        ledger2 = agent2.ledger('default')

        for n in range(5):
            loaded_schema = await ledger2.load_schema(id_=schema.id,
                                                      submitter_did=did2)
            assert loaded_schema is not None
            assert loaded_schema == schema
    finally:
        await agent1.close()
        await agent2.close()
Пример #4
0
async def test_agents_communications(test_suite: ServerTestSuite):
    agent1_params = test_suite.get_agent_params('agent1')
    agent2_params = test_suite.get_agent_params('agent2')
    entity1 = list(agent1_params['entities'].items())[0][1]
    entity2 = list(agent2_params['entities'].items())[0][1]
    agent1 = Agent(
        server_address=agent1_params['server_address'],
        credentials=agent1_params['credentials'],
        p2p=agent1_params['p2p'],
        timeout=5,
    )
    agent2 = Agent(
        server_address=agent2_params['server_address'],
        credentials=agent2_params['credentials'],
        p2p=agent2_params['p2p'],
        timeout=5,
    )
    await agent1.open()
    await agent2.open()
    try:
        # Get endpoints
        agent2_endpoint = [
            e for e in agent2.endpoints if e.routing_keys == []
        ][0].address
        agent2_listener = await agent2.subscribe()
        # Exchange Pairwise
        await agent1.wallet.did.store_their_did(entity2['did'],
                                                entity2['verkey'])
        if not await agent1.wallet.pairwise.is_pairwise_exists(entity2['did']):
            print('#1')
            await agent1.wallet.pairwise.create_pairwise(
                their_did=entity2['did'], my_did=entity1['did'])
        await agent2.wallet.did.store_their_did(entity1['did'],
                                                entity1['verkey'])
        if not await agent2.wallet.pairwise.is_pairwise_exists(entity1['did']):
            print('#2')
            await agent2.wallet.pairwise.create_pairwise(
                their_did=entity1['did'], my_did=entity2['did'])
        # Prepare message
        trust_ping = Message({
            '@id': 'trust-ping-message-' + uuid.uuid4().hex,
            '@type': 'did:sov:BzCbsNYhMrjHiqZDTUASHg;spec/trust_ping/1.0/ping',
            "comment": "Hi. Are you listening?",
            "response_requested": True
        })
        await agent1.send_message(message=trust_ping,
                                  their_vk=entity2['verkey'],
                                  endpoint=agent2_endpoint,
                                  my_vk=entity1['verkey'],
                                  routing_keys=[])
        event = await agent2_listener.get_one(timeout=5)
        msg = event['message']
        assert msg[
            '@type'] == 'did:sov:BzCbsNYhMrjHiqZDTUASHg;spec/trust_ping/1.0/ping'
        assert msg['@id'] == trust_ping.id
    finally:
        await agent1.close()
        await agent2.close()
async def test__threadbased_protocol_on_hub(test_suite: ServerTestSuite):
    agent1_params = test_suite.get_agent_params('agent1')
    agent2_params = test_suite.get_agent_params('agent2')
    agent1 = Agent(
        server_address=agent1_params['server_address'],
        credentials=agent1_params['credentials'],
        p2p=agent1_params['p2p'],
        timeout=5,
    )
    agent2 = Agent(
        server_address=agent2_params['server_address'],
        credentials=agent2_params['credentials'],
        p2p=agent2_params['p2p'],
        timeout=5,
    )
    await agent1.open()
    await agent2.open()
    try:
        # Get endpoints
        agent1_endpoint = [
            e for e in agent1.endpoints if e.routing_keys == []
        ][0].address
        agent2_endpoint = [
            e for e in agent2.endpoints if e.routing_keys == []
        ][0].address
        # Init pairwise list #1
        did1, verkey1 = await agent1.wallet.did.create_and_store_my_did()
        did2, verkey2 = await agent2.wallet.did.create_and_store_my_did()
        await agent1.wallet.did.store_their_did(did2, verkey2)
        await agent1.wallet.pairwise.create_pairwise(their_did=did2,
                                                     my_did=did1)
        await agent2.wallet.did.store_their_did(did1, verkey1)
        await agent2.wallet.pairwise.create_pairwise(their_did=did1,
                                                     my_did=did2)
        # Init pairwise list #2
        pairwise1 = Pairwise(me=Pairwise.Me(did=did1, verkey=verkey1),
                             their=Pairwise.Their(did=did2,
                                                  label='Label-2',
                                                  endpoint=agent2_endpoint,
                                                  verkey=verkey2))
        pairwise2 = Pairwise(me=Pairwise.Me(did=did2, verkey=verkey2),
                             their=Pairwise.Their(did=did1,
                                                  label='Label-1',
                                                  endpoint=agent1_endpoint,
                                                  verkey=verkey1))
    finally:
        await agent1.close()
        await agent2.close()

    thread_id = uuid.uuid4().hex
    co1 = sirius_sdk.CoProtocolThreadedP2P(thread_id, pairwise1)
    co2 = sirius_sdk.CoProtocolThreadedP2P(thread_id, pairwise2)
    MSG_LOG.clear()
    await run_coroutines(routine1_on_hub(co1, **agent1_params),
                         routine2_on_hub(co2, **agent2_params))
    check_msg_log()
Пример #6
0
    def handle(self, *args, **options):
        meta_url = options['meta_url']
        print('======================')
        print('Meta URL: ' + meta_url)
        print('======================')
        resp = requests.get(meta_url)
        assert resp.status_code == 200
        meta = resp.json()

        components = list(urlsplit(meta_url))
        components[2] = ''
        url = urlunsplit(components)

        for outer_name in meta.keys():
            for inner_name in meta.keys():
                if inner_name == outer_name:
                    continue
                print('### establish pairwise %s:%s' %
                      (outer_name, inner_name))
                agent1 = Agent(
                    server_address=url,
                    credentials=meta[outer_name]['credentials'].encode(
                        'ascii'),
                    p2p=P2PConnection(my_keys=(
                        meta[outer_name]['p2p']['smart_contract']['verkey'],
                        meta[outer_name]['p2p']['smart_contract']
                        ['secret_key'],
                    ),
                                      their_verkey=meta[outer_name]['p2p']
                                      ['agent']['verkey']))
                key1 = list(meta[outer_name]['entities'].keys())[0]
                entity1 = meta[outer_name]['entities'][key1]
                agent2 = Agent(
                    server_address=url,
                    credentials=meta[inner_name]['credentials'].encode(
                        'ascii'),
                    p2p=P2PConnection(my_keys=(
                        meta[inner_name]['p2p']['smart_contract']['verkey'],
                        meta[inner_name]['p2p']['smart_contract']
                        ['secret_key'],
                    ),
                                      their_verkey=meta[inner_name]['p2p']
                                      ['agent']['verkey']))
                key2 = list(meta[inner_name]['entities'].keys())[0]
                entity2 = meta[inner_name]['entities'][key2]
                run_async(self.establish_connection(agent1, entity1, agent2,
                                                    entity2),
                          timeout=190)
                print('### establish success !')
Пример #7
0
async def test_nym_ops(agent1: Agent, agent2: Agent):
    steward = agent1
    await steward.open()
    await agent2.open()
    try:
        seed = '000000000000000000000000Steward1'
        did_steward, verkey_steward = await steward.wallet.did.create_and_store_my_did(
            seed=seed)
        # check-1: read ops sane
        dkms = steward.ledger('default')
        ok, resp = await dkms.read_nym(did_steward, did_steward)
        assert ok is True
        print('#')
        did_test, verkey_test = await agent2.wallet.did.create_and_store_my_did(
        )
        # check-2: read nym operation for unknown DID
        dkms = agent2.ledger('default')
        ok, resp = await dkms.read_nym(did_test, did_test)
        assert ok is False
        # Check-3: read nym for known DID
        ok, resp = await dkms.read_nym(did_test, did_steward)
        assert ok is True
        # Check-4: write Nym
        dkms = steward.ledger('default')
        ok, resp = await dkms.write_nym(did_steward,
                                        did_test,
                                        verkey_test,
                                        alias='Test Alias')
        assert ok is True
    finally:
        await steward.close()
        await agent2.close()
Пример #8
0
async def test_schema_registration(agent1: Agent):
    await agent1.open()
    try:
        seed = '000000000000000000000000Steward1'
        did, verkey = await agent1.wallet.did.create_and_store_my_did(seed=seed
                                                                      )
        schema_name = 'schema_' + uuid.uuid4().hex
        schema_id, anoncred_schema = await agent1.wallet.anoncreds.issuer_create_schema(
            did, schema_name, '1.0', ['attr1', 'attr2', 'attr3'])
        ledger = agent1.ledger('default')

        ok, schema = await ledger.register_schema(schema=anoncred_schema,
                                                  submitter_did=did)
        assert ok is True
        assert schema.seq_no > 0

        ok, _ = await ledger.register_schema(schema=anoncred_schema,
                                             submitter_did=did)
        assert ok is False

        restored_schema = await ledger.ensure_schema_exists(
            schema=anoncred_schema, submitter_did=did)
        assert restored_schema is not None
        assert restored_schema == schema

    finally:
        await agent1.close()
Пример #9
0
 async def participants_trust_ping(ping_id: str):
     if settings.AGENT['entity']:
         # extract neighbours
         neighbours = {did: meta for did, meta in settings.PARTICIPANTS_META.items() if did != settings.AGENT['entity']}
         agent = Agent(
             server_address=settings.AGENT['server_address'],
             credentials=settings.AGENT['credentials'].encode('ascii'),
             p2p=P2PConnection(
                 my_keys=(
                     settings.AGENT['my_verkey'],
                     settings.AGENT['my_secret_key']
                 ),
                 their_verkey=settings.AGENT['agent_verkey']
             )
         )
         print('agent.open()')
         await agent.open()
         print('start ping to all')
         try:
             for their_did, meta in neighbours.items():
                 to = await agent.pairwise_list.load_for_did(their_did)
                 print('ping to: ' + their_did)
                 await agent.send_to(
                     message=Ping(comment=ping_id),
                     to=to
                 )
         finally:
             await agent.close()
async def test__their_endpoint_protocol(test_suite: ServerTestSuite):
    agent1_params = test_suite.get_agent_params('agent1')
    agent2_params = test_suite.get_agent_params('agent2')
    entity1 = list(agent1_params['entities'].items())[0][1]
    entity2 = list(agent2_params['entities'].items())[0][1]
    agent1 = Agent(
        server_address=agent1_params['server_address'],
        credentials=agent1_params['credentials'],
        p2p=agent1_params['p2p'],
        timeout=5,
    )
    agent2 = Agent(
        server_address=agent2_params['server_address'],
        credentials=agent2_params['credentials'],
        p2p=agent2_params['p2p'],
        timeout=5,
    )
    await agent1.open()
    await agent2.open()
    try:
        # Get endpoints
        agent1_endpoint = [
            e for e in agent1.endpoints if e.routing_keys == []
        ][0].address
        agent2_endpoint = [
            e for e in agent2.endpoints if e.routing_keys == []
        ][0].address
        # Make protocol instances
        their1 = TheirEndpoint(agent2_endpoint, entity2['verkey'])
        agent1_protocol = await agent1.spawn(entity1['verkey'], their1)
        assert isinstance(agent1_protocol, TheirEndpointCoProtocolTransport)
        their2 = TheirEndpoint(agent1_endpoint, entity1['verkey'])
        agent2_protocol = await agent2.spawn(entity2['verkey'], their2)
        assert isinstance(agent2_protocol, TheirEndpointCoProtocolTransport)
        await agent1_protocol.start(['test_protocol'])
        await agent2_protocol.start(['test_protocol'])
        try:
            MSG_LOG.clear()
            await run_coroutines(routine1(agent1_protocol),
                                 routine2(agent2_protocol))
            check_msg_log()
        finally:
            await agent1_protocol.stop()
            await agent2_protocol.stop()
    finally:
        await agent1.close()
        await agent2.close()
Пример #11
0
def get_agent(name: str) -> Agent:
    params = get_suite_singleton().get_agent_params(name)
    agent = Agent(server_address=params['server_address'],
                  credentials=params['credentials'],
                  p2p=params['p2p'],
                  timeout=30,
                  name=name)
    return agent
Пример #12
0
 def alloc_agent_connection() -> Agent:
     agent = Agent(
         server_address=settings.AGENT['server_address'],
         credentials=settings.AGENT['credentials'].encode('ascii'),
         p2p=P2PConnection(my_keys=(settings.AGENT['my_verkey'],
                                    settings.AGENT['my_secret_key']),
                           their_verkey=settings.AGENT['agent_verkey']))
     return agent
Пример #13
0
async def test_same_account(test_suite: ServerTestSuite):
    params = test_suite.get_agent_params('agent1')
    session1 = Agent(
        server_address=params['server_address'],
        credentials=params['credentials'],
        p2p=params['p2p'],
        timeout=5,
    )
    session2 = Agent(
        server_address=params['server_address'],
        credentials=params['credentials'],
        p2p=params['p2p'],
        timeout=5,
    )
    await session1.open()
    await session2.open()
    try:
        # check locking OK
        resources = [f'resource-{uuid.uuid4().hex}' for i in range(100)]
        ok, busy = await session1.acquire(resources=resources, lock_timeout=5)
        try:
            assert ok is True
            ok, busy = await session2.acquire(resources=resources,
                                              lock_timeout=1)
            assert ok is False
            assert set(busy) == set(resources)
        finally:
            await session1.release()
        # check session ok may lock after explicitly release
        ok, busy = await session2.acquire(resources=resources, lock_timeout=1)
        assert ok is True
        # Check after timeout
        resources = [f'resource-{uuid.uuid4().hex}' for i in range(100)]
        timeout = 5.0
        ok, _ = await session1.acquire(resources=resources,
                                       lock_timeout=timeout)
        assert ok is True
        ok, _ = await session2.acquire(resources=resources, lock_timeout=1.0)
        assert ok is False
        await asyncio.sleep(timeout + 1.0)
        ok, _ = await session2.acquire(resources=resources, lock_timeout=1.0)
        assert ok is True
    finally:
        await session1.close()
        await session2.close()
Пример #14
0
async def test_register_cred_def(agent1: Agent):
    await agent1.open()
    try:
        seed = '000000000000000000000000Steward1'
        did, verkey = await agent1.wallet.did.create_and_store_my_did(seed=seed
                                                                      )
        schema_name = 'schema_' + uuid.uuid4().hex
        schema_id, anoncred_schema = await agent1.wallet.anoncreds.issuer_create_schema(
            did, schema_name, '1.0', ['attr1', 'attr2', 'attr3'])
        ledger = agent1.ledger('default')

        ok, schema = await ledger.register_schema(schema=anoncred_schema,
                                                  submitter_did=did)
        assert ok is True

        cred_def = CredentialDefinition(tag='Test Tag', schema=schema)
        assert cred_def.body is None
        ok, ledger_cred_def = await ledger.register_cred_def(cred_def=cred_def,
                                                             submitter_did=did)
        assert ok is True
        assert ledger_cred_def.body is not None
        assert ledger_cred_def.seq_no > 0
        assert ledger_cred_def.submitter_did == did
        my_value = 'my-value-' + uuid.uuid4().hex

        ok, ledger_cred_def2 = await ledger.register_cred_def(
            cred_def=cred_def, submitter_did=did, tags={'my_tag': my_value})
        assert ok is True
        assert ledger_cred_def.body == ledger_cred_def2.body
        assert ledger_cred_def2.seq_no > ledger_cred_def.seq_no

        ser = ledger_cred_def.serialize()
        loaded = CredentialDefinition.deserialize(ser)
        assert loaded.body == ledger_cred_def.body
        assert loaded.seq_no == ledger_cred_def.seq_no
        assert loaded.schema.body == ledger_cred_def.schema.body
        assert loaded.config.serialize() == ledger_cred_def.config.serialize()

        results = await ledger.fetch_cred_defs(schema_id=schema_id)
        assert len(results) == 2
        results = await ledger.fetch_cred_defs(my_tag=my_value)
        assert len(results) == 1

        parts = ledger_cred_def.id.split(':')
        print(str(parts))

        opts = CacheOptions()
        for n in range(3):
            cached_body = await agent1.wallet.cache.get_cred_def(
                'default', did, ledger_cred_def.id, opts)
            assert cached_body == ledger_cred_def.body
            cred_def = await ledger.load_cred_def(ledger_cred_def.id, did)
            assert cred_def.body == cached_body
    finally:
        await agent1.close()
async def test__their_endpoint_protocol_on_hub(test_suite: ServerTestSuite):
    agent1_params = test_suite.get_agent_params('agent1')
    agent2_params = test_suite.get_agent_params('agent2')
    entity1 = list(agent1_params['entities'].items())[0][1]
    entity2 = list(agent2_params['entities'].items())[0][1]

    agent1 = Agent(
        server_address=agent1_params['server_address'],
        credentials=agent1_params['credentials'],
        p2p=agent1_params['p2p'],
        timeout=5,
    )
    agent2 = Agent(
        server_address=agent2_params['server_address'],
        credentials=agent2_params['credentials'],
        p2p=agent2_params['p2p'],
        timeout=5,
    )
    await agent1.open()
    await agent2.open()
    try:
        # Get endpoints
        agent1_endpoint = [
            e for e in agent1.endpoints if e.routing_keys == []
        ][0].address
        agent2_endpoint = [
            e for e in agent2.endpoints if e.routing_keys == []
        ][0].address
    finally:
        await agent1.close()
        await agent2.close()
    # FIRE!!!
    their1 = TheirEndpoint(agent2_endpoint, entity2['verkey'])
    their2 = TheirEndpoint(agent1_endpoint, entity1['verkey'])
    co1 = sirius_sdk.CoProtocolP2PAnon(entity1['verkey'], their1,
                                       ['test_protocol'])
    co2 = sirius_sdk.CoProtocolP2PAnon(entity2['verkey'], their2,
                                       ['test_protocol'])
    MSG_LOG.clear()
    await run_coroutines(routine1_on_hub(co1, **agent1_params),
                         routine2_on_hub(co2, **agent2_params))
    check_msg_log()
Пример #16
0
async def test__all_agents_ping(test_suite: ServerTestSuite):
    for name in ['agent1', 'agent2', 'agent3', 'agent4']:
        params = test_suite.get_agent_params(name)
        agent = Agent(
            server_address=params['server_address'],
            credentials=params['credentials'],
            p2p=params['p2p'],
            timeout=5,
        )
        await agent.open()
        try:
            success = await agent.ping()
            assert success is True, 'agent [%s] is not ping-able' % name
        finally:
            await agent.close()
Пример #17
0
async def test_agents_wallet(test_suite: ServerTestSuite):
    params = test_suite.get_agent_params('agent1')
    agent = Agent(
        server_address=params['server_address'],
        credentials=params['credentials'],
        p2p=params['p2p'],
        timeout=5,
    )
    await agent.open()
    try:
        # Check wallet calls is ok
        did, verkey = await agent.wallet.did.create_and_store_my_did()
        assert did
        assert verkey
        # check reopen is OK
        await agent.reopen()
    finally:
        await agent.close()
Пример #18
0
async def test_schema_fetching(agent1: Agent):
    await agent1.open()
    try:
        seed = '000000000000000000000000Steward1'
        did, verkey = await agent1.wallet.did.create_and_store_my_did(seed=seed
                                                                      )
        schema_name = 'schema_' + uuid.uuid4().hex
        schema_id, anoncred_schema = await agent1.wallet.anoncreds.issuer_create_schema(
            did, schema_name, '1.0', ['attr1', 'attr2', 'attr3'])
        ledger = agent1.ledger('default')

        ok, schema = await ledger.register_schema(schema=anoncred_schema,
                                                  submitter_did=did)
        assert ok is True

        fetches = await ledger.fetch_schemas(name=schema_name)
        assert len(fetches) == 1
        assert fetches[0].issuer_did == did

    finally:
        await agent1.close()
async def test__threadbased_protocol(test_suite: ServerTestSuite):
    agent1_params = test_suite.get_agent_params('agent1')
    agent2_params = test_suite.get_agent_params('agent2')
    agent1 = Agent(
        server_address=agent1_params['server_address'],
        credentials=agent1_params['credentials'],
        p2p=agent1_params['p2p'],
        timeout=5,
    )
    agent2 = Agent(
        server_address=agent2_params['server_address'],
        credentials=agent2_params['credentials'],
        p2p=agent2_params['p2p'],
        timeout=5,
    )
    await agent1.open()
    await agent2.open()
    try:
        # Get endpoints
        agent1_endpoint = [
            e for e in agent1.endpoints if e.routing_keys == []
        ][0].address
        agent2_endpoint = [
            e for e in agent2.endpoints if e.routing_keys == []
        ][0].address
        # Init pairwise list #1
        did1, verkey1 = await agent1.wallet.did.create_and_store_my_did()
        did2, verkey2 = await agent2.wallet.did.create_and_store_my_did()
        await agent1.wallet.did.store_their_did(did2, verkey2)
        await agent1.wallet.pairwise.create_pairwise(their_did=did2,
                                                     my_did=did1)
        await agent2.wallet.did.store_their_did(did1, verkey1)
        await agent2.wallet.pairwise.create_pairwise(their_did=did1,
                                                     my_did=did2)
        # Init pairwise list #2
        pairwise1 = Pairwise(me=Pairwise.Me(did=did1, verkey=verkey1),
                             their=Pairwise.Their(did=did2,
                                                  label='Label-2',
                                                  endpoint=agent2_endpoint,
                                                  verkey=verkey2))
        pairwise2 = Pairwise(me=Pairwise.Me(did=did2, verkey=verkey2),
                             their=Pairwise.Their(did=did1,
                                                  label='Label-1',
                                                  endpoint=agent1_endpoint,
                                                  verkey=verkey1))

        thread_id = uuid.uuid4().hex
        agent1_protocol = await agent1.spawn(thread_id, pairwise1)
        agent2_protocol = await agent2.spawn(thread_id, pairwise2)
        assert isinstance(agent1_protocol, ThreadBasedCoProtocolTransport)
        assert isinstance(agent2_protocol, ThreadBasedCoProtocolTransport)

        await agent1_protocol.start()
        await agent2_protocol.start()
        try:
            MSG_LOG.clear()
            await run_coroutines(routine1(agent1_protocol),
                                 routine2(agent2_protocol))
            check_msg_log()
        finally:
            await agent1_protocol.stop()
            await agent2_protocol.stop()
    finally:
        await agent1.close()
        await agent2.close()
async def test__protocols_intersections(test_suite: ServerTestSuite):
    agent1_params = test_suite.get_agent_params('agent1')
    agent2_params = test_suite.get_agent_params('agent2')
    agent1 = Agent(
        server_address=agent1_params['server_address'],
        credentials=agent1_params['credentials'],
        p2p=agent1_params['p2p'],
        timeout=15,
    )
    agent2 = Agent(
        server_address=agent2_params['server_address'],
        credentials=agent2_params['credentials'],
        p2p=agent2_params['p2p'],
        timeout=15,
    )
    await agent1.open()
    await agent2.open()
    try:
        # Get endpoints
        agent1_endpoint = [
            e for e in agent1.endpoints if e.routing_keys == []
        ][0].address
        agent2_endpoint = [
            e for e in agent2.endpoints if e.routing_keys == []
        ][0].address
        # Init pairwise list #1
        did1, verkey1 = await agent1.wallet.did.create_and_store_my_did()
        did2, verkey2 = await agent2.wallet.did.create_and_store_my_did()
        await agent1.wallet.did.store_their_did(did2, verkey2)
        await agent1.wallet.pairwise.create_pairwise(their_did=did2,
                                                     my_did=did1)
        await agent2.wallet.did.store_their_did(did1, verkey1)
        await agent2.wallet.pairwise.create_pairwise(their_did=did1,
                                                     my_did=did2)
        # Init pairwise list #2
        pairwise1 = Pairwise(me=Pairwise.Me(did=did1, verkey=verkey1),
                             their=Pairwise.Their(did=did2,
                                                  label='Label-2',
                                                  endpoint=agent2_endpoint,
                                                  verkey=verkey2))
        pairwise2 = Pairwise(me=Pairwise.Me(did=did2, verkey=verkey2),
                             their=Pairwise.Their(did=did1,
                                                  label='Label-1',
                                                  endpoint=agent1_endpoint,
                                                  verkey=verkey1))

        thread_id = uuid.uuid4().hex
        agent1_protocol_threaded = await agent1.spawn(thread_id, pairwise1)
        agent2_protocol_threaded = await agent2.spawn(thread_id, pairwise2)
        assert isinstance(agent1_protocol_threaded,
                          ThreadBasedCoProtocolTransport)
        assert isinstance(agent2_protocol_threaded,
                          ThreadBasedCoProtocolTransport)
        agent1_protocol_pairwise = await agent1.spawn(pairwise1)
        agent2_protocol_pairwise = await agent2.spawn(pairwise2)
        assert isinstance(agent1_protocol_pairwise,
                          PairwiseCoProtocolTransport)
        assert isinstance(agent2_protocol_pairwise,
                          PairwiseCoProtocolTransport)

        await agent1_protocol_threaded.start(['test_protocol'])
        await agent2_protocol_threaded.start(['test_protocol'])
        await agent1_protocol_pairwise.start(['test_protocol'])
        await agent2_protocol_pairwise.start(['test_protocol'])
        try:
            MSG_LOG.clear()
            await run_coroutines(
                routine1(agent1_protocol_threaded),
                routine2(agent2_protocol_threaded),
                routine1(agent1_protocol_pairwise),
                routine2(agent2_protocol_pairwise),
            )
            # collect messages
            threaded_sequence = [msg for msg in MSG_LOG if '~thread' in msg]
            non_threaded_sequence = [
                msg for msg in MSG_LOG if '~thread' not in msg
            ]
            # threaded messages
            MSG_LOG.clear()
            MSG_LOG.extend(threaded_sequence)
            check_msg_log()
            for msg in threaded_sequence:
                assert msg['~thread']['thid'] == thread_id
            # non-threaded messages
            MSG_LOG.clear()
            MSG_LOG.extend(non_threaded_sequence)
            check_msg_log()
        finally:
            await agent1_protocol_threaded.stop()
            await agent2_protocol_threaded.stop()
            await agent1_protocol_pairwise.stop()
            await agent2_protocol_pairwise.stop()
    finally:
        await agent1.close()
        await agent2.close()