diff --git a/.circleci/config.yml b/.circleci/config.yml index 0a42817e..2ba4ff38 100644 --- a/.circleci/config.yml +++ b/.circleci/config.yml @@ -7,11 +7,11 @@ workflows: - unit-test: matrix: parameters: - python-version: ["3.8", "3.9", "3.10"] + python-version: ["3.8", "3.9", "3.10", "3.11"] - integration-test: matrix: parameters: - python-version: ["3.8", "3.9", "3.10"] + python-version: ["3.8", "3.9", "3.10", "3.11"] - docset jobs: diff --git a/.test-env b/.test-env index df783a4f..9dfcb210 100644 --- a/.test-env +++ b/.test-env @@ -13,4 +13,47 @@ REMOVE_LOCAL_FEATURES=0 # WARNING: Be careful when turning on the next variable. # In that case you'll need to provide all variables expected by `algorand-sdk-testing`'s `.env` -OVERWRITE_TESTING_ENVIRONMENT=0 +OVERWRITE_TESTING_ENVIRONMENT=1 + +# WARNING: THE FOLLOWING IS FOR LOCAL DEVELOPMENT ONLY +# IF SET TO 1 AND PUSHED TO C.I., THE TEST WILL HANG AND FAIL. +# +# What can ease some of the pain above is to overwrite interactively: +INTERACTIVE_TESTING_ENVIRONMENT=0 + + +## --- FOR OVERWRITE PURPOSES! DELETE ALL THE BELOW!!!! + +# Used to determine sandbox build type: +TYPE=source # (previously `"channel"`) # OR "source" + + +# Used when TYPE==channel: +ALGOD_CHANNEL="nightly" + +# Used when TYPE==source: +ALGOD_URL=https://github.com/tzaffi/go-algorand # (previously `"https://github.com/algorand/go-algorand"`) +ALGOD_BRANCH=improve-some-goal-errors # (previously `"master"`) +ALGOD_SHA="" + +# Used regardless of TYPE: +NETWORK_TEMPLATE="images/algod/DevModeNetwork.json" # refers to the ./images directory in the sandbox repo +NETWORK_NUM_ROUNDS=30000 +INDEXER_URL="https://github.com/algorand/indexer" +NODE_ARCHIVAL="False" +INDEXER_BRANCH="develop" +INDEXER_SHA="" + +# Sandbox configuration: +SANDBOX_URL="https://github.com/algorand/sandbox" +SANDBOX_BRANCH="master" +LOCAL_SANDBOX_DIR=".sandbox" + +# replacement values for Sandbox's docker-compose: +ALGOD_CONTAINER=sdk-harness-algod +KMD_PORT=60001 +ALGOD_PORT=60000 +INDEXER_CONTAINER=sdk-harness-indexer +INDEXER_PORT=59999 +POSTGRES_CONTAINER=sdk-harness-postgres +POSTGRES_PORT=65432 diff --git a/harness_overwrite.py b/harness_overwrite.py new file mode 100644 index 00000000..5677cd17 --- /dev/null +++ b/harness_overwrite.py @@ -0,0 +1,91 @@ +import sys +from typing import Dict, Optional, Tuple + + +def get_env(line: str) -> Optional[Tuple[str, str, str]]: + if line and line[0] not in (" ", "#") and "=" in line: + key, others = line.split("=", maxsplit=1) + key = key.strip() + if "#" in others: + val, extra = others.split("#", maxsplit=1) + val = val.strip() + else: + val, extra = others.strip(), "" + return key, val, extra + + +def manualy_parse(env_file: str) -> Dict[str, str]: + env = {} + with open(env_file) as f: + for line in f.readlines(): + if e := get_env(line): + key, val, _ = e + env[key] = val + return env + + +def overwrite(env_file: str, new_env: Dict[str, str]) -> None: + with open(env_file, "r+") as f: + lines = f.readlines() + for i, line in enumerate(lines): + if e := get_env(line): + key, old_val, extra = e + if key in new_env and (val := new_env[key]) != old_val: + lines[i] = ( + f"{key}={val} # (previously `{old_val}`)" + + (f" # {extra}" if extra else "") + + "\n" + ) + + f.seek(0) + f.writelines(lines) + f.truncate() + + +def get_rewrites( + env: Dict[str, str], key_filter: Optional[str] = None +) -> Dict[str, str]: + keys = key_filter.split(",") if key_filter else None + return { + k: w + for k, v in env.items() + if (not keys or k in keys) + and (w := input(f"{k} (default `{v}`):").strip()) + and w != v + } + + +def get_keys(env: Dict[str, str]) -> Optional[str]: + print( + f"""Which of the following env vars do you want to modify? + +{",".join(env.keys())} + + (skip for ALL, or provide comma separated) + + A typical choice is: +TYPE,ALGOD_URL,ALGOD_BRANCH +""" + ) + return input("CHOICES:\n").strip() + + +def go(): + env_file = sys.argv[1] + env = manualy_parse(env_file) + print("_" * 50) + keys = get_keys(env) + print("_" * 50) + print("Please provide env variable overrides (skip to keep defaults)") + new_env = get_rewrites(env, key_filter=keys) + + print("_" * 50) + print("OVERWRITING") + for k, v in new_env.items(): + print(f"new_env[{k}]={v} (PREVIOUS: env[{k}]={env[k]})") + + overwrite(env_file, new_env) + print("_" * 50) + + +go() diff --git a/test-harness.sh b/test-harness.sh index 7e1a4f75..91c4fdca 100755 --- a/test-harness.sh +++ b/test-harness.sh @@ -84,6 +84,12 @@ if [[ $OVERWRITE_TESTING_ENVIRONMENT == 1 ]]; then cp "$ENV_FILE" "$SDK_TESTING_HARNESS"/.env fi +# **** BEGIN PYTHON ONLY **** # +echo "$THIS: INTERACTIVE_TESTING_ENVIRONMENT=$INTERACTIVE_TESTING_ENVIRONMENT" +if [[ $INTERACTIVE_TESTING_ENVIRONMENT == 1 ]]; then + python harness_overwrite.py "$SDK_TESTING_HARNESS"/.env +fi +# **** END PYTHON ONLY **** # echo "$THIS: REMOVE_LOCAL_FEATURES=$REMOVE_LOCAL_FEATURES" ## Copy feature files into the project resources