Skip to content

Testing Environment Setup

O edited this page Dec 23, 2025 · 1 revision

O Blockchain Testing Environment Setup Guide

This guide helps you set up a comprehensive testing environment for O Blockchain features:

  • Invites - Measurement invitation system
  • Measurements - Water price and exchange rate submissions
  • Transactions - Regular blockchain transactions
  • Stability Mining - Currency stability detection and rewards

Quick Start

1. Start the Node

# Start O Blockchain node in regtest mode
./build/bin/bitcoind -regtest -daemon

# Wait for node to be ready
./build/bin/bitcoin-cli -regtest getblockchaininfo

2. Set Up Test Environment

# Use the setup helper
python3 test_o_setup_helper.py setup

# Or manually:
./build/bin/bitcoin-cli -regtest createwallet "test_wallet"
./build/bin/bitcoin-cli -regtest generatetoaddress 101 $(./build/bin/bitcoin-cli -regtest getnewaddress)

3. Run Comprehensive Integration Tests

# Run the complete integration test
./build/test/functional/test_runner.py test_o_integration_complete

# Or run directly
python3 test/functional/test_o_integration_complete.py

Testing Individual Features

Test Invites

# Quick test
python3 test_o_setup_helper.py test-invites

# Check active invites
./build/bin/bitcoin-cli -regtest getactiveinvites

# Check measurement statistics
./build/bin/bitcoin-cli -regtest getmeasurementstatistics

# Generate blocks to trigger automatic invites (every 10 blocks)
./build/bin/bitcoin-cli -regtest generatetoaddress 10 $(./build/bin/bitcoin-cli -regtest getnewaddress)

Test Measurements

# Quick test
python3 test_o_setup_helper.py test-measurements

# Check if you have active invites first
./build/bin/bitcoin-cli -regtest getactiveinvites

# Submit a water price measurement (requires invite_id)
./build/bin/bitcoin-cli -regtest submitwaterpricetx "USD" 150 "invite_id_hex" "url" "https://example.com/water"

# Submit an exchange rate measurement
./build/bin/bitcoin-cli -regtest submitexchangeratetx "USD" "EUR" 9200 "invite_id_hex" "url" "https://example.com/rate"

# Check measurement statistics
./build/bin/bitcoin-cli -regtest getmeasurementstatistics

Test Transactions

# Quick test
python3 test_o_setup_helper.py test-transactions

# Generate blocks for maturity
./build/bin/bitcoin-cli -regtest generatetoaddress 101 $(./build/bin/bitcoin-cli -regtest getnewaddress)

# Get balance
./build/bin/bitcoin-cli -regtest getbalance

# Send transaction
./build/bin/bitcoin-cli -regtest sendtoaddress "o1..." 10.0

# Generate block to confirm
./build/bin/bitcoin-cli -regtest generatetoaddress 1 $(./build/bin/bitcoin-cli -regtest getnewaddress)

Test Stability Mining

# Quick test
python3 test_o_setup_helper.py test-stability

# Check stabilization statistics
./build/bin/bitcoin-cli -regtest getstabilizationstats

# Check integration status
./build/bin/bitcoin-cli -regtest getstabilizationintegrationstatus

# Check consensus statistics
./build/bin/bitcoin-cli -regtest getstabilizationconsensusstats

# Check unstable currencies
./build/bin/bitcoin-cli -regtest getstabilizationcoinstats

# Generate blocks (stability mining checks happen during block processing)
./build/bin/bitcoin-cli -regtest generatetoaddress 20 $(./build/bin/bitcoin-cli -regtest getnewaddress)

Complete Test Workflow

Step 1: Setup Environment

# 1. Start node
./build/bin/bitcoind -regtest -daemon

# 2. Create wallet
./build/bin/bitcoin-cli -regtest createwallet "test"

# 3. Generate blocks to maturity
python3 test_o_setup_helper.py setup

Step 2: Test Invites

# Check initial state
./build/bin/bitcoin-cli -regtest getactiveinvites
./build/bin/bitcoin-cli -regtest getmeasurementstatistics

# Generate blocks to trigger automatic invites (every 10 blocks)
current_height=$(./build/bin/bitcoin-cli -regtest getblockcount | jq -r '.blocks')
next_10=$(( (($current_height / 10) + 1) * 10 ))
blocks_needed=$(( $next_10 - $current_height ))
./build/bin/bitcoin-cli -regtest generatetoaddress $blocks_needed $(./build/bin/bitcoin-cli -regtest getnewaddress)

# Check for new invites
./build/bin/bitcoin-cli -regtest getactiveinvites

Step 3: Test Measurements

# Get an active invite
invites=$(./build/bin/bitcoin-cli -regtest getactiveinvites)
invite_id=$(echo $invites | jq -r '.[0].invite_id' 2>/dev/null || echo "")

