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 FilePurposeRequired Variables
.envDevelopmentDEV_API_KEY, POSTGRES_URL
.env.testTestingTEST_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 FilePurpose
auth.test.tsAuthentication functionality
createWorkflow.test.tsWorkflow creation
getWorkflow.test.tsRetrieving specific workflow
getWorkflows.test.tsRetrieving multiple workflows
cancelWorkflow.test.tsWorkflow cancellation
deleteWorkflow.test.tsWorkflow deletion
getExecution.test.tsExecution retrieval
getExecutions.test.tsMultiple executions retrieval
getWallet.test.tsSmart wallet retrieval
getWallets.test.tsMultiple wallets retrieval
secret.test.tsSecret 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:

  1. dev-test-on-pr.yml: Runs on all PRs using a local Docker AVS instance
  2. staging-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:

FunctionPurpose
generateSignatureCreates a signed message for authentication
generateAuthPayloadWithApiKeyGenerates API key authentication payload
requireEnvVarEnsures required environment variables are set
queueForRemovalTracks resources for cleanup
removeCreatedWorkflowsRemoves workflows created during tests
cleanupWorkflowsCleans up all workflows for a wallet
compareResultsVerifies 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: