Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
63 changes: 38 additions & 25 deletions e2e/artillery/processors/multi-endpoint.ts
Original file line number Diff line number Diff line change
Expand Up @@ -38,29 +38,42 @@ import {
let sharedContext: any = null;
let alicePkpAuthContext: any = null;
let aliceCustomAuthContext: any = null;
let initializationPromise: Promise<any> | null = null;

/**
* Initialize the shared context once per Artillery run
*/
async function initializeSharedContext() {
if (sharedContext) return sharedContext;

// Prevent race conditions by ensuring only one initialization happens
if (initializationPromise) {
return await initializationPromise;
}

try {
console.log('🚀 Initializing Artillery shared context...');

// Use the same init function as e2e tests
sharedContext = await init();

// Create auth contexts using helper functions
alicePkpAuthContext = await createPkpAuthContext(sharedContext);
aliceCustomAuthContext = await createCustomAuthContext(sharedContext);
initializationPromise = (async () => {
try {
console.log('🚀 Initializing Artillery shared context...');

// Use the same init function as e2e tests
sharedContext = await init();

// Create auth contexts using helper functions
alicePkpAuthContext = await createPkpAuthContext(sharedContext);
aliceCustomAuthContext = await createCustomAuthContext(sharedContext);

console.log('✅ Artillery shared context initialized');
return sharedContext;
} catch (error) {
console.error('❌ Failed to initialize Artillery context:', error);
// Reset state on failure so retry is possible
initializationPromise = null;
sharedContext = null;
throw error;
}
})();

console.log('✅ Artillery shared context initialized');
return sharedContext;
} catch (error) {
console.error('❌ Failed to initialize Artillery context:', error);
throw error;
}
return await initializationPromise;
}

/**
Expand Down Expand Up @@ -166,7 +179,7 @@ export async function runMultiEndpointTest(context: any, events: any) {
/**
* PKP Sign test functions
*/
export async function runPkpSignTest(context, events) {
export async function runPkpSignTest(context: any, events: any) {
await initializeSharedContext();

const parallelism = context.vars.parallelism || 5;
Expand All @@ -176,7 +189,7 @@ export async function runPkpSignTest(context, events) {
await runTestWithMetrics('pkp_sign', testFn, context, events, parallelism);
}

export async function runPkpSignTestWithEoa(context, events) {
export async function runPkpSignTestWithEoa(context: any, events: any) {
await initializeSharedContext();

const parallelism = context.vars.parallelism || 5;
Expand All @@ -192,7 +205,7 @@ export async function runPkpSignTestWithEoa(context, events) {
);
}

export async function runPkpSignTestWithPkp(context, events) {
export async function runPkpSignTestWithPkp(context: any, events: any) {
await initializeSharedContext();

const parallelism = context.vars.parallelism || 5;
Expand All @@ -208,7 +221,7 @@ export async function runPkpSignTestWithPkp(context, events) {
);
}

export async function runPkpSignTestWithCustom(context, events) {
export async function runPkpSignTestWithCustom(context: any, events: any) {
await initializeSharedContext();

const parallelism = context.vars.parallelism || 5;
Expand All @@ -227,7 +240,7 @@ export async function runPkpSignTestWithCustom(context, events) {
/**
* Encrypt/Decrypt test functions
*/
export async function runEncryptDecryptTest(context, events) {
export async function runEncryptDecryptTest(context: any, events: any) {
await initializeSharedContext();

const parallelism = context.vars.parallelism || 3;
Expand All @@ -243,7 +256,7 @@ export async function runEncryptDecryptTest(context, events) {
);
}

export async function runPkpEncryptDecryptTest(context, events) {
export async function runPkpEncryptDecryptTest(context: any, events: any) {
await initializeSharedContext();

const parallelism = context.vars.parallelism || 3;
Expand All @@ -259,7 +272,7 @@ export async function runPkpEncryptDecryptTest(context, events) {
);
}

export async function runEncryptDecryptFlowTest(context, events) {
export async function runEncryptDecryptFlowTest(context: any, events: any) {
await initializeSharedContext();

const parallelism = context.vars.parallelism || 3;
Expand All @@ -278,7 +291,7 @@ export async function runEncryptDecryptFlowTest(context, events) {
/**
* Execute JS test function
*/
export async function runExecuteJsTest(context, events) {
export async function runExecuteJsTest(context: any, events: any) {
await initializeSharedContext();

const parallelism = context.vars.parallelism || 4;
Expand All @@ -291,7 +304,7 @@ export async function runExecuteJsTest(context, events) {
/**
* View PKPs test functions
*/
export async function runViewPkpsTest(context, events) {
export async function runViewPkpsTest(context: any, events: any) {
await initializeSharedContext();

const parallelism = context.vars.parallelism || 5;
Expand Down Expand Up @@ -325,7 +338,7 @@ export async function runViewPkpsTest(context, events) {
/**
* Viem integration test functions
*/
export async function runViemSignTest(context, events) {
export async function runViemSignTest(context: any, events: any) {
await initializeSharedContext();

const parallelism = context.vars.parallelism || 3;
Expand Down
10 changes: 5 additions & 5 deletions e2e/src/init.ts
Original file line number Diff line number Diff line change
Expand Up @@ -50,7 +50,7 @@ export const init = async (
const aliceViemAccountAuthData = await ViemAccountAuthenticator.authenticate(
aliceViemAccount
);

const bobViemAccount = privateKeyToAccount(generatePrivateKey());
const bobViemAccountAuthData = await ViemAccountAuthenticator.authenticate(
bobViemAccount
Expand Down Expand Up @@ -167,7 +167,7 @@ export const init = async (
},
storageProvider: storagePlugins.localStorageNode({
appName: 'my-app',
networkName: 'naga-dev',
networkName: _network,
storagePath: './pkp-tokens',
}),
});
Expand All @@ -180,7 +180,7 @@ export const init = async (
},
storageProvider: storagePlugins.localStorageNode({
appName: 'my-app',
networkName: 'naga-dev',
networkName: _network,
storagePath: './pkp-tokens-bob',
}),
});
Expand Down Expand Up @@ -219,7 +219,7 @@ export const init = async (
},
storageProvider: storagePlugins.localStorageNode({
appName: 'my-app',
networkName: 'naga-dev',
networkName: _network,
storagePath: './pkp-tokens',
}),
});
Expand All @@ -232,7 +232,7 @@ export const init = async (
},
storageProvider: storagePlugins.localStorageNode({
appName: 'my-app',
networkName: 'naga-dev',
networkName: _network,
storagePath: './pkp-tokens-bob',
}),
});
Expand Down
12 changes: 6 additions & 6 deletions packages/lit-client/src/lib/LitClient/createLitClient.ts
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@ import type {
} from '@lit-protocol/networks';
import {
AuthContextSchema2,
AuthData,
EncryptedVersion1Schema,
HexPrefixedSchema,
JsonSignCustomSessionKeyRequestForPkpReturnSchema,
Expand Down Expand Up @@ -50,8 +51,7 @@ import {
MintWithCustomAuthRequest,
MintWithCustomAuthSchema,
} from './schemas/MintWithCustomAuthSchema';
import { LitClient, NagaNetworkModule } from './type';
import { NagaLitClient } from './types/NagaLitClient.type';
import { NagaNetworkModule } from './type';

const _logger = getChildLogger({
module: 'createLitClient',
Expand Down Expand Up @@ -84,7 +84,7 @@ export const createLitClient = async ({
network,
}: {
network: SupportedNetworkModule;
}): Promise<LitClient> => {
}) => {
switch (network.id) {
// -- (v8) Naga Network Module
case 'naga':
Expand Down Expand Up @@ -144,7 +144,7 @@ export const createLitClient = async ({
*/
export const _createNagaLitClient = async (
networkModule: NagaNetworkModule
): Promise<NagaLitClient> => {
) => {
const _stateManager = await networkModule.createStateManager<
Awaited<ReturnType<typeof orchestrateHandshake>>,
NagaNetworkModule
Expand Down Expand Up @@ -702,7 +702,7 @@ export const _createNagaLitClient = async (
return response;
}

const litClient: NagaLitClient = {
const litClient = {
// This function is likely be used by another module to get the current context, eg. auth manager
// only adding what is required by other modules for now.
// maybe you will need connectionInfo: _stateManager.getLatestConnectionInfo(),
Expand Down Expand Up @@ -832,7 +832,7 @@ export const _createNagaLitClient = async (
authMethodType: number | bigint;
authMethodId: string;
accessToken?: string;
};
} | AuthData;
pagination?: { limit?: number; offset?: number };
storageProvider?: PKPStorageProvider;
}) => {
Expand Down
4 changes: 2 additions & 2 deletions packages/lit-client/src/lib/LitClient/type.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
import { NagaLocalModule } from '@lit-protocol/networks';
import { NagaDevModule } from '@lit-protocol/networks';
import { NagaStagingModule } from '@lit-protocol/networks';
import { NagaLitClient } from './types/NagaLitClient.type';
// import { NagaLitClient } from './types/NagaLitClient.type';

/**
* ========== All Network Modules ==========
Expand All @@ -27,5 +27,5 @@ export type NagaNetworkModule =
/**
* Union type for all possible Lit clients
*/
export type LitClient = NagaLitClient;
// export type LitClient = NagaLitClient;
// | DatilLitClient;
Loading