Skip to content

Commit 2904d76

Browse files
author
Josh Long
committed
Merge branch 'master' of github.com:LIT-Protocol/js-sdk
2 parents 610ed7d + 3346f57 commit 2904d76

32 files changed

+409
-414
lines changed

README.md

Lines changed: 34 additions & 31 deletions
Large diffs are not rendered by default.

e2e-nodejs/00-setup.mjs

Lines changed: 5 additions & 71 deletions
Original file line numberDiff line numberDiff line change
@@ -1,21 +1,13 @@
1-
import { LitNodeClient, uint8arrayFromString } from '@lit-protocol/lit-node-client';
1+
import { LitNodeClient } from '@lit-protocol/lit-node-client';
22
import LITCONFIG from '../lit.config.json' assert { type: 'json' };
33
import { fail } from '../tools/scripts/utils.mjs';
4-
import {LitContracts} from "@lit-protocol/contracts-sdk";
5-
import {ethers} from "ethers";
6-
import * as siwe from 'siwe';
74

8-
// ==================== ENV Loading ====================
9-
const network = process.env.NETWORK ?? LITCONFIG.TEST_ENV.litNetwork;
10-
const debug = process.env.DEBUG === 'true' ?? LITCONFIG.TEST_ENV.debug;
11-
const minNodeCount = LITCONFIG.TEST_ENV.minNodeCount;
12-
const checkSevAttestation = process.env.CHECK_SEV ?? false;
135

146
const client = new LitNodeClient({
15-
litNetwork: network,
16-
debug: debug,
17-
minNodeCount: minNodeCount,
18-
checkNodeAttestation: checkSevAttestation
7+
litNetwork: globalThis.LitCI.network,
8+
debug: globalThis.LitCI.debug,
9+
minNodeCount: globalThis.LitCI.minNodeCount,
10+
checkNodeAttestation: globalThis.LitCI.sevAttestation
1911
});
2012
await client.connect();
2113

@@ -28,63 +20,5 @@ if (LITCONFIG.CONTROLLER_AUTHSIG === undefined) {
2820
fail('Controller authSig cannot be empty');
2921
}
3022

31-
// ==================== SIWE Gen ====================
32-
const provider = new ethers.providers.JsonRpcProvider(
33-
LITCONFIG.CHRONICLE_RPC
34-
);
35-
36-
const wallet = new ethers.Wallet(LITCONFIG.CONTROLLER_PRIVATE_KEY, provider);
37-
const address = ethers.utils.getAddress(await wallet.getAddress());
38-
39-
// Craft the SIWE message
40-
const domain = 'localhost';
41-
const origin = 'https://localhost/login';
42-
const statement =
43-
'This is a test statement. You can put anything you want here.';
44-
const siweMessage = new siwe.SiweMessage({
45-
domain,
46-
address: address,
47-
statement,
48-
uri: origin,
49-
version: '1',
50-
chainId: 1,
51-
expirationTime: new Date(Date.now() + 1000 * 60).toISOString()
52-
});
53-
const messageToSign = siweMessage.prepareMessage();
54-
55-
// Sign the message and format the authSig
56-
const signature = await wallet.signMessage(messageToSign);
57-
58-
const authSig = {
59-
sig: signature,
60-
derivedVia: 'web3.eth.personal.sign',
61-
signedMessage: messageToSign,
62-
address: address,
63-
};
64-
console.log("generated siwe for test run: ", authSig);
65-
66-
// ==================== Global Vars ====================
67-
globalThis.LitCI = {};
68-
globalThis.LitCI.network = network;
69-
globalThis.LitCI.debug = debug;
70-
globalThis.LitCI.sevAttestation = checkSevAttestation;
71-
globalThis.LitCI.CONTROLLER_AUTHSIG = authSig;
72-
globalThis.LitCI.CONTROLLER_AUTHSIG_2 = LITCONFIG.CONTROLLER_AUTHSIG_2;
73-
74-
75-
globalThis.LitCI.PKP_INFO = {};
76-
globalThis.LitCI.PKP_INFO.publicKey = LITCONFIG.PKP_PUBKEY;
77-
78-
let contractClient = new LitContracts({
79-
signer: wallet,
80-
debug: process.env.DEBUG === 'true' ?? LITCONFIG.TEST_ENV.debug,
81-
network: process.env.NETWORK ?? LITCONFIG.TEST_ENV.litNetwork,
82-
});
83-
await contractClient.connect();
84-
85-
let res = await contractClient.pkpNftContractUtils.write.mint();
86-
globalThis.LitCI.PKP_INFO = res.pkp;
87-
88-
8923
// ==================== Success ====================
9024
export { client };

