diff --git a/cli/config b/cli/config index 73a4dd675..874d82d62 100644 --- a/cli/config +++ b/cli/config @@ -1 +1,3 @@ -URL=http://localhost:9090/wallet/v2 +{ + "URL" : "http://localhost:9090/wallet/v2" +} diff --git a/cli/forest_utils.py b/cli/forest_utils.py index 27f66b0f4..21dab90b5 100644 --- a/cli/forest_utils.py +++ b/cli/forest_utils.py @@ -1,11 +1,16 @@ #!/usr/bin/python3.9 # Copyright (c) 2021 MobileCoin Inc. # Copyright (c) 2021 The Forest Team -import functools + +import json import logging import os from typing import Optional, cast, Dict +if __name__ == '__main__': + module_root = os.getcwd() +else: + module_root = os.path.dirname(__file__) def MuteAiohttp(record: logging.LogRecord) -> bool: str_msg = str(getattr(record, "msg", "")) @@ -34,30 +39,29 @@ def MuteAiohttp(record: logging.LogRecord) -> bool: # edge cases: # accessing an unset secret loads other variables and potentially overwrites existing ones -def parse_secrets(secrets: str) -> dict[str, str]: - pairs = [ - line.strip().split("=", 1) - for line in secrets.split("\n") - if line and not line.startswith("#") - ] - can_be_a_dict = cast(list[tuple[str, str]], pairs) - return dict(can_be_a_dict) +def parse_secrets(file: str) -> Dict[str, str]: + with open(file) as json_file: + config = json.load(json_file) + return config -# to dump: "\n".join(f"{k}={v}" for k, v in secrets.items()) +# to dump: "\n".join(f"{k}={v}" for k, v in secrets.items()) +env_cache = set() -@functools.cache # don't load the same env more than once def load_secrets(env: Optional[str] = None, overwrite: bool = False) -> None: + if str(env) in env_cache: + return + env_cache.add(str(env)) if not env: env = os.environ.get("ENV", "dev") try: - secrets = parse_secrets(open(f"config").read()) + secrets = parse_secrets(f"{module_root}/config") if overwrite: new_env = secrets else: # mask loaded secrets with existing env - new_env = secrets | os.environ + new_env = {**secrets, **dict(os.environ)} os.environ.update(new_env) except FileNotFoundError: pass diff --git a/cli/fullservice.py b/cli/fullservice.py index a55f51df7..8ee2395a8 100644 --- a/cli/fullservice.py +++ b/cli/fullservice.py @@ -26,17 +26,23 @@ class Request: + def __init__(self, logLevel = logging.ERROR): + logging.basicConfig( level=logLevel) url = utils.get_secret('URL') + logging.info("Woohoo error") async def req(self, request_data: dict) -> dict: logging.info("request: %s", request_data.get("method")) - request_data["params"] = { - k: v for k, v in request_data["params"].items() if v - } # handle optional params + if len(request_data["params"]) > 0: + request_data["params"] = { + k: v for k, v in request_data["params"].items() if v + } # handle optional params + else: + del request_data["params"] response_data = await self.request(request_data) - if "error" in str(response_data): + if "error" in str(response_data) or "InvalidRequest" in str(response_data): logging.error(response_data) else: - print(response_data) + logging.info(response_data) return response_data async def request(self, request_data: dict): @@ -55,6 +61,9 @@ async def request(self, request_data: dict): class FullServiceAPIv2(Request): + def __init__(self, logLevel=logging.ERROR): + logging.basicConfig( level=logLevel) + async def assign_address_for_account(self, account_id, metadata=""): return await self.req( { diff --git a/integ-tests/basic.py b/integ-tests/basic.py new file mode 100644 index 000000000..125513cea --- /dev/null +++ b/integ-tests/basic.py @@ -0,0 +1,32 @@ +# verify that the transaction went through +# the mob went through +# the transaction log updatedx +# Ideally all of the endpoints (v2) that actually hit the mobilecoin network +# +# get_network_status +# get_wallet_status +# build, build_and_submit, build_split_txo .. etc + +import sys +import os +sys.path.append(os.path.abspath("../cli")) + +from fullservice import FullServiceAPIv2 as v2 +import asyncio +import json +import subprocess +from pathlib import Path + +with open('config') as json_file: + config = json.load(json_file) + + +async def main(): + fs = v2() + + network_status = await fs.get_network_status() + print(network_status) + + +if __name__ == '__main__': + asyncio.run(main()) \ No newline at end of file diff --git a/integ-tests/config b/integ-tests/config new file mode 100644 index 000000000..7a73a41bf --- /dev/null +++ b/integ-tests/config @@ -0,0 +1,2 @@ +{ +} \ No newline at end of file diff --git a/tools/run-fs.sh b/tools/run-fs.sh index c7c471593..f0f70b245 100755 --- a/tools/run-fs.sh +++ b/tools/run-fs.sh @@ -18,10 +18,12 @@ elif [ "$NET" == "alpha" ]; then PEER_DOMAIN="alpha.development.mobilecoin.com/" TX_SOURCE_URL="https://s3-eu-central-1.amazonaws.com/mobilecoin.eu.development.chain" INGEST_SIGSTRUCT_URI="" +elif [ "$NET" == "local" ]; then + NAMESPACE=$NET + INGEST_SIGSTRUCT_URI="" else - # TODO: add support for local network echo "Unknown network" - echo "Usage: run-fs.sh {main|test|alpha} [--no-build]" + echo "Usage: run-fs.sh {main|test|alpha|local} [--no-build]" exit 1 fi @@ -31,11 +33,12 @@ LEDGER_DB_DIR="${WORK_DIR}/ledger-db" INGEST_DOWNLOAD_LOCATION="$WORK_DIR/ingest-enclave.css" mkdir -p ${WORK_DIR} - +# If there is no file at the download location and we know where to download it from if ! test -f "$INGEST_DOWNLOAD_LOCATION" && [ "$INGEST_SIGSTRUCT_URI" != "" ]; then (cd ${WORK_DIR} && curl -O https://enclave-distribution.${NAMESPACE}.mobilecoin.com/${INGEST_SIGSTRUCT_URI}) fi +# If the environment variable isn't set if [ -z "$INGEST_ENCLAVE_CSS" ]; then export INGEST_ENCLAVE_CSS=$INGEST_DOWNLOAD_LOCATION fi @@ -54,13 +57,26 @@ if [ "$2" != "--no-build" ]; then cp $SCRIPT_DIR/../target/release/full-service $WORK_DIR fi + mkdir -p ${WALLET_DB_DIR} -$WORK_DIR/full-service \ - --wallet-db ${WALLET_DB_DIR}/wallet.db \ - --ledger-db ${LEDGER_DB_DIR} \ - --peer mc://node1.${PEER_DOMAIN} \ - --peer mc://node2.${PEER_DOMAIN} \ - --tx-source-url ${TX_SOURCE_URL}/node1.${PEER_DOMAIN} \ - --tx-source-url ${TX_SOURCE_URL}/node2.${PEER_DOMAIN} \ - --fog-ingest-enclave-css $INGEST_ENCLAVE_CSS \ - --chain-id $NET +if [ "$NET" == "local" ]; then + $WORK_DIR/full-service \ + --wallet-db ${WALLET_DB_DIR}/wallet.db \ + --ledger-db ${LEDGER_DB_DIR} \ + --peer insecure-mc://localhost:3200 \ + --peer insecure-mc://localhost:3201 \ + --tx-source-url http://localhost:4566/node-0-ledger \ + --tx-source-url http://localhost:4566/node-1-ledger \ + --fog-ingest-enclave-css $INGEST_ENCLAVE_CSS \ + --chain-id $NET +else + $WORK_DIR/full-service \ + --wallet-db ${WALLET_DB_DIR}/wallet.db \ + --ledger-db ${LEDGER_DB_DIR} \ + --peer mc://node1.${PEER_DOMAIN} \ + --peer mc://node2.${PEER_DOMAIN} \ + --tx-source-url ${TX_SOURCE_URL}/node1.${PEER_DOMAIN} \ + --tx-source-url ${TX_SOURCE_URL}/node2.${PEER_DOMAIN} \ + --fog-ingest-enclave-css $INGEST_ENCLAVE_CSS \ + --chain-id $NET +fi