Skip to content

Commit 65aa168

Browse files
committed
scaffold unit tests for all operations
1 parent cb5ad55 commit 65aa168

14 files changed

Lines changed: 1369 additions & 13 deletions

Cargo.lock

Lines changed: 1 addition & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

Cargo.toml

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -38,6 +38,7 @@ dotenv = "0.15"
3838
uuid = { version = "1.0", features = ["v4"] }
3939
test-case = "3.3.1"
4040
tracing-test = "0.2.5"
41+
tempfile = "3.0"
4142

4243
# used for deterministic key generation under testing
4344
rand_chacha = "0.9.0"

README.md

Lines changed: 115 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -71,6 +71,121 @@ PRIVY_APP_ID=your_app_id
7171
PRIVY_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

src/client.rs

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -18,6 +18,7 @@ use crate::{
1818
/// the `wallet()` method.
1919
#[derive(Clone, Debug)]
2020
pub struct PrivyClient {
21+
#[allow(dead_code)]
2122
pub(crate) app_id: String,
2223
#[allow(dead_code)]
2324
pub(crate) app_secret: String,

0 commit comments

Comments
 (0)