e2e-nodejs/README.md

Lines changed: 32 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,32 @@
1+
# End to End NodeJS testing
2+
3+
End to end testing environment for different operations on the Lit Network
4+
- Message singing
5+
- Transaction signing
6+
- Session signature generation / signing
7+
- Lit Action api testing
8+
- LitContracts testing
9+
- Concurrency operation tests
10+
- 1 signature tests
11+
- multi signature tests
12+
13+
14+
## Usage
15+
To run all tests in all groups you can use the command
16+
`yarn test:e2e:node`
17+
18+
Each test suite is contained in a single folder which is called a `group` groups can be filtered by the `filter` flag
19+
20+
`yarn test:e2e:node --group=lit-actions`
21+
In the above example, only tests in the `group-lit-actions` will run as group flags omit the `group` prefix
22+
23+
`yarn test:e2e:node --group=lit-actions --filter=1-sig`
24+
In the above example, we only run the `lit-actions` test group with a filter on the `test-lit-action-1-sig` which is reduced to `1-sig` from the `group` flag
25+
26+
## environment Configuration
27+
```
28+
NETWORK = cayenne | internalDev #Configures the network context for the test run
29+
DEBUG = true | false # Turns on or off logging
30+
CHECK_SEV = true | false # Configures checking of sev snp attestation reports
31+
MINT_NEW = true | false # Enables provisioning of new keys for the test run
32+
```

e2e-nodejs/group-connection/test-connection-internal-dev.mjs

Lines changed: 0 additions & 28 deletions
This file was deleted.

e2e-nodejs/group-connection/test-connection-threshold.mjs

Lines changed: 11 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -4,34 +4,36 @@ import LITCONFIG from '../../lit.config.json' assert { type: 'json' };
44
import { LitNodeClient } from '@lit-protocol/lit-node-client';
55
import {LitContracts} from '@lit-protocol/contracts-sdk';
66

7-
const LIT_NETWORK = 'cayenne';
7+
88

