|
1 | | -# @litprotocol/e2e |
| 1 | +# @lit-protocol/e2e |
2 | 2 |
|
3 | | -A comprehensive end-to-end testing package for Lit Protocol integrations. This package allows you to programmatically run the full suite of Lit Protocol tests across different authentication methods and network configurations. |
| 3 | +Utilities and ready-made specs for Lit Protocol end-to-end testing. This package now ships the canonical Jest suite we run in-repo, plus helpers (state initialisers, Shiva client, etc.) so QA teams can execute the same coverage or layer on additional `.spec.ts` files without cloning this repository. |
4 | 4 |
|
5 | 5 | ## Installation |
6 | 6 |
|
7 | 7 | ```bash |
8 | | -pnpm add @litprotocol/e2e |
| 8 | +pnpm add -D jest @lit-protocol/e2e @lit-protocol/lit-client @lit-protocol/networks viem |
9 | 9 | ``` |
10 | 10 |
|
11 | | -## Environment Variables |
| 11 | +> The package depends on `jest` being available in the consumer workspace. Install any additional peer dependencies (for example `ts-node` if you prefer to author specs in TypeScript directly). |
12 | 12 |
|
13 | | -**Required** - Set these environment variables before running tests: |
| 13 | +## Required Environment |
| 14 | + |
| 15 | +Set the same environment variables the in-repo test harness expects **before** running any specs: |
14 | 16 |
|
15 | 17 | ```bash |
16 | | -# For live networks (naga-dev, naga-staging) |
| 18 | +# Accounts that sponsor users on live and local networks |
17 | 19 | LIVE_MASTER_ACCOUNT=0x... |
18 | | - |
19 | | -# For local network (naga-local) |
20 | 20 | LOCAL_MASTER_ACCOUNT=0x... |
21 | 21 |
|
22 | | -# Optional - can also be passed as parameters |
23 | | -NETWORK=naga-dev |
| 22 | +# General configuration (can also be passed to init()) |
| 23 | +NETWORK=naga-local # or naga-dev / naga-staging / naga-test |
24 | 24 | LOG_LEVEL=info |
| 25 | + |
| 26 | +# Optional local overrides |
| 27 | +NAGA_LOCAL_CONTEXT_PATH=./lit-assets/blockchain/contracts/networkContext.json |
| 28 | +NAGA_LOCAL_CONTEXT_NAME=naga-develop |
| 29 | +LIT_YELLOWSTONE_PRIVATE_RPC_URL=http://127.0.0.1:8545 |
25 | 30 | ``` |
26 | 31 |
|
27 | | -## Quick Start |
| 32 | +Make sure the referenced network (local Naga cluster, Shiva-managed testnet, or live subnet) is running and reachable from your test machine. |
28 | 33 |
|
29 | | -```typescript |
30 | | -import { runLitE2eTests } from '@litprotocol/e2e'; |
| 34 | +## Run the Bundled Suite |
31 | 35 |
|
32 | | -// Run all tests on naga-dev network |
33 | | -const results = await runLitE2eTests({ |
34 | | - network: 'naga-dev', |
35 | | -}); |
| 36 | +The published package contains the compiled `e2e.spec.ts`. You can execute it either through the provided CLI or by calling Jest directly: |
36 | 37 |
|
37 | | -console.log(`Tests completed: ${results.passed}/${results.totalTests} passed`); |
38 | | -``` |
| 38 | +```bash |
| 39 | +# Preferred: CLI wrapper injects the packaged config automatically |
| 40 | +npx lit-e2e |
39 | 41 |
|
40 | | -## Configuration Options |
41 | | - |
42 | | -```typescript |
43 | | -const results = await runLitE2eTests({ |
44 | | - network: 'naga-dev', // Required: 'naga-dev' | 'naga-local' | 'naga-staging' |
45 | | - logLevel: 'info', // Optional: 'silent' | 'info' | 'debug' |
46 | | - testTimeout: 30000, // Optional: timeout per test in milliseconds |
47 | | - selectedTests: [ |
48 | | - // Optional: run specific tests only |
49 | | - 'pkpSign', |
50 | | - 'executeJs', |
51 | | - 'viemSignMessage', |
52 | | - ], |
53 | | -}); |
| 42 | +# Equivalent manual invocation |
| 43 | +npx jest \ |
| 44 | + --config node_modules/@lit-protocol/e2e/dist/jest.e2e.package.config.cjs \ |
| 45 | + node_modules/@lit-protocol/e2e/dist/specs/e2e.spec.js |
54 | 46 | ``` |
55 | 47 |
|
56 | | -## Available Tests |
| 48 | +Both commands honour additional Jest flags (e.g. `--runInBand`, `--verbose`), so you can tailor runs to your infrastructure. |
57 | 49 |
|
58 | | -### Endpoint Tests |
| 50 | +## Author Your Own Specs |
59 | 51 |
|
60 | | -- `pkpSign` - PKP signing functionality |
61 | | -- `executeJs` - Lit Actions execution |
62 | | -- `viewPKPsByAddress` - PKP lookup by address |
63 | | -- `viewPKPsByAuthData` - PKP lookup by auth data |
64 | | -- `pkpEncryptDecrypt` - PKP-based encryption/decryption |
65 | | -- `encryptDecryptFlow` - Full encryption/decryption workflow |
66 | | -- `pkpPermissionsManagerFlow` - PKP permissions management |
67 | | -- `eoaNativeAuthFlow` - EOA native authentication and PKP minting |
| 52 | +All helper utilities are exported from `@lit-protocol/e2e`. This includes the environment `init` routine, auth-context builders, and the new Shiva client wrapper. |
68 | 53 |
|
69 | | -### Integration Tests |
| 54 | +```ts |
| 55 | +import { init, createShivaClient } from '@lit-protocol/e2e'; |
70 | 56 |
|
71 | | -- `viemSignMessage` - Viem integration for message signing |
72 | | -- `viemSignTransaction` - Viem integration for transaction signing |
73 | | -- `viemSignTypedData` - Viem integration for typed data signing |
| 57 | +describe('Epoch rollover', () => { |
| 58 | + it('advances when Shiva triggers a transition', async () => { |
| 59 | + const ctx = await init('naga-local'); |
| 60 | + const shiva = await createShivaClient(ctx.litClient, { |
| 61 | + baseUrl: 'http://localhost:8000', |
| 62 | + }); |
74 | 63 |
|
75 | | -## Test Results |
| 64 | + const before = await shiva.inspectEpoch(); |
| 65 | + await shiva.transitionEpochAndWait(); |
| 66 | + const after = await shiva.waitForEpochChange({ baselineEpoch: before.epoch }); |
76 | 67 |
|
77 | | -```typescript |
78 | | -const results = await runLitE2eTests({ network: 'naga-dev' }); |
| 68 | + expect(after.epoch).not.toEqual(before.epoch); |
| 69 | + }); |
| 70 | +}); |
| 71 | +``` |
79 | 72 |
|
80 | | -console.log(`Total: ${results.totalTests}`); |
81 | | -console.log(`Passed: ${results.passed}`); |
82 | | -console.log(`Failed: ${results.failed}`); |
83 | | -console.log(`Duration: ${results.duration}ms`); |
| 73 | +Execute custom specs with the same packaged config: |
84 | 74 |
|
85 | | -// Check for failures |
86 | | -if (results.failed > 0) { |
87 | | - const failedTests = results.results.filter((r) => r.status === 'failed'); |
88 | | - failedTests.forEach((test) => { |
89 | | - console.log(`Failed: ${test.name} - ${test.error}`); |
90 | | - }); |
91 | | -} |
| 75 | +```bash |
| 76 | +npx jest --config node_modules/@lit-protocol/e2e/dist/jest.e2e.package.config.cjs qa-epoch.spec.ts |
92 | 77 | ``` |
93 | 78 |
|
94 | | -## Examples |
| 79 | +## Bundled APIs |
| 80 | + |
| 81 | +Key exports now available from the package: |
| 82 | + |
| 83 | +- `init(network?, logLevel?)` – prepares Lit Client, Auth Manager, PKPs, and funded accounts across local or live environments. |
| 84 | +- `createShivaClient(litClient, { baseUrl, testnetId?, createRequest? })` – talks to the Shiva testnet manager (epoch transitions, node control, epoch inspection helpers). |
| 85 | +- Auth context helpers (EOA, PKP, Custom auth) under `@lit-protocol/e2e/helper/auth-contexts`. |
| 86 | +- Payment funding utilities, PKP helpers, and assorted testing primitives. |
95 | 87 |
|
96 | | -See `example.js` for detailed usage examples. |
| 88 | +Refer to the source under `packages/e2e/src/helper` for additional exported functions. |
97 | 89 |
|
98 | | -## Networks |
| 90 | +## Troubleshooting |
99 | 91 |
|
100 | | -- **naga-dev** - Development network (requires LIVE_MASTER_ACCOUNT) |
101 | | -- **naga-local** - Local development network (requires LOCAL_MASTER_ACCOUNT) |
102 | | -- **naga-staging** - Staging network (requires LIVE_MASTER_ACCOUNT) |
| 92 | +- **Jest not found** – install it locally (`pnpm add -D jest`). The CLI wrapper will exit with a helpful message if the dependency is missing. |
| 93 | +- **Missing signatures on naga-local** – provide `NAGA_LOCAL_CONTEXT_PATH` and optional `NAGA_LOCAL_CONTEXT_NAME` so the init routine calls `nagaLocal.withLocalContext`. |
| 94 | +- **RPC connectivity** – when pointing at a private RPC, set `LIT_YELLOWSTONE_PRIVATE_RPC_URL` so the Lit Client bypasses defaults. |
103 | 95 |
|
104 | | -## License |
| 96 | +With these additions, QA can stay in sync with the canonical Lit Protocol E2E coverage while extending it with custom assertions tailored to fast-epoch or failure scenarios. |
0 commit comments