Skip to content

Commit ac81c89

Browse files
committed
Add encrypt-decrypt load test
1 parent b3506a8 commit ac81c89

File tree

3 files changed

+90
-0
lines changed

3 files changed

+90
-0
lines changed
Lines changed: 24 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,24 @@
1+
config:
2+
target: "dummy"
3+
phases:
4+
# Over 60s, ramp up to creating 50 vusers per second
5+
- duration: 60
6+
arrivalRate: 5
7+
rampTo: 80
8+
name: "Ramp Up"
9+
# Over 300s, create 50 vusers per second
10+
- duration: 300
11+
arrivalRate: 80
12+
name: "Sustained Encrypt & Decrypt"
13+
# Over 60s, ramp down to creating 5 vusers per second
14+
- duration: 60
15+
arrivalRate: 20
16+
name: "Ramp Down"
17+
processor: "../src/processors/multi-endpoints.ts"
18+
19+
scenarios:
20+
- name: "Encrypt & Decrypt Stress Test"
21+
weight: 100
22+
flow:
23+
- function: "runEncryptDecryptTest"
24+
- think: 0.1

e2e/artillery/src/processors/multi-endpoints.ts

Lines changed: 65 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,7 @@ import { z } from 'zod';
44
import * as StateManager from '../StateManager';
55
import * as NetworkManager from '../../../src/helper/NetworkManager';
66
import * as AccountManager from '../AccountManager';
7+
import { createAccBuilder } from '@lit-protocol/access-control-conditions';
78

89
// PKP Sign Result Schema
910
const PkpSignResultSchema = z.object({
@@ -147,6 +148,70 @@ export async function runPkpSignTest() {
147148
}
148149
}
149150

151+
// test '/web/encryption/sign/v2' endpoint
152+
export async function runEncryptDecryptTest() {
153+
const startTime = Date.now();
154+
155+
try {
156+
// 1. Initialise shared resources (only happens once)
157+
await initialiseSharedResources();
158+
159+
// 2. Read state
160+
const state = await StateManager.readFile();
161+
162+
// Create auth context
163+
const authContext = await createAuthContextFromState();
164+
165+
// Set up access control conditions requiring wallet ownership
166+
const addressToUse = authContext.account.address;
167+
const builder = createAccBuilder();
168+
const accs = builder
169+
.requireWalletOwnership(addressToUse)
170+
.on('ethereum')
171+
.build();
172+
173+
// Encrypt data with the access control conditions
174+
const dataToEncrypt = 'Hello from PKP encrypt-decrypt test!';
175+
const encryptedData = await litClient.encrypt({
176+
dataToEncrypt,
177+
unifiedAccessControlConditions: accs,
178+
chain: 'ethereum',
179+
});
180+
181+
// Decrypt the data using the appropriate auth context
182+
const decryptedData = await litClient.decrypt({
183+
data: encryptedData,
184+
unifiedAccessControlConditions: accs,
185+
chain: 'ethereum',
186+
authContext,
187+
});
188+
189+
// Assert that the decrypted data is the same as the original data
190+
if (decryptedData.convertedData !== dataToEncrypt) {
191+
throw new Error('❌ Decrypted data does not match the original data');
192+
}
193+
194+
const endTime = Date.now();
195+
const duration = endTime - startTime;
196+
197+
console.log(`✅ encrypt & decrypt successful in ${duration}ms`);
198+
199+
// For Artillery, just return - no need to call next()
200+
return;
201+
} catch (error) {
202+
const endTime = Date.now();
203+
const duration = endTime - startTime;
204+
205+
console.error(
206+
`❌ encrypt & decrypt failed in ${duration}ms:`,
207+
error instanceof Error ? error.message : String(error)
208+
);
209+
210+
// Throw the error to let Artillery handle it
211+
throw error;
212+
}
213+
}
214+
150215
// test '/web/sign_session_key' endpoint
151216
export async function runSignSessionKeyTest() {
152217
// ❗️ IT'S IMPORTANT TO SET THIS TO FALSE FOR TESTING

package.json

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -28,6 +28,7 @@
2828
"artillery:init": "bun run ./e2e/artillery/src/init.ts",
2929
"artillery:balance-status": "LOG_LEVEL=silent bun run ./e2e/artillery/src/balance-status.ts",
3030
"artillery:pkp-sign": "DEBUG_HTTP=true LOG_LEVEL=silent dotenvx run --env-file=.env -- sh -c 'artillery run ./e2e/artillery/configs/pkp-sign.yml ${ARTILLERY_KEY:+--record --key $ARTILLERY_KEY}'",
31+
"artillery:encrypt-decrypt": "DEBUG_HTTP=true LOG_LEVEL=silent dotenvx run --env-file=.env -- sh -c 'artillery run ./e2e/artillery/configs/encrypt-decrypt.yml ${ARTILLERY_KEY:+--record --key $ARTILLERY_KEY}'",
3132
"artillery:sign-session-key": "DEBUG_HTTP=true LOG_LEVEL=silent dotenvx run --env-file=.env -- sh -c 'artillery run ./e2e/artillery/configs/sign-session-key.yml ${ARTILLERY_KEY:+--record --key $ARTILLERY_KEY}'"
3233
},
3334
"private": true,

0 commit comments

Comments
 (0)