Skip to content

Commit

Permalink
Integration tests - Add retry to did registration
Browse files Browse the repository at this point in the history
Signed-off-by: jamshale <[email protected]>
  • Loading branch information
jamshale committed Mar 6, 2024
1 parent fa2a8ea commit 8bf8da2
Show file tree
Hide file tree
Showing 4 changed files with 41 additions and 31 deletions.
3 changes: 2 additions & 1 deletion demo/bdd_support/agent_backchannel_client.py
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,6 @@

from runners.agent_container import AgentContainer, create_agent_with_args_list


######################################################################
# coroutine utilities
######################################################################
Expand Down Expand Up @@ -246,13 +245,15 @@ def agent_container_POST(
data: dict = None,
text: bool = False,
params: dict = None,
raise_error: bool = True,
) -> dict:
return run_coroutine(
the_container.admin_POST,
path,
data=data,
text=text,
params=params,
raise_error=raise_error,
)


Expand Down
18 changes: 12 additions & 6 deletions demo/features/steps/0586-sign-transaction.py
Original file line number Diff line number Diff line change
Expand Up @@ -32,19 +32,25 @@ def step_impl(context, agent_name, did_role):
created_did = agent_container_POST(agent["agent"], "/wallet/did/create")

# publish to the ledger with did_role
registered_did = agent_container_register_did(
agent_container_register_did(
agent["agent"],
created_did["result"]["did"],
created_did["result"]["verkey"],
"ENDORSER" if did_role == "ENDORSER" else "",
)

# make the new did the wallet's public did
published_did = agent_container_POST(
agent["agent"],
"/wallet/did/public",
params={"did": created_did["result"]["did"]},
)
retries = 3
for retry in range(retries):
published_did = agent_container_POST(
agent["agent"],
"/wallet/did/public",
params={"did": created_did["result"]["did"]},
raise_error=retries - 1 == retry,
)
if "result" in published_did or "txn" in published_did:
break

if "result" in published_did:
# published right away!
pass
Expand Down
28 changes: 15 additions & 13 deletions demo/runners/agent_container.py
Original file line number Diff line number Diff line change
Expand Up @@ -7,26 +7,25 @@
import sys
import time
from typing import List
import yaml

from qrcode import QRCode

import yaml
from aiohttp import ClientError
from qrcode import QRCode

sys.path.append(os.path.dirname(os.path.dirname(os.path.abspath(__file__))))

from runners.support.agent import ( # noqa:E402
DemoAgent,
default_genesis_txns,
start_mediator_agent,
connect_wallet_to_mediator,
start_endorser_agent,
connect_wallet_to_endorser,
WALLET_TYPE_INDY,
CRED_FORMAT_INDY,
CRED_FORMAT_JSON_LD,
DID_METHOD_KEY,
KEY_TYPE_BLS,
WALLET_TYPE_INDY,
DemoAgent,
connect_wallet_to_endorser,
connect_wallet_to_mediator,
default_genesis_txns,
start_endorser_agent,
start_mediator_agent,
)
from runners.support.utils import ( # noqa:E402
check_requires,
Expand All @@ -36,7 +35,6 @@
log_timer,
)


CRED_PREVIEW_TYPE = "https://didcomm.org/issue-credential/2.0/credential-preview"
SELF_ATTESTED = os.getenv("SELF_ATTESTED")
TAILS_FILE_COUNT = int(os.getenv("TAILS_FILE_COUNT", 100))
Expand Down Expand Up @@ -1174,15 +1172,19 @@ async def admin_GET(self, path, text=False, params=None) -> dict:
"""
return await self.agent.admin_GET(path, text=text, params=params)

async def admin_POST(self, path, data=None, text=False, params=None) -> dict:
async def admin_POST(
self, path, data=None, text=False, params=None, raise_error=True
) -> dict:
"""Execute an admin POST request in the context of the current wallet.
path = /path/of/request
data = payload to post with the request
text = True if the expected response is text, False if json data
params = any additional parameters to pass with the request
"""
return await self.agent.admin_POST(path, data=data, text=text, params=params)
return await self.agent.admin_POST(
path, data=data, text=text, params=params, raise_error=raise_error
)

async def admin_PATCH(self, path, data=None, text=False, params=None) -> dict:
"""Execute an admin PATCH request in the context of the current wallet.
Expand Down
23 changes: 12 additions & 11 deletions demo/runners/support/agent.py
Original file line number Diff line number Diff line change
@@ -1,6 +1,4 @@
import asyncio
from concurrent.futures import ThreadPoolExecutor
import asyncpg
import base64
import functools
import json
Expand All @@ -9,17 +7,18 @@
import random
import subprocess
import sys
import yaml

from concurrent.futures import ThreadPoolExecutor
from timeit import default_timer

import asyncpg
import yaml
from aiohttp import (
web,
ClientSession,
ClientError,
ClientRequest,
ClientResponse,
ClientError,
ClientSession,
ClientTimeout,
web,
)

from .utils import flatten, log_json, log_msg, log_timer, output_reader
Expand Down Expand Up @@ -1045,17 +1044,17 @@ async def handle_problem_report(self, message):
)

async def handle_endorse_transaction(self, message):
self.log(f"Received endorse transaction ...\n", source="stderr")
self.log("Received endorse transaction ...\n", source="stderr")

async def handle_revocation_registry(self, message):
reg_id = message.get("revoc_reg_id", "(undetermined)")
self.log(f"Revocation registry: {reg_id} state: {message['state']}")

async def handle_mediation(self, message):
self.log(f"Received mediation message ...\n")
self.log("Received mediation message ...\n")

async def handle_keylist(self, message):
self.log(f"Received handle_keylist message ...\n")
self.log("Received handle_keylist message ...\n")
self.log(json.dumps(message))

async def taa_accept(self):
Expand Down Expand Up @@ -1167,7 +1166,7 @@ async def agency_admin_POST(
raise

async def admin_POST(
self, path, data=None, text=False, params=None, headers=None
self, path, data=None, text=False, params=None, headers=None, raise_error=True
) -> ClientResponse:
try:
EVENT_LOGGER.debug(
Expand All @@ -1192,6 +1191,8 @@ async def admin_POST(
return response
except ClientError as e:
self.log(f"Error during POST {path}: {str(e)}")
if not raise_error:
return None
raise

async def admin_PATCH(
Expand Down

0 comments on commit 8bf8da2

Please sign in to comment.