Skip to content

Commit

Permalink
fix: use /v2/status when querying localnet algod container (#198)
Browse files Browse the repository at this point in the history
  • Loading branch information
daniel-makerx authored Mar 9, 2023
1 parent 8b2910b commit 0fb0488
Show file tree
Hide file tree
Showing 7 changed files with 24 additions and 16 deletions.
12 changes: 6 additions & 6 deletions src/algokit/core/sandbox.py
Original file line number Diff line number Diff line change
Expand Up @@ -155,7 +155,7 @@ def fetch_algod_status_data(service_info: dict[str, Any]) -> dict[str, Any]:
with httpx.Client() as client:
algod_headers = {"X-Algo-API-Token": DEFAULT_ALGOD_TOKEN}
http_status_response = client.get(
f"{DEFAULT_ALGOD_SERVER}:{DEFAULT_ALGOD_PORT}/v1/status", headers=algod_headers, timeout=3
f"{DEFAULT_ALGOD_SERVER}:{DEFAULT_ALGOD_PORT}/v2/status", headers=algod_headers, timeout=3
)
http_versions_response = client.get(
f"{DEFAULT_ALGOD_SERVER}:{DEFAULT_ALGOD_PORT}/versions", headers=algod_headers, timeout=3
Expand All @@ -168,8 +168,8 @@ def fetch_algod_status_data(service_info: dict[str, Any]) -> dict[str, Any]:

# status response
status_response = http_status_response.json()
results["Last round"] = status_response["lastRound"]
results["Time since last round"] = "%.1fs" % status_response["timeSinceLastRound"]
results["Last round"] = status_response["last-round"]
results["Time since last round"] = "%.1fs" % (status_response["time-since-last-round"] / 1e9)
# genesis response
genesis_response = http_versions_response.json()
results["Genesis ID"] = genesis_response["genesis_id"]
Expand All @@ -193,15 +193,15 @@ def fetch_indexer_status_data(service_info: dict[str, Any]) -> dict[str, Any]:

results["Port"] = service_info["Publishers"][0]["PublishedPort"]
# container specific response
http_response = httpx.get(f"{DEFAULT_ALGOD_SERVER}:{DEFAULT_INDEXER_PORT}/health", timeout=5)
health_url = f"{DEFAULT_ALGOD_SERVER}:{DEFAULT_INDEXER_PORT}/health"
http_response = httpx.get(health_url, timeout=5)

if http_response.status_code != httpx.codes.OK:
return {"Status": "Error"}

response = http_response.json()
logger.debug(f"{health_url} response: {response}")
results["Last round"] = response["round"]
if "errors" in response:
results["Error(s)"] = response["errors"]
results["Version"] = response["version"]
return results
except Exception as err:
Expand Down
16 changes: 12 additions & 4 deletions tests/localnet/test_localnet_status.py
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,9 @@ def test_localnet_status_successful(app_dir_mock: AppDirs, proc_mock: ProcMock,
(app_dir_mock.app_config_dir / "sandbox").mkdir()
(app_dir_mock.app_config_dir / "sandbox" / "docker-compose.yml").write_text("existing")

httpx_mock.add_response(url="http://localhost:4001/v1/status", json={"lastRound": 1, "timeSinceLastRound": 15.3})
httpx_mock.add_response(
url="http://localhost:4001/v2/status", json={"last-round": 1, "time-since-last-round": 15.3 * 1e9}
)
httpx_mock.add_response(
url="http://localhost:4001/versions",
json={
Expand Down Expand Up @@ -83,7 +85,9 @@ def test_localnet_status_http_error(app_dir_mock: AppDirs, proc_mock: ProcMock,
(app_dir_mock.app_config_dir / "sandbox").mkdir()
(app_dir_mock.app_config_dir / "sandbox" / "docker-compose.yml").write_text("existing")

httpx_mock.add_response(url="http://localhost:4001/v1/status", json={"lastRound": 1, "timeSinceLastRound": 15.3})
httpx_mock.add_response(
url="http://localhost:4001/v2/status", json={"last-round": 1, "time-since-last-round": 15.3 * 1e9}
)
httpx_mock.add_response(
url="http://localhost:4001/versions",
json={
Expand Down Expand Up @@ -152,7 +156,9 @@ def test_localnet_status_unexpected_port(app_dir_mock: AppDirs, proc_mock: ProcM
(app_dir_mock.app_config_dir / "sandbox").mkdir()
(app_dir_mock.app_config_dir / "sandbox" / "docker-compose.yml").write_text("existing")

httpx_mock.add_response(url="http://localhost:4001/v1/status", json={"lastRound": 1, "timeSinceLastRound": 15.3})
httpx_mock.add_response(
url="http://localhost:4001/v2/status", json={"last-round": 1, "time-since-last-round": 15.3 * 1e9}
)
httpx_mock.add_response(
url="http://localhost:4001/versions",
json={
Expand Down Expand Up @@ -282,7 +288,9 @@ def test_localnet_status_docker_error(app_dir_mock: AppDirs, proc_mock: ProcMock
(app_dir_mock.app_config_dir / "sandbox").mkdir()
(app_dir_mock.app_config_dir / "sandbox" / "docker-compose.yml").write_text("existing")

httpx_mock.add_response(url="http://localhost:4001/v1/status", json={"lastRound": 1, "timeSinceLastRound": 15.3})
httpx_mock.add_response(
url="http://localhost:4001/v2/status", json={"last-round": 1, "time-since-last-round": 15.3 * 1e9}
)
httpx_mock.add_response(
url="http://localhost:4001/versions",
json={
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ DEBUG: docker: STDOUT
DEBUG: docker: STDERR
DEBUG: Running 'docker compose ps --format json' in '{app_config}/sandbox'
DEBUG: docker: [{"ID": "00e93d3db91d964d1b2bcf444c938140dc6b43398380374eaac8510f45381973", "Name": "algokit_algod", "Command": "start.sh", "Project": "algokit_sandbox", "Service": "algod", "State": "running", "Health": "", "ExitCode": 0, "Publishers": [{"URL": "0.0.0.0", "TargetPort": 4001, "PublishedPort": 4001, "Protocol": "tcp"}, {"URL": "0.0.0.0", "TargetPort": 4002, "PublishedPort": 4002, "Protocol": "tcp"}, {"URL": "0.0.0.0", "TargetPort": 9392, "PublishedPort": 9392, "Protocol": "tcp"}]}, {"ID": "a242581a65f7e49d376bff9fd8d2288cdd85a28a264657d73db84dbeef6155b7", "Name": "algokit_indexer", "Command": "/tmp/start.sh", "Project": "algokit_sandbox", "Service": "indexer", "State": "running", "Health": "", "ExitCode": 0, "Publishers": []}, {"ID": "9e66aca1cd3542446e7b88f0701122a90f388308f7de0b57b6e2d843b3da9026", "Name": "algokit_postgres", "Command": "docker-entrypoint.sh postgres", "Project": "algokit_sandbox", "Service": "indexer-db", "State": "running", "Health": "", "ExitCode": 0, "Publishers": [{"URL": "", "TargetPort": 5432, "PublishedPort": 0, "Protocol": "tcp"}]}]
DEBUG: HTTP Request: GET http://localhost:4001/v1/status "HTTP/1.1 200 OK"
DEBUG: HTTP Request: GET http://localhost:4001/v2/status "HTTP/1.1 200 OK"
DEBUG: HTTP Request: GET http://localhost:4001/versions "HTTP/1.1 200 OK"
# algod status
Status: Running
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ DEBUG: docker: STDOUT
DEBUG: docker: STDERR
DEBUG: Running 'docker compose ps --format json' in '{app_config}/sandbox'
DEBUG: docker: [{"ID": "00e93d3db91d964d1b2bcf444c938140dc6b43398380374eaac8510f45381973", "Name": "algokit_algod", "Command": "start.sh", "Project": "algokit_sandbox", "Service": "algod", "State": "running", "Health": "", "ExitCode": 0, "Publishers": [{"URL": "0.0.0.0", "TargetPort": 4001, "PublishedPort": 4001, "Protocol": "tcp"}, {"URL": "0.0.0.0", "TargetPort": 4002, "PublishedPort": 4002, "Protocol": "tcp"}, {"URL": "0.0.0.0", "TargetPort": 9392, "PublishedPort": 9392, "Protocol": "tcp"}]}, {"ID": "a242581a65f7e49d376bff9fd8d2288cdd85a28a264657d73db84dbeef6155b7", "Name": "algokit_indexer", "Command": "/tmp/start.sh", "Project": "algokit_sandbox", "Service": "indexer", "State": "running", "Health": "", "ExitCode": 0, "Publishers": [{"URL": "0.0.0.0", "TargetPort": 8980, "PublishedPort": 8980, "Protocol": "tcp"}]}, {"ID": "9e66aca1cd3542446e7b88f0701122a90f388308f7de0b57b6e2d843b3da9026", "Name": "algokit_postgres", "Command": "docker-entrypoint.sh postgres", "Project": "algokit_sandbox", "Service": "indexer-db", "State": "running", "Health": "", "ExitCode": 0, "Publishers": [{"URL": "", "TargetPort": 5432, "PublishedPort": 0, "Protocol": "tcp"}]}]
DEBUG: HTTP Request: GET http://localhost:4001/v1/status "HTTP/1.1 200 OK"
DEBUG: HTTP Request: GET http://localhost:4001/v2/status "HTTP/1.1 200 OK"
DEBUG: HTTP Request: GET http://localhost:4001/versions "HTTP/1.1 200 OK"
DEBUG: Error checking indexer status: Unable to read within timeout
# algod status
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -6,13 +6,13 @@ DEBUG: docker: STDERR
DEBUG: Running 'docker compose ps --format json' in '{app_config}/sandbox'
DEBUG: docker: [{"ID": "00e93d3db91d964d1b2bcf444c938140dc6b43398380374eaac8510f45381973", "Name": "algokit_algod", "Command": "start.sh", "Project": "algokit_sandbox", "Service": "algod", "State": "stopped", "Health": "", "ExitCode": 0, "Publishers": [{"URL": "0.0.0.0", "TargetPort": 4001, "PublishedPort": 4001, "Protocol": "tcp"}, {"URL": "0.0.0.0", "TargetPort": 4002, "PublishedPort": 4002, "Protocol": "tcp"}, {"URL": "0.0.0.0", "TargetPort": 9392, "PublishedPort": 9392, "Protocol": "tcp"}]}, {"ID": "a242581a65f7e49d376bff9fd8d2288cdd85a28a264657d73db84dbeef6155b7", "Name": "algokit_indexer", "Command": "/tmp/start.sh", "Project": "algokit_sandbox", "Service": "indexer", "State": "running", "Health": "", "ExitCode": 0, "Publishers": [{"URL": "0.0.0.0", "TargetPort": 8980, "PublishedPort": 8980, "Protocol": "tcp"}]}, {"ID": "9e66aca1cd3542446e7b88f0701122a90f388308f7de0b57b6e2d843b3da9026", "Name": "algokit_postgres", "Command": "docker-entrypoint.sh postgres", "Project": "algokit_sandbox", "Service": "indexer-db", "State": "running", "Health": "", "ExitCode": 0, "Publishers": [{"URL": "", "TargetPort": 5432, "PublishedPort": 0, "Protocol": "tcp"}]}]
DEBUG: HTTP Request: GET http://localhost:8980/health "HTTP/1.1 200 OK"
DEBUG: http://localhost:8980/health response: {'round': 1, 'errors': ['error'], 'version': 'v1.0'}
# algod status
Status: Not running
# indexer status
Status: Running
Port: 8980
Last round: 1
Error(s): ['error']
Version: v1.0
# indexer-db status
Status: Running
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,9 +5,10 @@ DEBUG: docker: STDOUT
DEBUG: docker: STDERR
DEBUG: Running 'docker compose ps --format json' in '{app_config}/sandbox'
DEBUG: docker: [{"ID": "90ce27e631e4d0b048322abd01a9e68e4c899b936ad4e4e3106ad5d9f774a189", "Name": "algokit_algod", "Command": "start.sh", "Project": "algokit_sandbox", "Service": "algod", "State": "running", "Health": "", "ExitCode": 0, "Publishers": [{"URL": "0.0.0.0", "TargetPort": 4001, "PublishedPort": 4001, "Protocol": "tcp"}, {"URL": "0.0.0.0", "TargetPort": 4002, "PublishedPort": 4002, "Protocol": "tcp"}, {"URL": "0.0.0.0", "TargetPort": 9392, "PublishedPort": 9392, "Protocol": "tcp"}]}, {"ID": "d3a74173d552ac388643ee65c9c6aa4c1864cb1442d0423d62bd95c468ac4b97", "Name": "algokit_indexer", "Command": "/tmp/start.sh", "Project": "algokit_sandbox", "Service": "indexer", "State": "running", "Health": "", "ExitCode": 0, "Publishers": [{"URL": "0.0.0.0", "TargetPort": 8980, "PublishedPort": 8980, "Protocol": "tcp"}]}, {"ID": "9e66aca1cd3542446e7b88f0701122a90f388308f7de0b57b6e2d843b3da9026", "Name": "algokit_postgres", "Command": "docker-entrypoint.sh postgres", "Project": "algokit_sandbox", "Service": "indexer-db", "State": "running", "Health": "", "ExitCode": 0, "Publishers": [{"URL": "", "TargetPort": 5432, "PublishedPort": 0, "Protocol": "tcp"}]}]
DEBUG: HTTP Request: GET http://localhost:4001/v1/status "HTTP/1.1 200 OK"
DEBUG: HTTP Request: GET http://localhost:4001/v2/status "HTTP/1.1 200 OK"
DEBUG: HTTP Request: GET http://localhost:4001/versions "HTTP/1.1 200 OK"
DEBUG: HTTP Request: GET http://localhost:8980/health "HTTP/1.1 200 OK"
DEBUG: http://localhost:8980/health response: {'round': 1, 'errors': ['error'], 'version': 'v1.0'}
# algod status
Status: Running
Port: 4001
Expand All @@ -20,7 +21,6 @@ Version: 1.2.1
Status: Running
Port: 8980
Last round: 1
Error(s): ['error']
Version: v1.0
# indexer-db status
Status: Running
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ DEBUG: docker: STDOUT
DEBUG: docker: STDERR
DEBUG: Running 'docker compose ps --format json' in '{app_config}/sandbox'
DEBUG: docker: [{"ID": "00e93d3db91d964d1b2bcf444c938140dc6b43398380374eaac8510f45381973", "Name": "algokit_algod", "Command": "start.sh", "Project": "algokit_sandbox", "Service": "algod", "State": "running", "Health": "", "ExitCode": 0, "Publishers": [{"URL": "0.0.0.0", "TargetPort": 4001, "PublishedPort": 4001, "Protocol": "tcp"}, {"URL": "0.0.0.0", "TargetPort": 4002, "PublishedPort": 4002, "Protocol": "tcp"}, {"URL": "0.0.0.0", "TargetPort": 9392, "PublishedPort": 9392, "Protocol": "tcp"}]}, {"ID": "a242581a65f7e49d376bff9fd8d2288cdd85a28a264657d73db84dbeef6155b7", "Name": "algokit_indexer", "Command": "/tmp/start.sh", "Project": "algokit_sandbox", "Service": "indexer", "State": "running", "Health": "", "ExitCode": 0, "Publishers": [{"URL": "0.0.0.0", "TargetPort": 1234, "PublishedPort": 1234, "Protocol": "tcp"}]}, {"ID": "9e66aca1cd3542446e7b88f0701122a90f388308f7de0b57b6e2d843b3da9026", "Name": "algokit_postgres", "Command": "docker-entrypoint.sh postgres", "Project": "algokit_sandbox", "Service": "indexer-db", "State": "running", "Health": "", "ExitCode": 0, "Publishers": [{"URL": "", "TargetPort": 5432, "PublishedPort": 0, "Protocol": "tcp"}]}]
DEBUG: HTTP Request: GET http://localhost:4001/v1/status "HTTP/1.1 200 OK"
DEBUG: HTTP Request: GET http://localhost:4001/v2/status "HTTP/1.1 200 OK"
DEBUG: HTTP Request: GET http://localhost:4001/versions "HTTP/1.1 200 OK"
# algod status
Status: Running
Expand Down

1 comment on commit 0fb0488

@github-actions
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Coverage

Coverage Report
FileStmtsMissCoverMissing
src/algokit
   __init__.py15753%6–13, 17–24, 32–34
   __main__.py220%1–3
src/algokit/cli
   completions.py103199%91
   doctor.py48394%140–142
   goal.py22195%36
   init.py1701691%53, 221–222, 253, 258–260, 271, 309, 346, 355–357, 360–365, 380
   localnet.py84199%157
src/algokit/core
   bootstrap.py1331688%109, 127, 195, 198, 204–218
   click_extensions.py482058%41–44, 51, 57, 68–69, 74–75, 80–81, 92, 105–115
   conf.py30487%13, 17, 25, 27
   doctor.py57395%63–65
   log_handlers.py68987%44–45, 50–51, 63, 112–116, 125
   proc.py45198%98
   sandbox.py112794%86, 151, 167, 182–184, 200
   version_prompt.py73889%27–28, 40, 59–62, 80, 109
TOTAL11299991% 

Tests Skipped Failures Errors Time
182 0 💤 0 ❌ 0 🔥 11.398s ⏱️

Please sign in to comment.