Skip to content

Latest commit

Β 

History

History
564 lines (411 loc) Β· 10.9 KB

File metadata and controls

564 lines (411 loc) Β· 10.9 KB

CompZ Testing & Usage Guide

Complete guide to test and use CompZ SDK with real Zcash blockchain integration.


πŸš€ Quick Start (3 Options)

Option 1: Instant Test (No Setup Required)

Test CompZ functionality without any blockchain setup:

# Install dependencies
cd /Users/satyamsinghal/Desktop/Products/CompZ
pip install -e .

# Test normalization and hashing
cd examples
python3 tamper_detection_demo.py

What this shows:

  • βœ… Deterministic JSON normalization
  • βœ… SHA-256 hash computation
  • βœ… Tampering detection logic
  • ⏱️ Takes: 10 seconds

Option 2: Demo Mode Test (Simulated)

Test the full workflow with demo mode (no blockchain):

cd examples
python3 basic_usage.py

What this shows:

  • βœ… SDK client initialization
  • βœ… Data normalization
  • βœ… Hash computation
  • βœ… Full API flow (simulated)
  • ⏱️ Takes: 30 seconds

Note: Demo mode shows the flow but doesn't use real blockchain (gateway endpoint not deployed yet).


Option 3: Real Zcash Testnet (Full Integration)

Test with actual Zcash blockchain transactions:

# Run automated setup
./scripts/setup_testnet.sh

# Follow prompts to:
# 1. Start Zcash node
# 2. Generate z-address
# 3. Fund from faucet
# 4. Configure .env

# Run real blockchain test
cd examples
python3 self_hosted_example.py

What this shows:

  • βœ… Real Zcash node connection
  • βœ… Shielded transaction creation
  • βœ… Memo field storage
  • βœ… On-chain verification
  • βœ… Block explorer integration
  • ⏱️ Takes: 2-4 hours (blockchain sync) + 5 minutes

πŸ“– Detailed Testing Instructions

Step 1: Install CompZ

cd /Users/satyamsinghal/Desktop/Products/CompZ

# Install in development mode
pip install -e .

# Verify installation
compz version
# Should output: CompZ SDK v1.0.0

Step 2: Test Core Functionality

A. Test Normalization

# Create test file: test_normalize.py
from compz.normalize import normalize_json

data = {
    "b": 2,
    "a": 1,
    "_internal": "removed",
    "empty": None
}

normalized = normalize_json(data)
print(normalized)
# Output: {"a":1,"b":2}

Run:

python3 test_normalize.py

B. Test Hashing

# Create test file: test_hash.py
from compz.hash import hash_compliance, create_memo

data = {"repo_id": "test", "risk_score": 25.5}
hash_value = hash_compliance(data)
memo = create_memo(hash_value)

print(f"Hash: {hash_value}")
print(f"Memo: {memo}")
# Output: 
# Hash: 0x...
# Memo: compz:v1:0x...

Run:

python3 test_hash.py

C. Test Tampering Detection

cd examples
python3 tamper_detection_demo.py

Expected output:

Original Hash: 0x3f7a2b8c...
Tampered Hash: 0x9d1e5f6a...
❌ TAMPERING DETECTED!

Step 3: Test CLI Tools

Check Status

compz status

Expected output:

CompZ SDK Status
Version: 1.0.0
Mode: demo
Network: testnet

Test Anchor (Demo Mode)

cd examples
compz anchor compliance_result.json

Expected output:

πŸ“„ Loaded: compliance_result.json
πŸ“Š Size: 1234 bytes
πŸš€ Using CompZ Demo Mode (testnet)
πŸ“Š Normalized data: 1234 bytes
πŸ” Hash: 0xabc123...
βœ… Successfully anchored!
Hash: 0xabc123...
TXID: [txid]
Network: testnet
Mode: demo

Step 4: Real Blockchain Testing

Prerequisites Check

# Check Docker
docker --version
docker-compose --version

# Check disk space (need 100GB+)
df -h

# Check internet connection
ping -c 3 google.com

Start Zcash Node

# Start node
docker-compose up -d zcashd

# Check if running
docker ps

# View logs
docker logs -f compz-zcashd
# Press Ctrl+C to exit logs

Wait for Sync

# Check sync status
docker exec compz-zcashd zcash-cli -testnet getblockchaininfo

# Look for these fields:
# "blocks": 2800000,      <- Current block
# "headers": 2800000,     <- Target block
# When blocks == headers, sync is complete!

Sync times:

  • Testnet: 2-4 hours
  • Mainnet: 24-48 hours

Generate Z-Address

# Generate Sapling shielded address
docker exec compz-zcashd zcash-cli -testnet z_getnewaddress sapling

# Save output, looks like:
# ztestsapling1abc123def456...xyz789

Fund Your Address

  1. Visit: https://faucet.testnet.z.cash/
  2. Paste your z-address
  3. Complete CAPTCHA
  4. Click "Send"
  5. Wait 2-3 minutes

Check balance:

docker exec compz-zcashd zcash-cli -testnet z_getbalance "YOUR_ZADDR"
# Should show: 0.01 (or similar)

Configure Environment

# Copy example config
cp .env.example .env

# Edit .env file
nano .env
# Or use your preferred editor

Add these values:

ZCASH_RPC_URL=http://localhost:18232
ZCASH_RPC_USER=compz
ZCASH_RPC_PASS=compz_secure_password_change_this
ZCASH_DEFAULT_ADDRESS=ztestsapling1abc123...xyz789  # YOUR ADDRESS
ZCASH_TESTNET=true

Test Real Blockchain Integration

cd examples
python3 self_hosted_example.py

Expected output:

============================================================
CompZ SDK - Real Zcash Testnet Integration
============================================================

