Building and Testing
This document provides a comprehensive guide to building and testing the Ava SDK JS repository.
This document provides a comprehensive guide to building and testing the Ava SDK JS repository. It covers development environment setup, building the SDK, and running tests to verify functionality. For information about the overall architecture and design of the SDK, see SDK Architecture.
1. Development Environment Setup#
1.1 Prerequisites#
Before working with the Ava SDK JS repository, ensure you have the following tools installed:
These version requirements are specified in the repository's package.json
:
Sources:
1.2 Environment Variables#
The SDK requires specific environment variables for development and testing. Create appropriate environment files based on the provided template:
Environment File | Purpose | Required Variables |
---|---|---|
.env | Development | DEV_API_KEY , POSTGRES_URL |
.env.test | Testing | TEST_API_KEY , TEST_PRIVATE_KEY , ENDPOINT , CHAIN_ENDPOINT |
Sources:
1.3 Repository Structure#
The Ava SDK JS repository follows a monorepo structure:
Sources:
2. Building the SDK#
2.1 Install Dependencies#
After cloning the repository, install dependencies using Yarn:
2.2 Build Process#
The build process compiles TypeScript source files across all packages:
The main build command is defined in the repository's root package.json
:
Sources:
2.3 gRPC Code Generation#
The SDK communicates with the AVS service using gRPC. The protocol buffer (protobuf) definitions and generated code are managed with these commands:
Sources:
3. Testing#
3.1 Test Framework#
The repository uses Jest as its testing framework:
The Jest configuration specifies the test environment, file patterns, and module mappings:
Sources:
3.2 Test Structure#
The tests are organized by functionality, with each test file focusing on a specific feature:
Test File | Purpose |
---|---|
auth.test.ts | Authentication functionality |
createWorkflow.test.ts | Workflow creation |
getWorkflow.test.ts | Retrieving specific workflow |
getWorkflows.test.ts | Retrieving multiple workflows |
cancelWorkflow.test.ts | Workflow cancellation |
deleteWorkflow.test.ts | Workflow deletion |
getExecution.test.ts | Execution retrieval |
getExecutions.test.ts | Multiple executions retrieval |
getWallet.test.ts | Smart wallet retrieval |
getWallets.test.ts | Multiple wallets retrieval |
secret.test.ts | Secret management |
Sources:
3.3 Running Tests#
The repository provides various commands for running tests:
Sources:
3.4 Docker-based Testing#
For integration testing with a local AVS service, the repository provides Docker-based testing:
The command for generating an API key for testing is defined in the root package.json
:
Sources:
4. Continuous Integration#
4.1 GitHub Actions Workflows#
The repository uses GitHub Actions for CI/CD, with two main workflows:
dev-test-on-pr.yml
: Runs on all PRs using a local Docker AVS instancestaging-test-on-pr.yml
: Runs on PRs to the main branch using a staging AVS
Sources:
4.2 Test Execution Flow#
The CI workflows follow this sequence:
Sources:
4.3 Test Utilities#
The repository includes test utilities in tests/utils.ts
that provide functions for test setup, execution, and cleanup:
Function | Purpose |
---|---|
generateSignature | Creates a signed message for authentication |
generateAuthPayloadWithApiKey | Generates API key authentication payload |
requireEnvVar | Ensures required environment variables are set |
queueForRemoval | Tracks resources for cleanup |
removeCreatedWorkflows | Removes workflows created during tests |
cleanupWorkflows | Cleans up all workflows for a wallet |
compareResults | Verifies workflow properties |
Sources:
5. Cleaning Up Resources#
Test execution creates resources that should be properly cleaned up:
The tests/utils.ts
file includes functions for tracking and cleaning up resources:
Sources:
Conclusion#
This document has covered the essential information for building and testing the Ava SDK JS repository. Following these instructions will help you set up your development environment, build the SDK components, and run tests to verify functionality.
For information about using the SDK in your applications, see Usage Examples. For details about the SDK architecture and components, see SDK Architecture.
Sources: