Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 2 additions & 2 deletions .circleci/config.yml
Original file line number Diff line number Diff line change
Expand Up @@ -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:
Expand Down
45 changes: 44 additions & 1 deletion .test-env
Original file line number Diff line number Diff line change
Expand Up @@ -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
91 changes: 91 additions & 0 deletions harness_overwrite.py
Original file line number Diff line number Diff line change
@@ -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()
6 changes: 6 additions & 0 deletions test-harness.sh
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down