@@ -71,6 +71,121 @@ PRIVY_APP_ID=your_app_id
7171PRIVY_APP_SECRET=your_app_secret
7272```
7373
74+ ## Testing
75+
76+ This project includes comprehensive test coverage across multiple levels:
77+
78+ ### Test Categories
79+
80+ - ** Unit Tests** : Located in ` src/ ` files using ` #[cfg(test)] ` modules
81+ - ** Integration Tests** : End-to-end tests in ` tests/ ` directory
82+ - ** Example Tests** : Runnable examples in ` examples/ ` directory
83+
84+ ### Environment Setup for Testing
85+
86+ #### Staging Environment Variables
87+
88+ For end-to-end tests, configure these environment variables:
89+
90+ ``` bash
91+ # Required for all E2E tests
92+ export STAGING_APP_ID=" your_staging_app_id"
93+ export STAGING_APP_SECRET=" your_staging_app_secret"
94+ export STAGING_URL=" https://api.privy.io" # Optional, defaults to production
95+
96+ # Optional for specific test types
97+ export STAGING_JWT=" your_test_jwt_token" # JWT authentication tests
98+ export STAGING_WALLET_ID=" your_test_wallet_id" # Wallet operation tests
99+ export STAGING_PRIVATE_KEY_PATH=" ./private_key.pem" # Signature auth tests
100+ ```
101+
102+ #### Key Generation for Signature Authorization
103+
104+ Generate P-256 key pairs for signature authorization tests:
105+
106+ ``` bash
107+ ./scripts/generate-keys.sh
108+ ```
109+
110+ This creates:
111+ - ` private_key.pem ` (SEC1 format for Rust)
112+ - ` public_key.pem ` (standard PEM format)
113+
114+ ### Running Tests
115+
116+ #### Unit Tests
117+
118+ ``` bash
119+ # Run all unit tests
120+ cargo test --lib
121+
122+ # Run specific module tests
123+ cargo test --lib keys::tests
124+ cargo test --lib client::tests
125+ cargo test --lib types::tests
126+ ```
127+
128+ #### End-to-End Tests
129+
130+ ``` bash
131+ # Run all E2E tests (requires staging environment)
132+ cargo test --test " *"
133+
134+ # Run specific E2E test suites
135+ cargo test --test wallet_operations
136+ cargo test --test jwt_authentication
137+ cargo test --test signature_authorization
138+
139+ # Run with detailed logging
140+ RUST_LOG=info cargo test --test wallet_operations
141+ ```
142+
143+ #### Test Coverage
144+
145+ The test suite covers:
146+
147+ ** Authentication Methods (` src/keys.rs ` )** :
148+ - Private key loading (PEM format, file-based)
149+ - Authorization contexts with multiple keys
150+ - JWT user authentication and key caching
151+ - ECDSA P-256 signature generation
152+ - Concurrent signing operations
153+
154+ ** Client Operations (` src/client.rs ` )** :
155+ - Canonical request generation (RFC 8785 compliance)
156+ - Multi-key signature authorization
157+ - HTTP client configuration and error handling
158+ - Idempotency key support
159+
160+ ** Wallet Operations (E2E)** :
161+ - Wallet creation, retrieval, and deletion
162+ - Balance checking and transaction history
163+ - Raw message signing with authorization
164+ - Wallet export functionality
165+
166+ ** JWT Authentication (E2E)** :
167+ - HPKE encryption/decryption workflows
168+ - Encrypted and unencrypted authentication flows
169+ - Authorization key caching and expiration
170+ - Invalid/expired JWT handling
171+
172+ ** Signature Authorization (E2E)** :
173+ - Canonical request generation and signing
174+ - Multi-key authorization scenarios
175+ - Deterministic signing validation
176+ - Wallet owner updates with signature auth
177+
178+ ### Test Structure
179+
180+ ```
181+ tests/
182+ ├── common/
183+ │ └── mod.rs # Shared test utilities and environment setup
184+ ├── wallet_operations.rs # Complete wallet lifecycle tests
185+ ├── jwt_authentication.rs # JWT authentication and HPKE tests
186+ └── signature_authorization.rs # Signature-based authorization tests
187+ ```
188+
74189## Development
75190
76191### Environment Setup
0 commit comments