Skip to content
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
128 changes: 115 additions & 13 deletions test-suite/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -30,29 +30,131 @@ KMS can be configured to two modes:
The test suite offers a unified CLI for all operations:

```sh

cd test-suite/fhevm

# Deploy the entire stack
./fhevm-cli deploy
# WIP: Build images locally (when private registry not available)
./fhevm-cli deploy --build

# Run specific tests
./fhevm-cli test input-proof
# Trivial
./fhevm-cli test user-decryption
# Trivial
./fhevm-cli test public-decryption
./fhevm-cli test erc20

# Upgrade a specific service
# Run blockchain integration tests
./fhevm-cli test input-proof # Test input proofs
./fhevm-cli test user-decryption # Test user decryptions
./fhevm-cli test public-decryption # Test public decryptions
./fhevm-cli test erc20 # Test ERC20 operations
./fhevm-cli test debug # Debug mode testing

# Database connector testing (runs gateway-stress via fhevm-cli wrapper)
./fhevm-cli db-test --track-responses # Test with all DB URLs from config
./fhevm-cli db-test --duration 60s -t mixed # Run for 60s with mixed requests
./fhevm-cli db-test -b 100 --clear-db # Batch size 100, clear DB first

# Upgrade specific services
./fhevm-cli upgrade host
./fhevm-cli upgrade gateway
./fhevm-cli upgrade connector
./fhevm-cli upgrade coprocessor
./fhevm-cli upgrade relayer
./fhevm-cli upgrade test-suite

# View logs
./fhevm-cli logs relayer
# View logs for any service
./fhevm-cli logs [SERVICE]

# Clean up
# Clean up all containers and volumes
./fhevm-cli clean
```

### Database Connector Testing

The `fhevm-cli db-test` command provides database-level stress testing:

```sh
# Implemented options:
-n, --num-connectors NUM # Number of DB URLs to use from config
-t, --type TYPE # Request type: public, user, or mixed
-b, --batch-size SIZE # Requests per batch
--duration TIME # Test duration (e.g., 30s, 5m, 1h)
-i, --interval TIME # Batch interval (e.g., 1s, 500ms, 2s)
-c, --config FILE # Path to custom config file
--track-responses # Enable response tracking
--clear-db # Clear DB tables before test

# Examples:
./fhevm-cli db-test --clear-db --track-responses # Clear DB, then test with tracking
./fhevm-cli db-test -n 2 -t mixed # Test 2 DBs with mixed requests
./fhevm-cli db-test --duration 60s -i 500ms # 60s test, 500ms intervals
./fhevm-cli db-test -c custom.toml -b 100 --clear-db # Custom config, clear DB, batch 100

# Default config: test-suite/gateway-stress/config/config.toml
```

### Advanced Gateway Stress Testing

For more control, use the standalone `gateway-stress` tool directly (in `test-suite/gateway-stress`):

1. **Blockchain-based testing** - Sends actual transactions through the blockchain
2. **Database-level testing** - Directly inserts requests into PostgreSQL for focused DB testing

#### Blockchain-based Testing
Sends decryption requests through the blockchain (requires deployed contracts):

```sh
cd test-suite/gateway-stress

# Build the tool first
cargo build --release

# Send public decryption transactions
./target/release/gateway-stress public

# Send user decryption transactions
./target/release/gateway-stress user

# Note: 'mixed' mode is not yet implemented
```

#### Database-level Testing
Bypasses blockchain and directly inserts into PostgreSQL databases:

```sh
cd test-suite/gateway-stress

# Build the tool
cargo build --release

# Basic database test with default settings from config
./target/release/gateway-stress db-connector

# Override test duration and request type
./target/release/gateway-stress db-connector --duration 60s --request-type public

# Enable response tracking to verify sync across databases
./target/release/gateway-stress db-connector --track-responses --batch-size 1000

# Use custom configuration
./target/release/gateway-stress --config custom-config.toml db-connector
```

#### Prerequisites
- Rust toolchain (for building gateway-stress)
- For blockchain testing: Deployed FHEVM contracts and configured ct_handles
- For database testing: Running PostgreSQL with credentials in `config/config.toml`

