Skip to content

Commit

Permalink
client: improvements to error handling and test_client script
Browse files Browse the repository at this point in the history
  • Loading branch information
dtebbs committed Aug 6, 2020
1 parent 390fb2a commit eb4834b
Show file tree
Hide file tree
Showing 2 changed files with 29 additions and 3 deletions.
17 changes: 16 additions & 1 deletion client/zecale/commands/zecale
Original file line number Diff line number Diff line change
Expand Up @@ -9,8 +9,10 @@ from zecale.commands.command_context import CommandContext
from zecale.commands.zecale_register import register
from zecale.commands.zecale_submit import submit
from zecale.commands.zecale_get_batch import get_batch
from grpc import RpcError
from click import command, group, option, pass_context, Context, ClickException
from click_default_group import DefaultGroup
import sys


@command()
Expand All @@ -26,7 +28,20 @@ def help(ctx: Context) -> None:
raise ClickException("no command specified")


@group(cls=DefaultGroup, default_if_no_args=True, default="help")
class HandleRpcExceptions(DefaultGroup):
"""
A click group which handles uncaught RpcExceptions with a sensible message
(similar to ClickException).
"""
def __call__(self, *args, **kwargs):
try:
return DefaultGroup.__call__(self, *args, **kwargs)
except RpcError as ex:
print(f"error: {ex.details()}")
sys.exit(1)


@group(cls=HandleRpcExceptions, default_if_no_args=True, default="help")
@option(
"--aggregator-server", "-a",
default=AGGREGATOR_SERVER_ENDPOINT_DEFAULT,
Expand Down
15 changes: 13 additions & 2 deletions scripts/test_client
Original file line number Diff line number Diff line change
Expand Up @@ -26,15 +26,26 @@ zecale register --key vk.json --name ${APP_NAME} || echo Already registered
( zecale register --key vk.json --name ${APP_NAME} ) && \
(echo Expected duplicate registration to fail; exit 1)

# Send 4 transactions
# Send 4 transactions (enough for 2 batches)

zecale submit --name ${APP_NAME} --tx extproof1.json
zecale submit --name ${APP_NAME} --tx extproof2.json
zecale submit --name ${APP_NAME} --tx extproof3.json
zecale submit --name ${APP_NAME} --tx extproof4.json

# Request and aggregate proof
# Request aggregate proofs. Assuming the server was empty at the beginning of
# the test, the first two request should succeed, and the third should fail.

zecale get-batch --name ${APP_NAME} --batch-file batch1.json
zecale get-batch --name ${APP_NAME} --batch-file batch2.json
zecale get-batch --name ${APP_NAME} --batch-file batch3.json && \
(echo Expected failure when no batch available; exit 1)

popd # _test_client_data

set +e
set +x

echo "=================================================="
echo "== Client Test Passed =="
echo "=================================================="

0 comments on commit eb4834b

Please sign in to comment.