99
export async function main() {
1010
// ==================== Test Logic ====================
1111
const client = new LitNodeClient({
12-
litNetwork: LIT_NETWORK
12+
litNetwork: globalThis.LitCI.network,
13+
debug: LITCONFIG.TEST_ENV.debug,
14+
checkNodeAttestation: globalThis.LitCI.sevAttestation
1315
});
1416
await client.connect();
1517

1618
// ==================== Post-Validation ====================
1719
if (!client.ready) {
1820
return fail('client not ready');
1921
}
20-
if (client.config.litNetwork !== LIT_NETWORK) {
21-
return fail(`client not connected to ${LIT_NETWORK}`);
22+
if (client.config.litNetwork !== globalThis.LitCI.network) {
23+
return fail(`client not connected to ${globalThis.LitCI.network}`);
2224
}
2325

2426

25-
let threshold = await LitContracts.getMinNodeCount(LIT_NETWORK);
27+
let threshold = await LitContracts.getMinNodeCount(globalThis.LitCI.network);
2628
console.log(`threshold ${threshold}`);
27-
console.log(`config threshold ${client.config.threshold}`)
28-
client.config.threshold
29-
if (client.config.minNodeCount !== threshold) {
29+
console.log(`config threshold ${client.config.minNodeCount}`);
30+
31+
if (parseInt(client.config.minNodeCount, 10) !== parseInt(threshold, 10)) {
3032
return fail(`threshold does not match config threshold, network state diverged`);
3133
}
3234

3335
// ==================== Success ====================
34-
return success(`Connected to ${LIT_NETWORK}`);
36+
return success(`Connected to ${globalThis.LitCI.network}`);
3537
}
3638

3739
await testThis({ name: path.basename(import.meta.url), fn: main });

e2e-nodejs/group-connection/test-connection-cayenne.mjs renamed to e2e-nodejs/group-connection/test-connection.mjs

Lines changed: 6 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -8,23 +8,22 @@ const LIT_NETWORK = 'cayenne';
88
export async function main() {
99
// ==================== Test Logic ====================
1010
const client = new LitNodeClient({
11-
litNetwork: LIT_NETWORK,
12-
debug: process.env.DEBUG === 'true' ?? LITCONFIG.TEST_ENV.debug,
13-
minNodeCount: LITCONFIG.TEST_ENV.minNodeCount,
14-
checkNodeAttestation: false,
11+
litNetwork: globalThis.LitCI.network,
12+
debug: LITCONFIG.TEST_ENV.debug,
13+
checkNodeAttestation: globalThis.LitCI.sevAttestation
1514
});
1615
await client.connect();
1716

1817
// ==================== Post-Validation ====================
1918
if (!client.ready) {
2019
return fail('client not ready');
2120
}
22-
if (client.config.litNetwork !== LIT_NETWORK) {
23-
return fail(`client not connected to ${LIT_NETWORK}`);
21+
if (client.config.litNetwork !== globalThis.LitCI.network) {
22+
return fail(`client not connected to ${globalThis.LitCI.network}`);
2423
}
2524

2625
// ==================== Success ====================
27-
return success(`Connected to ${LIT_NETWORK}`);
26+
return success(`Connected to ${globalThis.LitCI.network}`);
2827
}
2928

3029
await testThis({ name: path.basename(import.meta.url), fn: main });

e2e-nodejs/group-lit-actions/test-lit-action-1-sig.mjs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -27,7 +27,8 @@ export async function main() {
2727
});
2828

2929
// ==================== Post-Validation ====================
30-
if (Object.keys(res.signatures).length <= 0) {
30+
31+
if (!res.signatures || Object.keys(res.signatures).length <= 0) {
3132
return fail(
3233
`should have at least 1 signature but received ${
3334
Object.keys(res.signatures).length
@@ -42,7 +43,6 @@ export async function main() {
4243
}
4344
}
4445
);
45-
4646
// ==================== Success ====================
4747
return success('Lit Action should log sign x1 sig');
4848
}

e2e-nodejs/group-lit-actions/test-lit-action-2-sigs.mjs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -41,7 +41,7 @@ export async function main() {
4141
});
4242

4343
// ==================== Post-Validation ====================
44-
if (Object.keys(res.signatures).length !== 2) {
44+
if (!res.signatures || Object.keys(res.signatures).length !== 2) {
4545
return fail(
4646
`should have 2 signatures but received ${
4747
Object.keys(res.signatures).length

e2e-nodejs/group-pkp-client/test-pkp-client-with-rpc.mjs

Lines changed: 5 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1,20 +1,19 @@
11
import path from 'path';
22
import { success, fail, testThis } from '../../tools/scripts/utils.mjs';
33
import LITCONFIG from '../../lit.config.json' assert { type: 'json' };
4-
import { client } from '../00-setup.mjs';
54
import { PKPClient } from '@lit-protocol/pkp-client';
65
import { ethers } from 'ethers';
76

87
export async function main() {
98
// ==================== Setup ====================
109
const pkpClient = new PKPClient({
11-
controllerAuthSig: LITCONFIG.CONTROLLER_AUTHSIG,
12-
pkpPubKey: LITCONFIG.PKP_PUBKEY,
10+
controllerAuthSig: globalThis.LitCI.CONTROLLER_AUTHSIG,
11+
pkpPubKey: globalThis.LitCI.PKP_INFO.publicKey,
1312
rpcs: {
1413
eth: LITCONFIG.CHRONICLE_RPC,
1514
cosmos: LITCONFIG.COSMOS_RPC,
1615
},
17-
litNetwork: LITCONFIG.TEST_ENV.litNetwork,
16+
litNetwork: globalThis.LitCI.network,
1817
cosmosAddressPrefix: 'cosmos',
1918
});
2019

@@ -60,9 +59,9 @@ export async function main() {
6059
return fail('signature should be defined');
6160
}
6261

63-
if (recoveredAddress !== LITCONFIG.PKP_ETH_ADDRESS) {
62+
if (recoveredAddress !== globalThis.LitCI.PKP_INFO.ethAddress) {
6463
return fail(
65-
`recoveredAddres should be ${LITCONFIG.PKP_ETH_ADDRESS}, got ${recoveredAddress}`
64+
`recoveredAddres should be ${globalThis.LitCI.PKP_INFO.ethAddress}, got ${recoveredAddress}`
6665
);
6766
}
6867

e2e-nodejs/group-pkp-client/test-pkp-client-without-rpc-sign-message.mjs

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -7,9 +7,9 @@ import { PKPClient } from '@lit-protocol/pkp-client';
77
export async function main() {
88
// ==================== Setup ====================
99
const pkpClient = new PKPClient({
10-
controllerAuthSig: LITCONFIG.CONTROLLER_AUTHSIG,
11-
pkpPubKey: LITCONFIG.PKP_PUBKEY,
12-
litNetwork: LITCONFIG.TEST_ENV.litNetwork,
10+
controllerAuthSig: globalThis.LitCI.CONTROLLER_AUTHSIG,
11+
pkpPubKey: globalThis.LitCI.PKP_INFO.publicKey,
12+
litNetwork: globalThis.LitCI.network,
1313
cosmosAddressPrefix: 'cosmos',
1414
});
1515

0 commit comments

Comments
 (0)