if [ -n "$invite_id" ] && [ "$invite_id" != "null" ]; then
    # Submit water price measurement
    ./build/bin/bitcoin-cli -regtest submitwaterpricetx "USD" 150 "$invite_id" "url" "https://example.com/water"
    
    # Submit exchange rate measurement
    ./build/bin/bitcoin-cli -regtest submitexchangeratetx "USD" "EUR" 9200 "$invite_id" "url" "https://example.com/rate"
    
    # Mine blocks to include transactions
    ./build/bin/bitcoin-cli -regtest generatetoaddress 1 $(./build/bin/bitcoin-cli -regtest getnewaddress)
    
    # Check statistics
    ./build/bin/bitcoin-cli -regtest getmeasurementstatistics
else
    echo "No active invites available (may need verified users)"
fi

Step 4: Test Stability Mining

# Check current stability status
./build/bin/bitcoin-cli -regtest getstabilizationstats
./build/bin/bitcoin-cli -regtest getstabilizationconsensusstats

# Generate blocks to trigger stability checks
./build/bin/bitcoin-cli -regtest generatetoaddress 20 $(./build/bin/bitcoin-cli -regtest getnewaddress)

# Check if stability mining created rewards
./build/bin/bitcoin-cli -regtest getstabilizationstats
./build/bin/bitcoin-cli -regtest getstabilizationcoinstats

Test Scripts

Helper Script

The test_o_setup_helper.py script provides easy testing:

# Setup environment
python3 test_o_setup_helper.py setup

# Test individual features
python3 test_o_setup_helper.py test-invites
python3 test_o_setup_helper.py test-measurements
python3 test_o_setup_helper.py test-transactions
python3 test_o_setup_helper.py test-stability

# Run all tests
python3 test_o_setup_helper.py test-all

Functional Tests

Run comprehensive functional tests:

# Run complete integration test
./build/test/functional/test_runner.py test_o_integration_complete

# Run specific test suites
./build/test/functional/test_runner.py test_o_databases
./build/test/functional/test_runner.py test_o_blockchain_sync
./build/test/functional/test_runner.py test_o_features_and_performance

# Run all O-specific tests
./build/test/functional/test_runner.py test_o_*

Testing Prerequisites

What You Need

  1. Verified Users (for invites to work properly)

    • Invites require verified users to be available
    • May need to create user verification transactions first
  2. Active Invites (for submitting measurements)

    • Invites are created automatically every 10 blocks
    • Or can be created manually via RPC
  3. Sufficient Blocks (for stability mining)

    • Stability checks happen during block processing
    • Need blocks with measurement data for stability mining to trigger

Common Issues

No Active Invites:

  • Solution: Generate more blocks (invites created every 10 blocks)
  • May need verified users first

Cannot Submit Measurements:

  • Solution: Get an active invite first via getactiveinvites
  • Use the invite_id in measurement submission

Stability Mining Not Triggering:

  • Solution: Need unstable currencies (requires measurement data)
  • Generate more blocks after submitting measurements

Transactions Failing:

  • Solution: Ensure you have mature coins (101+ blocks after generation)
  • Check balance with getbalance

Monitoring Tests

Watch Debug Logs

# Tail debug log in real-time
tail -f ~/.bitcoin/regtest/debug.log

# Filter for O-specific logs
tail -f ~/.bitcoin/regtest/debug.log | grep -i "O "

# Filter for specific features
tail -f ~/.bitcoin/regtest/debug.log | grep -i "measurement"
tail -f ~/.bitcoin/regtest/debug.log | grep -i "stabilization"
tail -f ~/.bitcoin/regtest/debug.log | grep -i "invite"

Check Database Files

# Check database directories
ls -la ~/.bitcoin/regtest/brightid_users/
ls -la ~/.bitcoin/regtest/measurements/
ls -la ~/.bitcoin/regtest/business_miners/

# Check database sizes
du -sh ~/.bitcoin/regtest/brightid_users/
du -sh ~/.bitcoin/regtest/measurements/
du -sh ~/.bitcoin/regtest/business_miners/

Test Checklist

Use this checklist to verify all features are working:

  • Node starts and connects
  • Databases are initialized (3 LevelDB databases)
  • Wallets can be created
  • Blocks can be generated
  • Invites appear after block generation (every 10 blocks)
  • Measurements can be submitted (with valid invite)
  • Measurements appear in statistics
  • Regular transactions work
  • Stability mining statistics are available
  • Multi-node sync works (if testing with multiple nodes)

Next Steps

After basic testing works:

  1. Test with multiple nodes - Set up network of 2+ nodes
  2. Test measurement validation - Submit measurements and validate them
  3. Test stability edge cases - Create scenarios with unstable currencies
  4. Performance testing - Test with many measurements and transactions
  5. Stress testing - Test system under load

Troubleshooting

Node won't start

  • Check if already running: ps aux | grep bitcoind
  • Check port availability: lsof -i :18444
  • Check data directory permissions

RPC calls fail

  • Ensure node is running: getblockchaininfo
  • Check wallet is loaded: listwallets
  • Check debug logs for errors

Tests show warnings

  • Some features may be under development
  • Check if RPC commands are registered: help <command>
  • Review debug logs for more details

Quick Reference: Run python3 test_o_setup_helper.py test-all for a complete test overview.

Clone this wiki locally