-
Notifications
You must be signed in to change notification settings - Fork 12
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #60 from CapCap/add_mw_drw_proxy
[mw][e2e] Add miniwallet<->drw proxy
- Loading branch information
Showing
8 changed files
with
520 additions
and
450 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Large diffs are not rendered by default.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,16 @@ | ||
# MiniWallet <=> Reference Wallet Proxy | ||
|
||
This will run a proxy which allows the DMW test suite to communicate with DRW. | ||
|
||
For example, when the DRW requests to set up a user, the proxy registers a user, updates their information with KYC, | ||
and deposits any initial test balances that the DMW required, before returning an identifier for that user which DMW | ||
will reuse in future calls. | ||
|
||
|
||
### Usage: | ||
(from inside the venv) | ||
``` | ||
DRW_URL_PREFIX=http://reference_wallet:8080 MW_DRW_PROXY_PORT=3130 pipenv run python3 tests/mw_drw_proxy/proxy.py | ||
``` | ||
This will launch the proxy server on `http://localhost:3130`, and will proxy the requests to an instance of | ||
DRW running at `http://reference_wallet:8080` |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,2 @@ | ||
# Copyright (c) The Diem Core Contributors | ||
# SPDX-License-Identifier: Apache-2.0 |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,78 @@ | ||
# Copyright (c) The Diem Core Contributors | ||
# SPDX-License-Identifier: Apache-2.0 | ||
import logging | ||
import traceback | ||
import random | ||
|
||
import typing | ||
from requests import HTTPError | ||
|
||
DEFAULT_KYC_INFO = { | ||
"first_name": "Default", | ||
"last_name": "KYC", | ||
"dob": "1956-07-09", | ||
"phone": "1 202-456-1414", | ||
"address_1": "1840 Century Park East", | ||
"address_2": "", | ||
"city": "Los Angeles", | ||
"state": "California", | ||
"zip": "90067", | ||
"country": "US", | ||
"selected_fiat_currency": "USD", | ||
"selected_language": "en", | ||
} | ||
|
||
|
||
def convert_user_info_to_offchain(user_info: dict) -> dict: | ||
return { | ||
"payload_version": 1, | ||
"type": "individual", | ||
"given_name": user_info.get("first_name"), | ||
"surname": user_info.get("last_name"), | ||
"dob": user_info.get("dob"), | ||
"address": { | ||
"line1": user_info.get("address_1"), | ||
"line2": user_info.get("address_2"), | ||
"city": user_info.get("city"), | ||
"state": user_info.get("state"), | ||
"postal_code": user_info.get("zip"), | ||
"country": user_info.get("country"), | ||
}, | ||
} | ||
|
||
|
||
def convert_offchain_to_user_info(offchain: dict) -> dict: | ||
address = offchain.get("address") or {} | ||
return { | ||
**DEFAULT_KYC_INFO, | ||
"first_name": offchain.get("given_name"), | ||
"last_name": offchain.get("surname"), | ||
"dob": offchain.get("dob"), | ||
"address_1": address.get("line1"), | ||
"address_2": address.get("line2"), | ||
"city": address.get("city"), | ||
"state": address.get("state"), | ||
"zip": address.get("postal_code"), | ||
"country": address.get("country"), | ||
"selected_fiat_currency": "USD", | ||
"selected_language": "en", | ||
} | ||
|
||
|
||
def error_response(logger: logging.Logger, e: Exception) -> typing.Tuple[dict, int]: | ||
# Use status code 418 (I'm a teapot) to indicate actual proxy server failures vs upstream issues | ||
status_code = 418 | ||
if isinstance(e, HTTPError): | ||
status_code = e.response.status_code | ||
logger.warning( | ||
f"Got error: {e}. {e.request.method} - {e.request.path_url} - {e.request.body}" | ||
) | ||
else: | ||
backtrace = "\n".join(traceback.format_tb(e.__traceback__)) | ||
logger.warning(f"Got error: {e}. \n{backtrace}") | ||
|
||
response = { | ||
"error": str(e), | ||
"stacktrace": traceback.format_tb(e.__traceback__), | ||
} | ||
return response, status_code |
Oops, something went wrong.