Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Create integration test template that will run locally #581

Merged
merged 10 commits into from
Nov 15, 2022
4 changes: 3 additions & 1 deletion cli/config
Original file line number Diff line number Diff line change
@@ -1 +1,3 @@
URL=http://localhost:9090/wallet/v2
{
"URL" : "http://localhost:9090/wallet/v2"
}
30 changes: 17 additions & 13 deletions cli/forest_utils.py
Original file line number Diff line number Diff line change
@@ -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", ""))
Expand Down Expand Up @@ -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
Expand Down
19 changes: 14 additions & 5 deletions cli/fullservice.py
Original file line number Diff line number Diff line change
Expand Up @@ -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):
Expand All @@ -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(
{
Expand Down
32 changes: 32 additions & 0 deletions integ-tests/basic.py
Original file line number Diff line number Diff line change
@@ -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())
2 changes: 2 additions & 0 deletions integ-tests/config
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
{
}
40 changes: 28 additions & 12 deletions tools/run-fs.sh
Original file line number Diff line number Diff line change
Expand Up @@ -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

Expand All @@ -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
Expand All @@ -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