global: snapshot

This commit is contained in:
nym21
2026-01-11 17:19:00 +01:00
parent 6f45ec13f3
commit ea70c381de
419 changed files with 38059 additions and 7653 deletions
+47
View File
@@ -0,0 +1,47 @@
from __future__ import print_function
from brk_client import BrkClient
def test_client_creation():
client = BrkClient("http://localhost:3110")
assert client.base_url == "http://localhost:3110"
def test_tree_exists():
client = BrkClient("http://localhost:3110")
assert hasattr(client, "tree")
assert hasattr(client.tree, "price")
assert hasattr(client.tree, "blocks")
def test_fetch_block():
client = BrkClient("http://localhost:3110")
print(client.get_block_height(800000))
def test_fetch_any_metric():
client = BrkClient("http://localhost:3110")
print(client.get_metric_by_index("dateindex", "price_close"))
def test_fetch_typed_metric():
client = BrkClient("http://localhost:3110")
a = client.tree.constants.constant_0.by.dateindex().range(-10)
print(a)
b = client.tree.outputs.count.utxo_count.by.height().range(-10)
print(b)
c = client.tree.price.usd.split.close.by.dateindex().range(-10)
print(c)
d = client.tree.market.dca.period_lump_sum_stack._10y.dollars.by.dateindex().range(
-10
)
print(d)
e = client.tree.market.dca.class_average_price._2017.by.dateindex().range(-10)
print(e)
f = client.tree.distribution.address_cohorts.amount_range._10k_sats_to_100k_sats.activity.sent.dollars.cumulative.by.dateindex().range(
-10
)
print(f)
g = client.tree.price.usd.ohlc.by.dateindex().range(-10)
print(g)
-21
View File
@@ -1,21 +0,0 @@
from __future__ import print_function
from brk_client import VERSION, BrkClient
def test_version():
assert VERSION.startswith("v")
def test_client_creation():
client = BrkClient("http://localhost:3110")
assert client.base_url == "http://localhost:3110"
def test_tree_exists():
client = BrkClient("http://localhost:3110")
print(client.get_api_block_height_by_height(800000))
print(client.get_api_metric_by_metric_by_index("price_close", "dateindex"))
assert hasattr(client, "tree")
assert hasattr(client.tree, "computed")
assert hasattr(client.tree, "indexed")
+89
View File
@@ -0,0 +1,89 @@
"""Comprehensive test that fetches all endpoints in the tree."""
from brk_client import BrkClient
def get_all_metrics(obj, path=""):
"""Recursively collect all MetricPattern instances from the tree."""
metrics = []
for attr_name in dir(obj):
if attr_name.startswith("_"):
continue
try:
attr = getattr(obj, attr_name)
except Exception:
continue
current_path = f"{path}.{attr_name}" if path else attr_name
# Check if this is a metric pattern (has 'by' attribute with index methods)
if hasattr(attr, "by"):
by = attr.by
indexes = []
for idx_name in dir(by):
if not idx_name.startswith("_") and callable(
getattr(by, idx_name, None)
):
indexes.append(idx_name)
if indexes:
metrics.append((current_path, attr, indexes))
# Recurse into nested tree nodes
if hasattr(attr, "__dict__") and not callable(attr):
metrics.extend(get_all_metrics(attr, current_path))
return metrics
def test_all_endpoints():
"""Test fetching last 3 values from all metric endpoints."""
client = BrkClient("http://localhost:3110")
metrics = get_all_metrics(client.tree)
print(f"\nFound {len(metrics)} metrics")
success = 0
failed = 0
errors = []
for path, metric, indexes in metrics:
for idx_name in indexes:
try:
by = metric.by
endpoint = getattr(by, idx_name)()
res = endpoint.range(-3)
count = len(res["data"])
if count != 3:
failed += 1
error_msg = (
f"FAIL: {path}.by.{idx_name}() -> expected 3, got {count}"
)
errors.append(error_msg)
print(error_msg)
else:
success += 1
print(f"OK: {path}.by.{idx_name}() -> {count} items")
except Exception as e:
failed += 1
error_msg = f"FAIL: {path}.by.{idx_name}() -> {e}"
errors.append(error_msg)
print(error_msg)
print("\n=== Results ===")
print(f"Success: {success}")
print(f"Failed: {failed}")
if errors:
print("\nErrors:")
for err in errors[:10]: # Show first 10 errors
print(f" {err}")
if len(errors) > 10:
print(f" ... and {len(errors) - 10} more")
assert failed == 0, f"{failed} endpoints failed"
if __name__ == "__main__":
test_all_endpoints()