A Rust server that runs test suites for the Borrower CLI tool.
- HTTP API for running tests
- Test execution for Borrower CLI
- Results tracking
- Docker containerization
- PostgreSQL database integration for persistent test results
The test suite performs the following steps:
- Generate a new mnemonic and new receiving addresses for BTC and LavaUSD
- Call testnet faucet endpoints to receive BTC and LavaUSD
- Download and install the Borrower CLI
- Create a new loan
- Repay the loan
- Verify loan status and check JSON file
- Rust 1.5+ (for local development)
- Docker and docker-compose (for containerized deployment)
- PostgreSQL (optional, for database functionality)
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-dbBuild 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-psqlGET /health- Health check endpointPOST /run-test- Start a test executionGET /test-result/{test_id}- Get a specific test resultGET /test-results- Get all test results
The application includes optional PostgreSQL database support for persistent storage of test results:
- Store test results in a PostgreSQL database
- Retrieve specific test results by ID
- Get all historical test results
- Automatic table creation
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.
To build and run with database support:
# Local development with database
make run-with-db
# Run tests with database support
make test-with-dbDuring development and testing, we encountered several challenges that differed from the expected behavior described in the assignment:
-
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 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
- 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
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_nameMIT
- Fork the repository
- Create a feature branch
- Submit a pull request