#### DB Connector Options
- `--request-type <TYPE>` - Request type: `public`, `user`, or `mixed`
- `--duration <TIME>` - Test duration (e.g., `30s`, `5m`, `1h`)
- `--batch-size <NUM>` - Requests per batch (for load control)
- `--track-responses` - Monitor response processing and sync status

#### Configuration File
The tool reads from a TOML configuration file (default: `config/config.toml`):
- Database connection strings
- Batch intervals and sizes
- Connection pool settings
- Request generation parameters

See `gateway-stress/README.md` for detailed configuration examples.

### WIP - Forcing Local Builds (`--build`)

⚠️ **IMPORTANT: THIS FEATURE IS STILL A WORK IN PROGRESS!** ⚠️
Expand Down
25 changes: 25 additions & 0 deletions test-suite/fhevm/docker-compose/test-suite-docker-compose.yml
Original file line number Diff line number Diff line change
Expand Up @@ -14,3 +14,28 @@ services:
- ../env/staging/.env.test-suite.local
command:
- tail -f /dev/null

# Gateway stress test with db-connector subcommand
gateway-stress-db:
container_name: fhevm-gateway-stress-db
image: ghcr.io/zama-ai/fhevm/gateway-stress:${TEST_SUITE_VERSION}
build:
context: ../../..
dockerfile: test-suite/gateway-stress/Dockerfile
env_file:
- ../env/staging/.env.connector.local # Reuse connector env for DB connection
environment:
RUST_LOG: ${RUST_LOG:-gateway_stress=info}
command:
- db-connector
- --connectors
- "${DB_TEST_CONNECTORS:-1}"
- --track-responses
- --duration
- "${DB_TEST_DURATION:-30s}"
- --batch-size
- "${DB_TEST_BATCH:-10}"
- --request-type
- "${DB_TEST_TYPE:-mixed}"
profiles:
- db-test
136 changes: 136 additions & 0 deletions test-suite/fhevm/fhevm-cli
Original file line number Diff line number Diff line change
Expand Up @@ -51,6 +51,7 @@ function usage {
echo -e "${BOLD}${LIGHT_BLUE}Commands:${RESET}"
echo -e " ${YELLOW}deploy${RESET} ${CYAN}[--build]${RESET} WIP: Deploy the full fhevm stack (optionally rebuild images)"
echo -e " ${YELLOW}test${RESET} ${CYAN}[TYPE]${RESET} Run tests (input-proof|user-decryption|public-decryption|erc20|debug)"
echo -e " ${YELLOW}db-test${RESET} ${CYAN}[OPTIONS]${RESET} Test N database connectors with direct insertions"
echo -e " ${YELLOW}upgrade${RESET} ${CYAN}[SERVICE]${RESET} Upgrade specific service (host|gateway|connector|coprocessor|relayer|test-suite)"
echo -e " ${YELLOW}clean${RESET} Remove all containers and volumes"
echo -e " ${YELLOW}logs${RESET} ${CYAN}[SERVICE]${RESET} View logs for a specific service"
Expand All @@ -69,6 +70,7 @@ function usage {
echo -e " ${PURPLE}./fhevm-cli test user-decryption ${RESET}"
echo -e " ${PURPLE}./fhevm-cli test public-decryption -n staging${RESET}"
echo -e " ${PURPLE}./fhevm-cli test erc20${RESET}"
echo -e " ${PURPLE}./fhevm-cli db-test -n 3 --track-responses${RESET}"
echo -e " ${PURPLE}./fhevm-cli upgrade coprocessor${RESET}"
echo -e "${BLUE}============================================================${RESET}"
}
Expand Down Expand Up @@ -209,6 +211,140 @@ case $COMMAND in
fi
;;

db-test)
print_logo
echo -e "${LIGHT_BLUE}${BOLD}[DB-TEST] Running DB Connector Test...${RESET}"

# Check if running with docker-compose or locally
USE_DOCKER=false
USE_LOCAL=false