πŸ” Checking prerequisites...
βœ… All environment variables configured

============================================================
βœ… Self-Hosted Mode - Real Zcash Testnet
============================================================

βœ… Using self-hosted mode
🌐 Network: testnet
πŸ“Š Mode: self-hosted
...
πŸ“‘ Sending shielded transaction to Zcash testnet...
...
βœ… SUCCESS - Anchored to Blockchain!
πŸ” Hash: 0xabc123...
πŸ“ TXID: 9c8f7e6d5c4b3a2...
πŸ”— Explorer: https://explorer.testnet.z.cash/tx/9c8f7e6d...

βœ… VERIFICATION SUCCESSFUL

Step 5: Verify on Block Explorer

  1. Copy the TXID from output
  2. Visit: https://explorer.testnet.z.cash/
  3. Paste TXID in search
  4. You should see your transaction!

Note: The memo is encrypted in shielded transactions. Only you (with viewing key) can read it.


πŸ§ͺ Advanced Testing

Test 1: Verify Transaction Memo

# View transaction details (requires viewing key)
docker exec compz-zcashd zcash-cli -testnet z_viewtransaction YOUR_TXID

# Look for "memo" field in output
# Should contain: "636f6d707a3a76313a..." (hex-encoded "compz:v1:0x...")

Test 2: Verify Against Modified Data

# Create test file: test_verify.py
from compz import CompZClient
import json

client = CompZClient()

# Original data
original = {"repo_id": "test", "risk_score": 25.5}
result = client.anchor(original)

# Try to verify with original data
verify1 = client.verify(original, result.txid)
print(f"Original data: {verify1.valid}")  # Should be True

# Try to verify with modified data
modified = {"repo_id": "test", "risk_score": 5.0}  # Changed!
verify2 = client.verify(modified, result.txid)
print(f"Modified data: {verify2.valid}")  # Should be False

Test 3: CI/CD Integration

# Create test workflow: test_ci.sh
#!/bin/bash

echo "Running compliance scan..."
# Your scan tool here

echo "Anchoring to blockchain..."
compz anchor compliance.json -o proof.json

TXID=$(jq -r '.txid' proof.json)
echo "Proof TXID: $TXID"
echo "Share this TXID with auditors for verification"

πŸ“Š Testing Checklist

Basic Tests (No Blockchain)

  • Install SDK: pip install -e .
  • Run compz version
  • Test normalization: python3 test_normalize.py
  • Test hashing: python3 test_hash.py
  • Run tampering demo: python3 tamper_detection_demo.py
  • Test CLI status: compz status

Full Integration Tests (With Blockchain)

  • Docker installed and running
  • Start Zcash node: docker-compose up -d
  • Node synced: blocks == headers
  • Z-address generated
  • Address funded (>0.001 ZEC)
  • .env configured
  • Run self-hosted example
  • Transaction on block explorer
  • Verification successful

πŸ› Troubleshooting

Issue: "ModuleNotFoundError: No module named 'compz'"

Solution:

cd /Users/satyamsinghal/Desktop/Products/CompZ
pip install -e .

Issue: "Docker daemon not running"

Solution:

# Start Docker Desktop app
# Or on Linux:
sudo systemctl start docker

Issue: "Node not syncing"

Solution:

# Check peers
docker exec compz-zcashd zcash-cli -testnet getpeerinfo | grep addr

# Should show multiple peers
# If not, restart:
docker-compose restart zcashd

Issue: "Insufficient funds"

Solution:

# Check balance
docker exec compz-zcashd zcash-cli -testnet z_getbalance YOUR_ADDR

# If 0, get more from faucet:
# https://faucet.testnet.z.cash/

Issue: "Can't view memo"

Explanation: Memos are in shielded transactions. You need:

  1. The viewing key (automatic if you own the address)
  2. Use z_viewtransaction command
docker exec compz-zcashd zcash-cli -testnet z_viewtransaction TXID

Issue: "Demo mode not working"

Explanation: Demo gateway is not deployed yet. Use self-hosted mode for real testing.


🎯 Success Criteria

You know CompZ is working when:

  1. βœ… Normalization works: Same data always produces same JSON
  2. βœ… Hashing is deterministic: Same data always produces same hash
  3. βœ… Tampering detected: Modified data fails verification
  4. βœ… Transaction sent: Real TXID received
  5. βœ… On block explorer: Transaction visible on chain
  6. βœ… Verification passes: Original data matches on-chain hash
  7. βœ… CLI works: All commands execute successfully

πŸ“ Quick Reference

Common Commands

# Check status
compz status

# Anchor compliance data
compz anchor data.json

# Verify against blockchain
compz verify data.json TXID

# Check node status
docker exec compz-zcashd zcash-cli -testnet getinfo

# Check balance
docker exec compz-zcashd zcash-cli -testnet z_getbalance ADDR

# View logs
docker logs -f compz-zcashd

# Stop everything
docker-compose down

Python API

from compz import CompZClient

# Initialize client
client = CompZClient()  # Auto-detects mode

# Anchor data
result = client.anchor(compliance_data)
print(result.txid)

# Verify data
verified = client.verify(compliance_data, txid)
print(verified.valid)

# Check status
status = client.get_status()
print(status['mode'])

πŸš€ Next Steps

After testing:

  1. For Development:

    • Integrate into your CI/CD pipeline
    • Add to security scanning workflow
    • Automate compliance reporting
  2. For Production:

    • Switch to mainnet
    • Set up monitoring
    • Configure backups
  3. For Auditors:

    • Share TXIDs for verification
    • Provide verification instructions
    • Demonstrate immutability

πŸ’¬ Need Help?


You're ready to test! Start with Option 1 (instant test) and work your way up to real blockchain integration.