xatu-cbt

module
v0.0.0-...-249e40d Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: Jun 11, 2026 License: MIT

README

xatu-cbt

This repo contains the clickhouse migrations and the models for CBT on xatu data.

Documentation

Getting Started

Create a .env file:

cp example.env .env

Example .env file:

# Network configuration (REQUIRED - used for container suffixes)
NETWORK=mainnet

# ClickHouse configuration
CLICKHOUSE_HOST=localhost
CLICKHOUSE_NATIVE_PORT=9000
CLICKHOUSE_USERNAME=default
CLICKHOUSE_PASSWORD=
CLICKHOUSE_CLUSTER={cluster}

# Xatu configuration
XATU_REF=master # what xatu repo ref to use for testing

# Logging configuration
LOG_LEVEL=debug # debug, info, warn, error
Using Custom Environment Files

Use the --env flag to load a different environment file:

# CLI mode
./bin/xatu-cbt --env .env.production show-config

# TUI mode
./bin/xatu-cbt --env=.env.production
Usage
Interactive TUI Mode

Simply run the binary without arguments to enter interactive mode:

# use the makefile to build and run the binary
make

# or manually
go build -o ./bin/xatu-cbt ./cmd/xatu-cbt
./bin/xatu-cbt
CLI Commands
Network Commands

These commands will setup cbt admin tables, go-migrate schemas tables and run the migrations relevant for the configured network. You can also teardown the network database.

Note: this can be used against local clickhouse or a remote staging/production clickhouse.

# Setup network database (creates tables and migrations)
./bin/xatu-cbt network setup [--force]

# Teardown network database (truncates tables, preserves structure)
./bin/xatu-cbt network teardown [--force]

Infrastructure Management

The platform provides a persistent ClickHouse cluster infrastructure shared between development and testing.

Starting Infrastructure

Before running tests or development work, start the platform infrastructure:

# Start ClickHouse cluster, ClickHouse Keeper, and Redis
./bin/xatu-cbt infra start

This starts:

  • Refined ClickHouse cluster cluster_2S_1R: 2 nodes / 2 shards x 1 replica. Sharded so cross-shard issues — e.g. a distributed IN/JOIN missing GLOBAL — surface locally, without a 2nd replica per shard (which doubles ON CLUSTER DDL cost and slows the test suite)
  • 3-node ClickHouse Keeper ensemble for cluster coordination (replaces ZooKeeper)
  • Raw ClickHouse cluster xatu_cluster (external data source): 2 nodes / 2 shards x 1 replica, started in local xatu mode
  • Redis for state management
  • Shared across both ephemeral test databases and persistent network databases
Managing Infrastructure
# Check status
./bin/xatu-cbt infra status

# Detailed status with container info
./bin/xatu-cbt infra status --verbose

# Stop infrastructure (cleans up test databases)
./bin/xatu-cbt infra stop

# Stop without cleaning up test databases
./bin/xatu-cbt infra stop --cleanup-test-dbs=false

# Reset completely (removes all volumes)
./bin/xatu-cbt infra reset

The infra reset command is useful when:

  • Testing fresh xatu migrations
  • Disk space is low
  • You need a complete clean slate

Running Tests

Prerequisites
  1. Start infrastructure: ./bin/xatu-cbt infra start
  2. Ensure .env file is configured (see Getting Started)
Test Execution
# Run tests for a specific spec/network combination
./bin/xatu-cbt test spec --spec pectra --network mainnet

# Run with verbose output
./bin/xatu-cbt test spec --spec pectra --network mainnet --verbose

# Run fusaka tests on sepolia
./bin/xatu-cbt test spec --spec fusaka --network sepolia

Tests use ephemeral databases (e.g., test_mainnet_pectra_*) that are automatically managed.

Test Structure

Tests are organized by network and spec:

tests/
├── mainnet/
│   └── pectra/
│       └── models/                # Model definitions with embedded config
│           ├── canonical_beacon_block.yaml
│           └── fct_block.yaml
└── sepolia/
    └── fusaka/
        └── models/
            └── ...

Each model file contains:

  • data: Parquet file paths and row count expectations
  • sql: Transformation query (if transformation model)
  • assertions: SQL queries to validate results
CI/CD Integration

GitHub Actions automatically tests each spec/network combination:

# Workflow steps
cp example.env .env
mkdir -p .parquet_cache
./bin/xatu-cbt infra start
./bin/xatu-cbt test spec --spec pectra --network mainnet --verbose
./bin/xatu-cbt infra stop
Protobuf Generation

When adding or modifying transformation models, you must generate corresponding protobuf files:

# Generate protobuf files for all transformation models
make proto

When to run make proto:

  • After adding a new transformation model (.sql file in models/transformations/)
  • After modifying the schema or columns of an existing transformation model
  • Before committing changes to transformation models

The generated protobuf files in pkg/proto/clickhouse/ are used by CBT for type safety and schema validation. Each transformation model must have corresponding .proto, .go, and .pb.go files.

Directories

Path Synopsis
cmd
Package cmd contains CLI command definitions
Package cmd contains CLI command definitions
xatu-cbt command
Package main is the entry point for the xatu-cbt application
Package main is the entry point for the xatu-cbt application
internal
actions
Package actions contains the core business logic for xatu-cbt operations
Package actions contains the core business logic for xatu-cbt operations
clickhouse
Package clickhouse provides ClickHouse database connection and management utilities.
Package clickhouse provides ClickHouse database connection and management utilities.
config
Package config handles configuration loading and management
Package config handles configuration loading and management
infra
Package infra provides infrastructure management for Docker and ClickHouse clusters.
Package infra provides infrastructure management for Docker and ClickHouse clusters.
interactive
Package interactive provides terminal user interface components
Package interactive provides terminal user interface components
migrations
Package migrations handles database schema migrations
Package migrations handles database schema migrations
testing
Package testing provides end-to-end test orchestration and execution.
Package testing provides end-to-end test orchestration and execution.
testing/assertion
Package assertion provides SQL assertion execution for validating test results.
Package assertion provides SQL assertion execution for validating test results.
testing/memfs
Package memfs provides a simple in-memory filesystem implementation for migration files.
Package memfs provides a simple in-memory filesystem implementation for migration files.
testing/output
Package output provides formatted console output for test results.
Package output provides formatted console output for test results.
testing/testdef
Package testdef provides test definition loading and validation.
Package testdef provides test definition loading and validation.
pkg

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL