Skip to content

Commit b37d23d

Browse files
committed
fix(artillery): align init helpers, state cache, and docs
1 parent 8585dbc commit b37d23d

File tree

3 files changed

+61
-7
lines changed

3 files changed

+61
-7
lines changed

README.md

Lines changed: 44 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -99,6 +99,50 @@ DIRECTORY_NAME=naga-local
9999
NETWORK=naga-local pnpm run test:e2e all
100100
```
101101

102+
# Artillery Load Testing
103+
104+
Use the standalone Artillery project under `packages/artillery` to exercise Lit endpoints with realistic workloads.
105+
106+
## Preparation
107+
108+
```bash
109+
# from the repo root
110+
pnpm install
111+
112+
# pick your target network: naga-dev | naga-staging | naga-test | naga-local
113+
export NETWORK=naga-staging
114+
export LOG_LEVEL=info # optional: debug | debug2 | silent
115+
```
116+
117+
If you want Artillery Cloud reports, set `ARTILLERY_KEY=<your-key>` in `.env` before running a scenario.
118+
119+
## One-time initialisation
120+
121+
Master account, auth data and PKP info are written to this file:
122+
`packages/artillery/artillery-state.json`.
123+
124+
```bash
125+
pnpm nx run artillery:init
126+
```
127+
128+
(optional) Check master balances before blasting a load test:
129+
130+
```bash
131+
pnpm nx run artillery:balance-status
132+
```
133+
134+
## Run a workload
135+
136+
Each scenario is exposed as an Nx target. Use the `run:` prefixed name:
137+
138+
```bash
139+
pnpm nx run artillery:run:pkp-sign # PKP signing focus
140+
pnpm nx run artillery:run:encrypt-decrypt # Encryption/decryption focus
141+
pnpm nx run artillery:run:execute # Lit Action execution
142+
pnpm nx run artillery:run:mix # Mixed workload
143+
pnpm nx run artillery:run:sign-session-key # Session key signing
144+
```
145+
102146
# Manual Publishing
103147

104148
```bash

packages/artillery/src/StateManager.ts

Lines changed: 12 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -24,7 +24,7 @@ export const readFile = async (): Promise<State> => {
2424

2525
// If content is empty object, write base state
2626
if (Object.keys(content).length === 0) {
27-
await fs.writeFile(FILE_NAME, JSON.stringify(StateObject, null, 2));
27+
await fs.writeFile(FILE_NAME, stringify(StateObject));
2828
return StateObject;
2929
}
3030

@@ -42,7 +42,7 @@ export const readFile = async (): Promise<State> => {
4242

4343
// create the file if it doesn't exist
4444
export const createFile = async () => {
45-
await fs.writeFile(FILE_NAME, JSON.stringify(StateObject, null, 2));
45+
await fs.writeFile(FILE_NAME, stringify(StateObject));
4646
};
4747

4848
// Type-safe field paths - dynamically derived from State type
@@ -93,7 +93,7 @@ export const updateField = async <T extends StatePaths>(
9393
state[rootKey] !== null
9494
) {
9595
(state[rootKey] as any)[nestedKey] = value;
96-
await fs.writeFile(FILE_NAME, JSON.stringify(state, null, 2));
96+
await fs.writeFile(FILE_NAME, stringify(state));
9797
} else {
9898
throw new Error(`Invalid path: ${path}`);
9999
}
@@ -123,7 +123,7 @@ export const getOrUpdate = async <T extends StatePaths>(
123123

124124
// Otherwise, update with default value and return it
125125
(state as any)[path] = defaultValue;
126-
await fs.writeFile(FILE_NAME, JSON.stringify(state, null, 2));
126+
await fs.writeFile(FILE_NAME, stringify(state));
127127
return defaultValue;
128128
} else {
129129
// Nested property
@@ -144,10 +144,17 @@ export const getOrUpdate = async <T extends StatePaths>(
144144

145145
// Otherwise, update with default value and return it
146146
(state[rootKey] as any)[nestedKey] = defaultValue;
147-
await fs.writeFile(FILE_NAME, JSON.stringify(state, null, 2));
147+
await fs.writeFile(FILE_NAME, stringify(state));
148148
return defaultValue;
149149
} else {
150150
throw new Error(`Invalid path: ${path}`);
151151
}
152152
}
153153
};
154+
155+
const stringify = (value: unknown) =>
156+
JSON.stringify(
157+
value,
158+
(_, val) => (typeof val === 'bigint' ? val.toString() : val),
159+
2
160+
);

packages/artillery/src/init.ts

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -6,8 +6,11 @@ import {
66
} from '@lit-protocol/auth';
77
import * as StateManager from './StateManager';
88
import { createLitClient } from '@lit-protocol/lit-client';
9-
import { getOrCreatePkp } from '@lit-protocol/e2e/src/helper/pkp-utils';
10-
import * as NetworkManager from '@lit-protocol/e2e/src/helper/NetworkManager';
9+
import {
10+
getOrCreatePkp,
11+
getLitNetworkModule,
12+
getViemPublicClient,
13+
} from '@lit-protocol/e2e';
1114
import * as AccountManager from '../src/AccountManager';
1215

1316
const _network = process.env['NETWORK'];

0 commit comments

Comments
 (0)