Skip to content

Commit 68ffaa9

Browse files
committed
refactor(tests): update createPregenDelegationServerReuseTest to accept parameters directly
1 parent 29d011a commit 68ffaa9

File tree

3 files changed

+46
-13
lines changed

3 files changed

+46
-13
lines changed

packages/e2e/src/e2e.spec.ts

Lines changed: 8 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -272,7 +272,14 @@ describe('all', () => {
272272
describe('server reuse flow', () => {
273273
it(
274274
'should sign using materials shipped over the wire',
275-
createPregenDelegationServerReuseTest(ctx)
275+
createPregenDelegationServerReuseTest({
276+
authManager: ctx.authManager,
277+
authData: ctx.aliceViemAccountAuthData,
278+
pkpPublicKey: ctx.aliceViemAccountPkp.pubkey,
279+
clientLitClient: ctx.litClient,
280+
fallbackLitClient: ctx.litClient,
281+
networkName: process.env['NETWORK'] ?? 'naga-dev',
282+
})
276283
);
277284
});
278285
});

packages/e2e/src/tests/signSessionKey/pregen-delegation.ts

Lines changed: 30 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -6,17 +6,36 @@ import {
66
} from '@lit-protocol/auth';
77
import { createLitClient } from '@lit-protocol/lit-client';
88
import { resolveNetworkImportName } from '../../helper/network';
9-
import { initFast } from '../../init';
9+
import { AuthData } from '@lit-protocol/schemas';
10+
import { AuthManagerInstance, LitClientInstance } from '../../types';
1011

11-
type PregenContext = Awaited<ReturnType<typeof initFast>>;
12+
type PregenDelegationParams = {
13+
authManager: AuthManagerInstance;
14+
authData: AuthData;
15+
pkpPublicKey: string;
16+
clientLitClient: LitClientInstance;
17+
fallbackLitClient?: LitClientInstance;
18+
networkName?: string;
19+
};
1220

13-
export const createPregenDelegationServerReuseTest = (ctx: PregenContext) => {
21+
export const createPregenDelegationServerReuseTest = (
22+
params: PregenDelegationParams
23+
) => {
1424
return async () => {
25+
const {
26+
authManager,
27+
authData,
28+
pkpPublicKey,
29+
clientLitClient,
30+
fallbackLitClient,
31+
networkName,
32+
} = params;
33+
1534
const sessionKeyPair = generateSessionKeyPair();
1635
const delegationAuthSig =
17-
await ctx.authManager.generatePkpDelegationAuthSig({
18-
pkpPublicKey: ctx.aliceViemAccountPkp.pubkey,
19-
authData: ctx.aliceViemAccountAuthData,
36+
await authManager.generatePkpDelegationAuthSig({
37+
pkpPublicKey,
38+
authData,
2039
sessionKeyPair,
2140
authConfig: {
2241
resources: [
@@ -26,11 +45,11 @@ export const createPregenDelegationServerReuseTest = (ctx: PregenContext) => {
2645
],
2746
expiration: new Date(Date.now() + 1000 * 60 * 15).toISOString(),
2847
},
29-
litClient: ctx.litClient,
48+
litClient: clientLitClient,
3049
});
3150

3251
const envelope = JSON.stringify({
33-
pkpPublicKey: ctx.aliceViemAccountPkp.pubkey,
52+
pkpPublicKey,
3453
payload: Buffer.from(
3554
JSON.stringify({ sessionKeyPair, delegationAuthSig }),
3655
'utf8'
@@ -57,7 +76,7 @@ export const createPregenDelegationServerReuseTest = (ctx: PregenContext) => {
5776
const serverAuthManager = createAuthManager({
5877
storage: storagePlugins.localStorageNode({
5978
appName: 'e2e-server-reuse',
60-
networkName: process.env['NETWORK'] ?? 'naga-dev',
79+
networkName: networkName ?? 'naga-dev',
6180
storagePath: './.e2e/server-reuse-storage',
6281
}),
6382
});
@@ -72,12 +91,12 @@ export const createPregenDelegationServerReuseTest = (ctx: PregenContext) => {
7291
let litClient;
7392
try {
7493
const networksModule = await import('@lit-protocol/networks');
75-
const importName = resolveNetworkImportName(process.env['NETWORK']);
94+
const importName = resolveNetworkImportName(networkName);
7695
const networkModule = networksModule[importName];
7796
litClient = await createLitClient({ network: networkModule });
7897
await litClient.connect();
7998
} catch {
80-
litClient = ctx.litClient;
99+
litClient = fallbackLitClient ?? clientLitClient;
81100
}
82101

83102
const result = await litClient.chain.ethereum.pkpSign({

packages/e2e/src/tickets/jss36-pregen-delegation.spec.ts

Lines changed: 8 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,13 @@ describe('PKP Auth with Pre-generated Materials', () => {
99
});
1010

1111
test('Try to pregen', async () => {
12-
await createPregenDelegationServerReuseTest(ctx)();
12+
await createPregenDelegationServerReuseTest({
13+
authManager: ctx.authManager,
14+
authData: ctx.aliceViemAccountAuthData,
15+
pkpPublicKey: ctx.aliceViemAccountPkp.pubkey,
16+
clientLitClient: ctx.litClient,
17+
fallbackLitClient: ctx.litClient,
18+
networkName: process.env['NETWORK'] ?? 'naga-dev',
19+
})();
1320
});
1421
});

0 commit comments

Comments
 (0)