# Parse first argument to determine mode
if [[ "$1" == "--docker" ]] || [[ "$1" == "-d" ]]; then
USE_DOCKER=true
shift
elif [[ "$1" == "--local" ]] || [[ "$1" == "-l" ]]; then
USE_LOCAL=true
shift
else
# Default to docker if stack is running
if docker ps | grep -q "kms-connector-db"; then
USE_DOCKER=true
echo -e "${YELLOW}[INFO] Detected running docker stack, using docker mode${RESET}"
else
USE_LOCAL=true
echo -e "${YELLOW}[INFO] No docker stack detected, using local mode${RESET}"
fi
fi

if [ "$USE_DOCKER" = true ]; then
# Run using docker-compose
echo -e "${BLUE}[INFO] Running DB test in Docker environment${RESET}"

# Build environment variables for docker-compose
COMPOSE_ENV=""
while (( "$#" )); do
case "$1" in
-n|--connectors)
COMPOSE_ENV="$COMPOSE_ENV DB_TEST_CONNECTORS=$2"
shift 2
;;
--duration)
COMPOSE_ENV="$COMPOSE_ENV DB_TEST_DURATION=$2"
shift 2
;;
-b|--batch-size)
COMPOSE_ENV="$COMPOSE_ENV DB_TEST_BATCH=$2"
shift 2
;;
-t|--type)
COMPOSE_ENV="$COMPOSE_ENV DB_TEST_TYPE=$2"
shift 2
;;
*)
shift
;;
esac
done

# Run the test service using existing test-suite docker-compose
eval "$COMPOSE_ENV docker compose -p fhevm -f ${SCRIPT_DIR}/docker-compose/test-suite-docker-compose.yml --profile db-test run --rm gateway-stress-db"
else
# Run locally with cargo
GATEWAY_STRESS_DIR="${SCRIPT_DIR}/../gateway-stress"

if [ ! -d "$GATEWAY_STRESS_DIR" ]; then
echo -e "${RED}[ERROR]${RESET} ${BOLD}gateway-stress directory not found at: $GATEWAY_STRESS_DIR${RESET}"
exit 1
fi

cd "$GATEWAY_STRESS_DIR"
CMD="cargo run -- db-connector"

# Parse arguments for db-test
while (( "$#" )); do
case "$1" in
-n|--num-connectors)
CMD="$CMD --num-connectors $2"
shift 2
;;
-t|--type)
CMD="$CMD --request-type $2"
shift 2
;;
-b|--batch-size)
CMD="$CMD --batch-size $2"
shift 2
;;
--duration)
CMD="$CMD --duration $2"
shift 2
;;
-i|--interval)
CMD="$CMD --interval $2"
shift 2
;;
-c|--config)
CMD="$CMD --config $2"
shift 2
;;
--track-responses)
CMD="$CMD --track-responses"
shift
;;
--clear-db)
CMD="$CMD --clear-db"
shift
;;
*)
echo -e "${RED}[ERROR]${RESET} ${BOLD}Unknown option: $1${RESET}"
echo ""
echo -e "${BOLD}DB-Test Options:${RESET}"
echo -e " ${CYAN}-n, --num-connectors NUM${RESET} Number of DB URLs to use"
echo -e " ${CYAN}-t, --type TYPE${RESET} Request type: public, user, or mixed"
echo -e " ${CYAN}-b, --batch-size SIZE${RESET} Requests per batch"
echo -e " ${CYAN}--duration TIME${RESET} Test duration (e.g., 30s, 5m)"
echo -e " ${CYAN}-i, --interval TIME${RESET} Batch interval (e.g., 1s, 500ms)"
echo -e " ${CYAN}-c, --config FILE${RESET} Path to config file"
echo -e " ${CYAN}--track-responses${RESET} Enable response tracking"
echo -e " ${CYAN}--clear-db${RESET} Clear DB tables before test"
exit 1
;;
esac
done

echo -e "${YELLOW}Executing: $CMD${RESET}"
eval $CMD

if [ $? -eq 0 ]; then
echo -e "${GREEN}${BOLD}[SUCCESS] DB Connector Test completed successfully!${RESET}"
else
echo -e "${RED}${BOLD}[FAILURE] DB Connector Test failed${RESET}"
exit 1
fi
fi
;;

help|-h|--help)
usage
exit 0
Expand Down
Loading