Skip to content

Commit 3c250c7

Browse files
authored
Merge pull request openwallet-foundation#1840 from andrewwhitehead/fix/int-test-prefix
Set prefix for integration test demo agents; some code cleanup
2 parents dc476c0 + 6ec8376 commit 3c250c7

2 files changed

Lines changed: 19 additions & 55 deletions

File tree

demo/bdd_support/agent_backchannel_client.py

Lines changed: 16 additions & 51 deletions
Original file line numberDiff line numberDiff line change
@@ -1,51 +1,16 @@
11
import asyncio
2-
from aiohttp import (
3-
web,
4-
ClientSession,
5-
ClientRequest,
6-
ClientResponse,
7-
ClientError,
8-
ClientTimeout,
9-
)
102
import json
11-
import os
12-
from time import sleep
133
import uuid
144

155
from runners.agent_container import AgentContainer, create_agent_with_args_list
16-
from runners.support.agent import DemoAgent
176

187

198
######################################################################
209
# coroutine utilities
2110
######################################################################
2211

2312

24-
def run_coroutine(coroutine):
25-
loop = asyncio.get_event_loop()
26-
if not loop:
27-
loop = asyncio.new_event_loop()
28-
asyncio.set_event_loop(loop)
29-
try:
30-
return loop.run_until_complete(coroutine())
31-
finally:
32-
pass
33-
# loop.close()
34-
35-
36-
def run_coroutine_with_args(coroutine, *args):
37-
loop = asyncio.get_event_loop()
38-
if not loop:
39-
loop = asyncio.new_event_loop()
40-
asyncio.set_event_loop(loop)
41-
try:
42-
return loop.run_until_complete(coroutine(*args))
43-
finally:
44-
pass
45-
# loop.close()
46-
47-
48-
def run_coroutine_with_kwargs(coroutine, *args, **kwargs):
13+
def run_coroutine(coroutine, *args, **kwargs):
4914
loop = asyncio.get_event_loop()
5015
if not loop:
5116
loop = asyncio.new_event_loop()
@@ -58,22 +23,22 @@ def run_coroutine_with_kwargs(coroutine, *args, **kwargs):
5823

5924

6025
def async_sleep(delay):
61-
run_coroutine_with_args(asyncio.sleep, delay)
26+
run_coroutine(asyncio.sleep, delay)
6227

6328

6429
######################################################################
6530
# high level aries agent interface
6631
######################################################################
6732
def create_agent_container_with_args(in_args: list):
68-
return run_coroutine_with_args(create_agent_with_args_list, in_args)
33+
return run_coroutine(create_agent_with_args_list, in_args)
6934

7035

