Skip to content

Commit

Permalink
Ref/small fixes (LIT-Protocol#275)
Browse files Browse the repository at this point in the history
* update tests to gen pkps in setup for certain networks

* logging and network config updates

* add dynamic address and abi boostraping depedning on the network type.

* move env loading out of setup

* change to read from global

* tweaks to test runners for jit pkps

* fixes to network context resolve, and logging

* add readme to e2e tests

* changes to network resolving

* remove unused imports

* add custom to lit network types

* fix staker contract resolving

* add pkp with auth method to test env bootstrapping

* fix failing tests from loader context

* add response checks

* fix test validation

* fix: typo

* fix to threshold resolve on chain

* fixes to threshold parsing from chain

* udpate readme

* remove comment

* fix up connection tests

* up expiration time in generated siwe

* change check from config assertion

---------

Co-authored-by: Ansonhkg <[email protected]>
  • Loading branch information
Bean and Ansonhkg authored Dec 5, 2023
1 parent 2f4a517 commit 3346f57
Show file tree
Hide file tree
Showing 32 changed files with 407 additions and 412 deletions.
61 changes: 32 additions & 29 deletions README.md

Large diffs are not rendered by default.

76 changes: 5 additions & 71 deletions e2e-nodejs/00-setup.mjs
Original file line number Diff line number Diff line change
@@ -1,21 +1,13 @@
import { LitNodeClient, uint8arrayFromString } from '@lit-protocol/lit-node-client';
import { LitNodeClient } from '@lit-protocol/lit-node-client';
import LITCONFIG from '../lit.config.json' assert { type: 'json' };
import { fail } from '../tools/scripts/utils.mjs';
import {LitContracts} from "@lit-protocol/contracts-sdk";
import {ethers} from "ethers";
import * as siwe from 'siwe';

// ==================== ENV Loading ====================
const network = process.env.NETWORK ?? LITCONFIG.TEST_ENV.litNetwork;
const debug = process.env.DEBUG === 'true' ?? LITCONFIG.TEST_ENV.debug;
const minNodeCount = LITCONFIG.TEST_ENV.minNodeCount;
const checkSevAttestation = process.env.CHECK_SEV ?? false;

const client = new LitNodeClient({
litNetwork: network,
debug: debug,
minNodeCount: minNodeCount,
checkNodeAttestation: checkSevAttestation
litNetwork: globalThis.LitCI.network,
debug: globalThis.LitCI.debug,
minNodeCount: globalThis.LitCI.minNodeCount,
checkNodeAttestation: globalThis.LitCI.sevAttestation
});
await client.connect();

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

// ==================== SIWE Gen ====================
const provider = new ethers.providers.JsonRpcProvider(
LITCONFIG.CHRONICLE_RPC
);

const wallet = new ethers.Wallet(LITCONFIG.CONTROLLER_PRIVATE_KEY, provider);
const address = ethers.utils.getAddress(await wallet.getAddress());

// Craft the SIWE message
const domain = 'localhost';
const origin = 'https://localhost/login';
const statement =
'This is a test statement. You can put anything you want here.';
const siweMessage = new siwe.SiweMessage({
domain,
address: address,
statement,
uri: origin,
version: '1',
chainId: 1,
expirationTime: new Date(Date.now() + 1000 * 60).toISOString()
});
const messageToSign = siweMessage.prepareMessage();

// Sign the message and format the authSig
const signature = await wallet.signMessage(messageToSign);

const authSig = {
sig: signature,
derivedVia: 'web3.eth.personal.sign',
signedMessage: messageToSign,
address: address,
};
console.log("generated siwe for test run: ", authSig);

// ==================== Global Vars ====================
globalThis.LitCI = {};
globalThis.LitCI.network = network;
globalThis.LitCI.debug = debug;
globalThis.LitCI.sevAttestation = checkSevAttestation;
globalThis.LitCI.CONTROLLER_AUTHSIG = authSig;
globalThis.LitCI.CONTROLLER_AUTHSIG_2 = LITCONFIG.CONTROLLER_AUTHSIG_2;


globalThis.LitCI.PKP_INFO = {};
globalThis.LitCI.PKP_INFO.publicKey = LITCONFIG.PKP_PUBKEY;

let contractClient = new LitContracts({
signer: wallet,
debug: process.env.DEBUG === 'true' ?? LITCONFIG.TEST_ENV.debug,
network: process.env.NETWORK ?? LITCONFIG.TEST_ENV.litNetwork,
});
await contractClient.connect();

let res = await contractClient.pkpNftContractUtils.write.mint();
globalThis.LitCI.PKP_INFO = res.pkp;


// ==================== Success ====================
export { client };
32 changes: 32 additions & 0 deletions e2e-nodejs/README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,32 @@
# End to End NodeJS testing

End to end testing environment for different operations on the Lit Network
- Message singing
- Transaction signing
- Session signature generation / signing
- Lit Action api testing
- LitContracts testing
- Concurrency operation tests
- 1 signature tests
- multi signature tests


## Usage
To run all tests in all groups you can use the command
`yarn test:e2e:node`

Each test suite is contained in a single folder which is called a `group` groups can be filtered by the `filter` flag

`yarn test:e2e:node --group=lit-actions`
In the above example, only tests in the `group-lit-actions` will run as group flags omit the `group` prefix

`yarn test:e2e:node --group=lit-actions --filter=1-sig`
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

## environment Configuration
```
NETWORK = cayenne | internalDev #Configures the network context for the test run
DEBUG = true | false # Turns on or off logging
CHECK_SEV = true | false # Configures checking of sev snp attestation reports
MINT_NEW = true | false # Enables provisioning of new keys for the test run
```
28 changes: 0 additions & 28 deletions e2e-nodejs/group-connection/test-connection-internal-dev.mjs

This file was deleted.

20 changes: 11 additions & 9 deletions e2e-nodejs/group-connection/test-connection-threshold.mjs
Original file line number Diff line number Diff line change
Expand Up @@ -4,34 +4,36 @@ import LITCONFIG from '../../lit.config.json' assert { type: 'json' };
import { LitNodeClient } from '@lit-protocol/lit-node-client';
import {LitContracts} from '@lit-protocol/contracts-sdk';

const LIT_NETWORK = 'cayenne';


export async function main() {
// ==================== Test Logic ====================
const client = new LitNodeClient({
litNetwork: LIT_NETWORK
litNetwork: globalThis.LitCI.network,
debug: LITCONFIG.TEST_ENV.debug,
checkNodeAttestation: globalThis.LitCI.sevAttestation
});
await client.connect();

// ==================== Post-Validation ====================
if (!client.ready) {
return fail('client not ready');
}
if (client.config.litNetwork !== LIT_NETWORK) {
return fail(`client not connected to ${LIT_NETWORK}`);
if (client.config.litNetwork !== globalThis.LitCI.network) {
return fail(`client not connected to ${globalThis.LitCI.network}`);
}


let threshold = await LitContracts.getMinNodeCount(LIT_NETWORK);
let threshold = await LitContracts.getMinNodeCount(globalThis.LitCI.network);
console.log(`threshold ${threshold}`);
console.log(`config threshold ${client.config.threshold}`)
client.config.threshold
if (client.config.minNodeCount !== threshold) {
console.log(`config threshold ${client.config.minNodeCount}`);

if (parseInt(client.config.minNodeCount, 10) !== parseInt(threshold, 10)) {
return fail(`threshold does not match config threshold, network state diverged`);
}

// ==================== Success ====================
return success(`Connected to ${LIT_NETWORK}`);
return success(`Connected to ${globalThis.LitCI.network}`);
}

await testThis({ name: path.basename(import.meta.url), fn: main });
Original file line number Diff line number Diff line change
Expand Up @@ -8,23 +8,22 @@ const LIT_NETWORK = 'cayenne';
export async function main() {
// ==================== Test Logic ====================
const client = new LitNodeClient({
litNetwork: LIT_NETWORK,
debug: process.env.DEBUG === 'true' ?? LITCONFIG.TEST_ENV.debug,
minNodeCount: LITCONFIG.TEST_ENV.minNodeCount,
checkNodeAttestation: false,
litNetwork: globalThis.LitCI.network,
debug: LITCONFIG.TEST_ENV.debug,
checkNodeAttestation: globalThis.LitCI.sevAttestation
});
await client.connect();

// ==================== Post-Validation ====================
if (!client.ready) {
return fail('client not ready');
}
if (client.config.litNetwork !== LIT_NETWORK) {
return fail(`client not connected to ${LIT_NETWORK}`);
if (client.config.litNetwork !== globalThis.LitCI.network) {
return fail(`client not connected to ${globalThis.LitCI.network}`);
}

// ==================== Success ====================
return success(`Connected to ${LIT_NETWORK}`);
return success(`Connected to ${globalThis.LitCI.network}`);
}

await testThis({ name: path.basename(import.meta.url), fn: main });
4 changes: 2 additions & 2 deletions e2e-nodejs/group-lit-actions/test-lit-action-1-sig.mjs
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,8 @@ export async function main() {
});

// ==================== Post-Validation ====================
if (Object.keys(res.signatures).length <= 0) {

if (!res.signatures || Object.keys(res.signatures).length <= 0) {
return fail(
`should have at least 1 signature but received ${
Object.keys(res.signatures).length
Expand All @@ -42,7 +43,6 @@ export async function main() {
}
}
);

// ==================== Success ====================
return success('Lit Action should log sign x1 sig');
}
Expand Down
2 changes: 1 addition & 1 deletion e2e-nodejs/group-lit-actions/test-lit-action-2-sigs.mjs
Original file line number Diff line number Diff line change
Expand Up @@ -41,7 +41,7 @@ export async function main() {
});

// ==================== Post-Validation ====================
if (Object.keys(res.signatures).length !== 2) {
if (!res.signatures || Object.keys(res.signatures).length !== 2) {
return fail(
`should have 2 signatures but received ${
Object.keys(res.signatures).length
Expand Down
11 changes: 5 additions & 6 deletions e2e-nodejs/group-pkp-client/test-pkp-client-with-rpc.mjs
Original file line number Diff line number Diff line change
@@ -1,20 +1,19 @@
import path from 'path';
import { success, fail, testThis } from '../../tools/scripts/utils.mjs';
import LITCONFIG from '../../lit.config.json' assert { type: 'json' };
import { client } from '../00-setup.mjs';
import { PKPClient } from '@lit-protocol/pkp-client';
import { ethers } from 'ethers';

export async function main() {
// ==================== Setup ====================
const pkpClient = new PKPClient({
controllerAuthSig: LITCONFIG.CONTROLLER_AUTHSIG,
pkpPubKey: LITCONFIG.PKP_PUBKEY,
controllerAuthSig: globalThis.LitCI.CONTROLLER_AUTHSIG,
pkpPubKey: globalThis.LitCI.PKP_INFO.publicKey,
rpcs: {
eth: LITCONFIG.CHRONICLE_RPC,
cosmos: LITCONFIG.COSMOS_RPC,
},
litNetwork: LITCONFIG.TEST_ENV.litNetwork,
litNetwork: globalThis.LitCI.network,
cosmosAddressPrefix: 'cosmos',
});

Expand Down Expand Up @@ -60,9 +59,9 @@ export async function main() {
return fail('signature should be defined');
}

if (recoveredAddress !== LITCONFIG.PKP_ETH_ADDRESS) {
if (recoveredAddress !== globalThis.LitCI.PKP_INFO.ethAddress) {
return fail(
`recoveredAddres should be ${LITCONFIG.PKP_ETH_ADDRESS}, got ${recoveredAddress}`
`recoveredAddres should be ${globalThis.LitCI.PKP_INFO.ethAddress}, got ${recoveredAddress}`
);
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -7,9 +7,9 @@ import { PKPClient } from '@lit-protocol/pkp-client';
export async function main() {
// ==================== Setup ====================
const pkpClient = new PKPClient({
controllerAuthSig: LITCONFIG.CONTROLLER_AUTHSIG,
pkpPubKey: LITCONFIG.PKP_PUBKEY,
litNetwork: LITCONFIG.TEST_ENV.litNetwork,
controllerAuthSig: globalThis.LitCI.CONTROLLER_AUTHSIG,
pkpPubKey: globalThis.LitCI.PKP_INFO.publicKey,
litNetwork: globalThis.LitCI.network,
cosmosAddressPrefix: 'cosmos',
});

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -8,9 +8,9 @@ import { ethers } from 'ethers';
export async function main() {
// ==================== Setup ====================
const pkpClient = new PKPClient({
controllerAuthSig: LITCONFIG.CONTROLLER_AUTHSIG,
pkpPubKey: LITCONFIG.PKP_PUBKEY,
litNetwork: LITCONFIG.TEST_ENV.litNetwork,
controllerAuthSig: globalThis.LitCI.CONTROLLER_AUTHSIG,
pkpPubKey: globalThis.LitCI.PKP_INFO.publicKey,
litNetwork: globalThis.LitCI.network,
cosmosAddressPrefix: 'cosmos',
});

Expand Down Expand Up @@ -56,9 +56,9 @@ export async function main() {
return fail('signature should be defined');
}

if (recoveredAddress !== LITCONFIG.PKP_ETH_ADDRESS) {
if (recoveredAddress !== globalThis.LitCI.PKP_INFO.ethAddress) {
return fail(
`recoveredAddres should be ${LITCONFIG.PKP_ETH_ADDRESS}, got ${recoveredAddress}`
`recoveredAddres should be ${globalThis.LitCI.PKP_INFO.ethAddress}, got ${recoveredAddress}`
);
}
// ==================== Success ====================
Expand Down
4 changes: 2 additions & 2 deletions e2e-nodejs/group-pkp-cosmos/test-pkp-cosmos-send-tx.mjs
Original file line number Diff line number Diff line change
Expand Up @@ -15,8 +15,8 @@ import {
export async function main() {
// ==================== Setup ====================
const cosmosWallet = new PKPCosmosWallet({
controllerAuthSig: LITCONFIG.CONTROLLER_AUTHSIG,
pkpPubKey: LITCONFIG.PKP_PUBKEY,
controllerAuthSig: globalThis.LitCI.CONTROLLER_AUTHSIG,
pkpPubKey: globalThis.LitCI.PKP_INFO.publicKey,
rpc: LITCONFIG.COSMOS_RPC,
// debug: true,
addressPrefix: 'cosmos',
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -18,8 +18,8 @@ const TX_HASH =
export async function main() {
// ==================== Setup ====================
const cosmosWallet = new PKPCosmosWallet({
controllerAuthSig: LITCONFIG.CONTROLLER_AUTHSIG,
pkpPubKey: LITCONFIG.PKP_PUBKEY,
controllerAuthSig: globalThis.LitCI.CONTROLLER_AUTHSIG,
pkpPubKey: globalThis.LitCI.PKP_INFO.publicKey,
rpc: LITCONFIG.COSMOS_RPC,
// debug: true,
addressPrefix: 'cosmos',
Expand Down
14 changes: 10 additions & 4 deletions e2e-nodejs/group-pkp-cosmos/test-pkp-cosmos.mjs
Original file line number Diff line number Diff line change
Expand Up @@ -7,8 +7,8 @@ import { PKPCosmosWallet } from '@lit-protocol/pkp-cosmos';
export async function main() {
// ==================== Setup ====================
const cosmosWallet = new PKPCosmosWallet({
controllerAuthSig: LITCONFIG.CONTROLLER_AUTHSIG,
pkpPubKey: LITCONFIG.PKP_PUBKEY,
controllerAuthSig: globalThis.LitCI.CONTROLLER_AUTHSIG,
pkpPubKey: globalThis.LitCI.PKP_INFO.publicKey,
rpc: LITCONFIG.COSMOS_RPC,
// debug: true,
addressPrefix: 'cosmos',
Expand All @@ -24,10 +24,16 @@ export async function main() {
return fail('litNodeClient should be ready');
}

if (pkpAccount.address !== LITCONFIG.PKP_COSMOS_ADDRESS) {
return fail(`Expecting PKP address to be ${LITCONFIG.PKP_COSMOS_ADDRESS}`);
if (!pkpAccount.address.includes('cosmos')) {
return fail(`expecting account address to include "cosmos"`);
}
if (pkpAccount.algo != 'secp256k1') {
return fail('algo does not match: ', 'secp256k1');
}

if (pkpAccount.pubkey.length !== 33) {
return fail('pubkey buffer expected length is incorrect recieved: ', pkpAccount.pubkey.length, "expected", 33);
}
// ==================== Success ====================
return success('PKPCosmosWallet should be able to getAccounts');
}
Expand Down
Loading

0 comments on commit 3346f57

Please sign in to comment.