Skip to content

About

No description, website, or topics provided.

Resources

Stars

0 stars

Watchers

1 watching

Forks

Repository files navigation

Borrower CLI Test Server

A Rust server that runs test suites for the Borrower CLI tool.

Features

  • HTTP API for running tests
  • Test execution for Borrower CLI
  • Results tracking
  • Docker containerization
  • PostgreSQL database integration for persistent test results

Test Suite Steps

The test suite performs the following steps:

  1. Generate a new mnemonic and new receiving addresses for BTC and LavaUSD
  2. Call testnet faucet endpoints to receive BTC and LavaUSD
  3. Download and install the Borrower CLI
  4. Create a new loan
  5. Repay the loan
  6. Verify loan status and check JSON file

Getting Started

Prerequisites

  • Rust 1.5+ (for local development)
  • Docker and docker-compose (for containerized deployment)
  • PostgreSQL (optional, for database functionality)

Local Development

Clone the repository and run the server locally:

# Build the application
make build

# Run the application
make run

# Build and run with database support
make dev-db

Using Docker

Build and run using Docker:

# Build Docker image
make docker-build

# Run Docker container (includes PostgreSQL database)
make docker-run

# View logs
make docker-logs

# View database logs
make db-logs

# Connect to PostgreSQL database
make db-psql

API Endpoints

  • GET /health - Health check endpoint
  • POST /run-test - Start a test execution
  • GET /test-result/{test_id} - Get a specific test result
  • GET /test-results - Get all test results

Database Functionality

The application includes optional PostgreSQL database support for persistent storage of test results:

Features

  • Store test results in a PostgreSQL database
  • Retrieve specific test results by ID
  • Get all historical test results
  • Automatic table creation

Configuration

Set the following environment variables to configure the database:

DATABASE_URL=postgres://postgres:postgres@postgres:5432/borrowertests
FEATURES=database

When running with Docker Compose, these variables are set automatically.

Build with Database Support

To build and run with database support:

# Local development with database
make run-with-db

# Run tests with database support
make test-with-db

Known Issues and Mitigations

During development and testing, we encountered several challenges that differed from the expected behavior described in the assignment:

Faucet API Issues

  • BTC Faucet Unavailability: The Lava.xyz testnet faucet endpoint has been inconsistent. According to Lava's documentation, their testnet faucet has been paused. Our implementation handles this gracefully by:

    • Adding robust error handling for API unavailability
    • Logging detailed error messages
    • Continuing with the test process when possible, marking steps as skipped when external services fail
  • API Response Format Changes: The faucet API response format has changed from the documentation. Our code includes:

    • Flexible parsing of API responses
    • Fallback mechanisms for handling unexpected response formats
    • Comprehensive logging of response parsing issues

CLI Tool Interaction

  • CLI Output Variability: The output from the Borrower CLI tool sometimes differs from expected patterns. We've implemented:
    • Resilient regex patterns that can handle variations in output format
    • Fallback methods for extracting contract IDs
    • Verbose logging to track execution flow

Network Dependencies

  • External Service Dependencies: The test process relies on multiple external services that may be unavailable or slow. Our solution:
    • Implements timeouts for all external requests
    • Provides clear error messages for dependency failures
    • Includes a comprehensive test suite with mocked dependencies to verify code correctness

Testing

Run tests:

# Run all tests
make test

# Run tests with database support
make test-with-db

# Run a specific test
make test-one TEST=test_name

License

MIT

Contributing

  1. Fork the repository
  2. Create a feature branch
  3. Submit a pull request

About

No description, website, or topics provided.

Resources

Stars

0 stars

Watchers

1 watching

Forks

Releases

Packages

Used by

Contributors

Languages