7136
def aries_container_initialize(
7237
the_container: AgentContainer,
7338
schema_name: str = None,
7439
schema_attrs: list = None,
7540
):
76-
run_coroutine_with_kwargs(
41+
run_coroutine(
7742
the_container.initialize,
7843
schema_name=schema_name,
7944
schema_attrs=schema_attrs,
@@ -86,7 +51,7 @@ def agent_container_register_did(
8651
verkey: str,
8752
role: str,
8853
):
89-
run_coroutine_with_args(
54+
run_coroutine(
9055
the_container.register_did,
9156
did,
9257
verkey,
@@ -103,7 +68,7 @@ def aries_container_terminate(
10368
def aries_container_generate_invitation(
10469
the_container: AgentContainer,
10570
):
106-
return run_coroutine_with_kwargs(
71+
return run_coroutine(
10772
the_container.generate_invitation,
10873
)
10974

@@ -112,7 +77,7 @@ def aries_container_receive_invitation(
11277
the_container: AgentContainer,
11378
invite_details: dict,
11479
):
115-
return run_coroutine_with_kwargs(
80+
return run_coroutine(
11681
the_container.input_invitation,
11782
invite_details,
11883
)
@@ -130,7 +95,7 @@ def aries_container_create_schema_cred_def(
13095
schema_attrs: list,
13196
version: str = None,
13297
):
133-
return run_coroutine_with_kwargs(
98+
return run_coroutine(
13499
the_container.create_schema_and_cred_def,
135100
schema_name,
136101
schema_attrs,
@@ -143,7 +108,7 @@ def aries_container_issue_credential(
143108
cred_def_id: str,
144109
cred_attrs: list,
145110
):
146-
return run_coroutine_with_args(
111+
return run_coroutine(
147112
the_container.issue_credential,
148113
cred_def_id,
149114
cred_attrs,
@@ -155,7 +120,7 @@ def aries_container_receive_credential(
155120
cred_def_id: str,
156121
cred_attrs: list,
157122
):
158-
return run_coroutine_with_args(
123+
return run_coroutine(
159124
the_container.receive_credential,
160125
cred_def_id,
161126
cred_attrs,
@@ -166,7 +131,7 @@ def aries_container_request_proof(
166131
the_container: AgentContainer,
167132
proof_request: dict,
168133
):
169-
return run_coroutine_with_args(
134+
return run_coroutine(
170135
the_container.request_proof,
171136
proof_request,
172137
)
@@ -176,7 +141,7 @@ def aries_container_verify_proof(
176141
the_container: AgentContainer,
177142
proof_request: dict,
178143
):
179-
return run_coroutine_with_args(
144+
return run_coroutine(
180145
the_container.verify_proof,
181146
proof_request,
182147
)
@@ -228,7 +193,7 @@ def agent_container_GET(
228193
text: bool = False,
229194
params: dict = None,
230195
) -> dict:
231-
return run_coroutine_with_kwargs(
196+
return run_coroutine(
232197
the_container.admin_GET,
233198
path,
234199
text=text,
@@ -243,7 +208,7 @@ def agent_container_POST(
243208
text: bool = False,
244209
params: dict = None,
245210
) -> dict:
246-
return run_coroutine_with_kwargs(
211+
return run_coroutine(
247212
the_container.admin_POST,
248213
path,
249214
data=data,
@@ -259,7 +224,7 @@ def agent_container_PATCH(
259224
text: bool = False,
260225
params: dict = None,
261226
) -> dict:
262-
return run_coroutine_with_kwargs(
227+
return run_coroutine(
263228
the_container.admin_PATCH,
264229
path,
265230
data=data,
@@ -275,7 +240,7 @@ def agent_container_PUT(
275240
text: bool = False,
276241
params: dict = None,
277242
) -> dict:
278-
return run_coroutine_with_kwargs(
243+
return run_coroutine(
279244
the_container.admin_PUT,
280245
path,
281246
data=data,

demo/runners/agent_container.py

Lines changed: 3 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -20,14 +20,10 @@
2020
start_mediator_agent,
2121
connect_wallet_to_mediator,
2222
start_endorser_agent,
23-
connect_wallet_to_endorser,
2423
CRED_FORMAT_INDY,
2524
CRED_FORMAT_JSON_LD,
26-
DID_METHOD_SOV,
2725
DID_METHOD_KEY,
28-
KEY_TYPE_ED255,
2926
KEY_TYPE_BLS,
30-
SIG_TYPE_BLS,
3127
)
3228
from runners.support.utils import ( # noqa:E402
3329
check_requires,
@@ -615,6 +611,7 @@ def __init__(
615611
self,
616612
ident: str,
617613
start_port: int,
614+
prefix: str = None,
618615
no_auto: bool = False,
619616
revocation: bool = False,
620617
genesis_txns: str = None,
@@ -639,6 +636,7 @@ def __init__(
639636
self.genesis_txn_list = genesis_txn_list
640637
self.ident = ident
641638
self.start_port = start_port
639+
self.prefix = prefix or ident
642640
self.no_auto = no_auto
643641
self.revocation = revocation
644642
self.tails_server_base_url = tails_server_base_url
@@ -685,6 +683,7 @@ async def initialize(
685683
self.ident,
686684
self.start_port,
687685
self.start_port + 1,
686+
prefix=self.prefix,
688687
genesis_data=self.genesis_txns,
689688
genesis_txn_list=self.genesis_txn_list,
690689
no_auto=self.no_auto,

0 commit comments

Comments
 (0)