Testing Guide
Running Tests
Warning
Running all tests simultaneously may cause errors due to resource constraints. It is recommended to run per file or small groups.
Running Unit Tests
Running Integration Tests
Running Scenario Tests
Running Benchmark Tests
python -m pytest tests --benchmark-only -v --benchmark-save=benchmark_report
python -m pytest tests --benchmark-only -v --benchmark-histogram=benchmark_report
Running All Tests
Stress Testing
Docker Stress Testing
Run stress tests in Docker containers with 4 HieraChain nodes (1 CPU, 1GiB RAM each):
-
Build and run stress tests with HTML report:
-
Run real network stress tests (sends actual HTTP requests to nodes):
-
Run without HTML report:
-
Stop and clean up containers:
Reports are saved to log/report/ directory.
Kubernetes Stress Testing
Run stress tests in Kubernetes
Recommendation: Use Docker Compose for local dev. Use Kubernetes when you need a production-like environment.
Quick Start:
# Build image
docker build --no-cache -t hierachain:latest -f docker/Dockerfile .
# Create Kind cluster
kind create cluster --config docker/kind-config.yaml
# Resource limit for each Node of K8s (1 CPU, 1GiB RAM)
docker update --cpus 1 --memory 1g --memory-swap 1g hiera-cluster-control-plane
docker update --cpus 1 --memory 1g --memory-swap 1g hiera-cluster-worker
docker update --cpus 1 --memory 1g --memory-swap 1g hiera-cluster-worker2
docker update --cpus 1 --memory 1g --memory-swap 1g hiera-cluster-worker3
# Load image into cluster
kind load docker-image hierachain:latest --name hiera-cluster
kubectl apply -k docker/k8s/
# Wait for pods to be ready
kubectl wait --for=condition=ready pod -l app=hierachain -n hierachain --timeout=120s
# Expose the API to local host
kubectl port-forward service/hierachain-api 2661:2661 -n hierachain --address 0.0.0.0
# Test API
curl http://localhost:2661/api/v1/health
# Run stress test
docker compose -f docker/docker-compose.k8s-stress.yml --profile stress-test run --build stress-tester python -m pytest tests/stress/ -v --html=/app/log/report/stress_test_report.html --self-contained-html
# Cleanup
kubectl delete -k docker/k8s/
kind delete cluster --name hiera-cluster
Developer Scripts
The scripts/ directory contains utility tools.
Static Analysis
# Run default
python -m scripts.static_analysis
# Export results to file
python -m scripts.static_analysis --output analysis_report.json
Benchmarking
-
Hashing Performance (Compare Merkle tree hash vs JSON):
-
Throughput Benchmark (Measure event processing throughput):
Storage Verification
-
Verify Storage Persistence (Test SQLite durability):
Pytest Configuration (excerpt from pyproject.toml)
testpaths = ["tests/unit", "tests/integration", "tests/scenarios"]python_files = "test_*.py"python_classes = "Test*"python_functions = "test_*"-
Markers:
critical,high,medium,lowintegration,recovery,stress
Running by Marker Example
Testing Principles
- Focus on public API behavior of the module.
- Test edge cases and error scenarios.
- Keep tests independent, runnable by marker.
Test Layout Suggestions
- Unit: test individual classes/functions (core, security, storage...).
- Integration: test end-to-end flows via API v1/v2.
- Scenarios: business scenarios (e.g. create sub-chain → write event → submit proof → trace entity).