Skip to content

Commit 46c2f2b

Browse files
committed
fmt
1 parent dd339e0 commit 46c2f2b

File tree

5 files changed

+9308
-3238
lines changed

5 files changed

+9308
-3238
lines changed

packages/e2e/src/health/NagaHealthManager.ts

Lines changed: 13 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -1,17 +1,17 @@
11
/**
22
* Naga Health Manager
3-
*
3+
*
44
* This module implements health checks for Naga network endpoints.
55
* It tests the core functionality of the Lit Protocol network by executing
66
* a series of endpoint tests using a single test account.
7-
*
7+
*
88
* Tested Endpoints:
99
* 1. Handshake - Verifies basic node connectivity
1010
* 2. PKP Sign - Tests PKP signing functionality
1111
* 3. Sign Session Key - Tests session key signing (via PKP auth context creation)
1212
* 4. Execute JS - Tests Lit Actions execution
1313
* 5. Decrypt - Tests encryption and decryption flow
14-
*
14+
*
1515
* Usage:
1616
* const manager = new NagaHealthManager(ctx);
1717
* await manager.handshakeTest();
@@ -33,10 +33,10 @@ export class NagaHealthManager {
3333

3434
/**
3535
* Test 1: Handshake Test
36-
*
36+
*
3737
* Verifies basic connectivity to Lit nodes by checking if the client
3838
* is properly initialized and connected.
39-
*
39+
*
4040
* This is the most basic health check - if this fails, the network is down.
4141
*/
4242
handshakeTest = async (): Promise<void> => {
@@ -72,7 +72,7 @@ export class NagaHealthManager {
7272

7373
/**
7474
* Test 2: PKP Sign Test
75-
*
75+
*
7676
* Tests the PKP signing endpoint by signing a simple message.
7777
* This verifies that:
7878
* - The PKP is accessible
@@ -82,7 +82,7 @@ export class NagaHealthManager {
8282
pkpSignTest = async (): Promise<void> => {
8383
try {
8484
const testMessage = 'Hello from Naga health check!';
85-
85+
8686
const result = await this.ctx.litClient.chain.ethereum.pkpSign({
8787
authContext: this.ctx.aliceEoaAuthContext,
8888
pubKey: this.ctx.aliceViemAccountPkp.pubkey,
@@ -102,7 +102,7 @@ export class NagaHealthManager {
102102

103103
/**
104104
* Test 3: Sign Session Key Test
105-
*
105+
*
106106
* Tests the session key signing endpoint by creating a PKP auth context.
107107
* This involves the signSessionKey endpoint which is critical for
108108
* establishing authenticated sessions with PKPs.
@@ -136,10 +136,10 @@ export class NagaHealthManager {
136136

137137
/**
138138
* Test 4: Execute JS Test
139-
*
139+
*
140140
* Tests Lit Actions execution by running a simple JavaScript code
141141
* that performs an ECDSA signature.
142-
*
142+
*
143143
* This verifies:
144144
* - Lit Actions runtime is operational
145145
* - Code execution environment is working
@@ -186,11 +186,11 @@ export class NagaHealthManager {
186186

187187
/**
188188
* Test 5: Decrypt Test
189-
*
189+
*
190190
* Tests the encryption and decryption flow:
191191
* 1. Encrypts data with access control conditions
192192
* 2. Decrypts the data using the same account
193-
*
193+
*
194194
* This verifies:
195195
* - Encryption endpoint works
196196
* - Access control condition evaluation works
@@ -200,7 +200,7 @@ export class NagaHealthManager {
200200
decryptTest = async (): Promise<void> => {
201201
try {
202202
const testData = 'Secret health check data';
203-
203+
204204
// Create access control conditions for Alice's wallet
205205
const builder = createAccBuilder();
206206
const accs = builder
@@ -245,4 +245,3 @@ export class NagaHealthManager {
245245
}
246246
};
247247
}
248-

packages/e2e/src/health/README.md

Lines changed: 15 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -38,13 +38,15 @@ The health check system is designed to be:
3838
### How It Works
3939

4040
1. **Initialization** (`health-init.ts`):
41+
4142
- Creates a single test account (Alice)
4243
- Funds it with minimal amount
4344
- Creates one PKP
4445
- Sets up EOA auth context
4546
- No Bob, Eve, or complex multi-account setup
4647

4748
2. **Test Execution** (`NagaHealthManager.ts`):
49+
4850
- Reuses the same Alice account and auth context
4951
- Tests each endpoint sequentially
5052
- Throws errors on failures for proper error tracking
@@ -111,11 +113,13 @@ You can manually trigger health checks from GitHub:
111113
Configure these in your repository settings under `Settings → Secrets and variables → Actions`:
112114

113115
**Secrets:**
116+
114117
- `LIT_STATUS_WRITE_KEY` - API key for status backend
115118
- `LIVE_MASTER_ACCOUNT_NAGA_DEV` - Funding account for naga-dev
116119
- `LIVE_MASTER_ACCOUNT_NAGA_TEST` - Funding account for naga-test
117120

118121
**Variables:**
122+
119123
- `LIT_STATUS_BACKEND_URL` - Status backend URL
120124
- `LIT_YELLOWSTONE_PRIVATE_RPC_URL` - (Optional) Custom RPC URL
121125

@@ -126,6 +130,7 @@ Environment: `Health Check` (create this environment in repository settings)
126130
### Status Dashboard
127131

128132
View health check results at the Lit Status dashboard:
133+
129134
- URL: Configured via `LIT_STATUS_BACKEND_URL`
130135
- Shows success/failure rates
131136
- Tracks response times
@@ -134,6 +139,7 @@ View health check results at the Lit Status dashboard:
134139
### GitHub Actions
135140

136141
Monitor workflow runs:
142+
137143
- Go to `Actions → Naga Health Checks`
138144
- View recent runs and their status
139145
- Check logs for detailed error messages
@@ -152,15 +158,19 @@ If health checks fail:
152158
### Common Issues
153159

154160
**Error: "NETWORK environment variable is not set"**
161+
155162
- Solution: Ensure `NETWORK` is set in the workflow or .env file
156163

157164
**Error: "LIVE_MASTER_ACCOUNT is not set"**
165+
158166
- Solution: Check that the appropriate secret is configured in GitHub
159167

160168
**Error: "Failed to get network information"**
169+
161170
- Solution: Network may be down or unreachable. Check node status.
162171

163172
**Error: "Insufficient funds"**
173+
164174
- Solution: Fund the master account with more tokens
165175

166176
## 🧪 Testing Locally
@@ -191,6 +201,7 @@ pnpm run test:health
191201
To add a new health check test:
192202

193203
1. **Add test method to `NagaHealthManager.ts`**:
204+
194205
```typescript
195206
myNewTest = async (): Promise<void> => {
196207
try {
@@ -204,6 +215,7 @@ myNewTest = async (): Promise<void> => {
204215
```
205216

206217
2. **Register function in `index.ts`**:
218+
207219
```typescript
208220
const txs = await statusClient.getOrRegisterFunctions({
209221
network: NETWORK!,
@@ -220,12 +232,10 @@ const txs = await statusClient.getOrRegisterFunctions({
220232
```
221233

222234
3. **Execute test in `index.ts`**:
235+
223236
```typescript
224237
console.log('6️⃣ Testing: My New Test');
225-
await statusClient.executeAndLog(
226-
txs.myNewTest.id,
227-
healthManager.myNewTest
228-
);
238+
await statusClient.executeAndLog(txs.myNewTest.id, healthManager.myNewTest);
229239
```
230240

231241
## 🔐 Security Considerations
@@ -254,7 +264,7 @@ When modifying health checks:
254264
## 📧 Support
255265

256266
For issues or questions:
267+
257268
- Create an issue in the repository
258269
- Contact the Lit Protocol team
259270
- Check the status dashboard for network-wide issues
260-

packages/e2e/src/health/health-init.ts

Lines changed: 8 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,10 @@
11
/**
22
* Health Check Initialization Module
3-
*
3+
*
44
* This module provides a lightweight initialization for health checks that minimizes
55
* chain interactions. Unlike the full e2e init, this only creates a single test person
66
* using EOA authentication and reuses it across all endpoint tests.
7-
*
7+
*
88
* Design Philosophy:
99
* - Minimal chain interactions (only what's necessary for testing endpoints)
1010
* - Single person setup to reduce overhead
@@ -30,10 +30,7 @@ import {
3030
ViemAccount,
3131
} from '../types';
3232

33-
const SupportedNetworkSchema = z.enum([
34-
'naga-dev',
35-
'naga-test',
36-
]);
33+
const SupportedNetworkSchema = z.enum(['naga-dev', 'naga-test']);
3734

3835
type SupportedNetwork = z.infer<typeof SupportedNetworkSchema>;
3936

@@ -46,13 +43,13 @@ const LIVE_NETWORK_LEDGER_DEPOSIT_AMOUNT = '2';
4643

4744
/**
4845
* Initialize the health check environment with minimal setup
49-
*
46+
*
5047
* This function:
5148
* 1. Creates a single test account (Alice)
5249
* 2. Funds it minimally
5350
* 3. Creates one PKP for testing
5451
* 4. Sets up auth context for endpoint testing
55-
*
52+
*
5653
* @param network - The network to run health checks on (naga-dev or naga-test)
5754
* @param logLevel - Logging level for the health check run
5855
* @returns Initialized components needed for health checks
@@ -90,7 +87,9 @@ export const initHealthCheck = async (
9087
const parsedNetwork = SupportedNetworkSchema.safeParse(_network);
9188
if (!parsedNetwork.success) {
9289
throw new Error(
93-
`❌ Invalid network: ${_network}. Must be one of: ${SupportedNetworkSchema.options.join(', ')}`
90+
`❌ Invalid network: ${_network}. Must be one of: ${SupportedNetworkSchema.options.join(
91+
', '
92+
)}`
9493
);
9594
}
9695

@@ -249,4 +248,3 @@ export const initHealthCheck = async (
249248
networkName: _network,
250249
};
251250
};
252-

packages/e2e/src/health/index.ts

Lines changed: 16 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -1,20 +1,20 @@
11
/**
22
* Naga Health Check Runner
3-
*
3+
*
44
* This is the main entry point for running health checks on Naga networks.
55
* It initializes the environment, runs all endpoint tests, and logs results
66
* to the Lit Status backend for monitoring.
7-
*
7+
*
88
* Environment Variables Required:
99
* - NETWORK: The network to test (naga-dev or naga-test)
1010
* - LIVE_MASTER_ACCOUNT: Private key of the master funding account
1111
* - LIT_STATUS_BACKEND_URL: URL of the status backend
1212
* - LIT_STATUS_WRITE_KEY: API key for writing to status backend
13-
*
13+
*
1414
* Optional:
1515
* - LOG_LEVEL: Logging verbosity (silent, info, debug)
1616
* - LIT_YELLOWSTONE_PRIVATE_RPC_URL: Override RPC URL
17-
*
17+
*
1818
* Usage:
1919
* NETWORK=naga-dev pnpm run ci:health
2020
* NETWORK=naga-test pnpm run test:health
@@ -33,7 +33,10 @@ const PRODUCT = 'js-sdk/naga';
3333
function validateEnvironment(): void {
3434
console.log('🔍 Environment Variables:');
3535
console.log(' NETWORK:', process.env['NETWORK']);
36-
console.log(' LIT_STATUS_BACKEND_URL:', process.env['LIT_STATUS_BACKEND_URL']);
36+
console.log(
37+
' LIT_STATUS_BACKEND_URL:',
38+
process.env['LIT_STATUS_BACKEND_URL']
39+
);
3740
console.log(
3841
' LIT_STATUS_WRITE_KEY:',
3942
process.env['LIT_STATUS_WRITE_KEY'] ? '[SET]' : '[NOT SET]'
@@ -48,7 +51,9 @@ function validateEnvironment(): void {
4851
}
4952

5053
if (!process.env['LIT_STATUS_BACKEND_URL']) {
51-
throw new Error('❌ LIT_STATUS_BACKEND_URL environment variable is not set');
54+
throw new Error(
55+
'❌ LIT_STATUS_BACKEND_URL environment variable is not set'
56+
);
5257
}
5358

5459
if (!process.env['LIT_STATUS_WRITE_KEY']) {
@@ -77,7 +82,9 @@ async function runHealthCheck(): Promise<void> {
7782
console.log(`Time: ${new Date().toISOString()}\n`);
7883

7984
// Initialize Lit Status Client (dynamic import for ESM compatibility)
80-
const { createLitStatusClient } = await import('@lit-protocol/lit-status-sdk');
85+
const { createLitStatusClient } = await import(
86+
'@lit-protocol/lit-status-sdk'
87+
);
8188
const statusClient = createLitStatusClient({
8289
url: process.env['LIT_STATUS_BACKEND_URL']!,
8390
apiKey: process.env['LIT_STATUS_WRITE_KEY']!,
@@ -124,10 +131,7 @@ async function runHealthCheck(): Promise<void> {
124131

125132
// Test 2: PKP Sign
126133
console.log('2️⃣ Testing: PKP Sign');
127-
await statusClient.executeAndLog(
128-
txs.pkpSign.id,
129-
healthManager.pkpSignTest
130-
);
134+
await statusClient.executeAndLog(txs.pkpSign.id, healthManager.pkpSignTest);
131135
console.log('');
132136

133137
// Test 3: Sign Session Key
@@ -148,10 +152,7 @@ async function runHealthCheck(): Promise<void> {
148152

149153
// Test 5: Decrypt
150154
console.log('5️⃣ Testing: Encrypt/Decrypt');
151-
await statusClient.executeAndLog(
152-
txs.decrypt.id,
153-
healthManager.decryptTest
154-
);
155+
await statusClient.executeAndLog(txs.decrypt.id, healthManager.decryptTest);
155156
console.log('');
156157

157158
console.log('═══════════════════════════════════════');
@@ -180,4 +181,3 @@ async function runHealthCheck(): Promise<void> {
180181
process.exit(1);
181182
}
182183
})();
183-

0 commit comments

Comments
 (0)