Skip to content

Commit ac2b87f

Browse files
committed
Merge branch 'feat/tinny-standalone' into feature/lit-3748-naga
2 parents 741761a + 5515e15 commit ac2b87f

File tree

88 files changed

+4504
-122
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

88 files changed

+4504
-122
lines changed

.gitignore

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,7 @@
66
/out-tsc
77
**/dist
88
**/out-tsc
9+
local-tests/**/*.js
910

1011
# dependencies
1112
node_modules

README.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -66,6 +66,7 @@ If you're a tech-savvy user and wish to utilize only specific submodules that ou
6666
| [@lit-protocol/core](https://github.com/LIT-Protocol/js-sdk/tree/master/packages/core) | ![core](https://img.shields.io/badge/-universal-8A6496 'core') | <a target="_blank" href="https://www.npmjs.com/package/@lit-protocol/core"><img src="https://img.shields.io/npm/v/@lit-protocol/core"/></a> |
6767
| [@lit-protocol/crypto](https://github.com/LIT-Protocol/js-sdk/tree/master/packages/crypto) | ![crypto](https://img.shields.io/badge/-universal-8A6496 'crypto') | <a target="_blank" href="https://www.npmjs.com/package/@lit-protocol/crypto"><img src="https://img.shields.io/npm/v/@lit-protocol/crypto"/></a> |
6868
| [@lit-protocol/encryption](https://github.com/LIT-Protocol/js-sdk/tree/master/packages/encryption) | ![encryption](https://img.shields.io/badge/-universal-8A6496 'encryption') | <a target="_blank" href="https://www.npmjs.com/package/@lit-protocol/encryption"><img src="https://img.shields.io/npm/v/@lit-protocol/encryption"/></a> |
69+
| [@lit-protocol/event-listener](https://github.com/LIT-Protocol/js-sdk/tree/master/packages/event-listener) | ![event-listener](https://img.shields.io/badge/-universal-8A6496 'event-listener') | <a target="_blank" href="https://www.npmjs.com/package/@lit-protocol/event-listener"><img src="https://img.shields.io/npm/v/@lit-protocol/event-listener"/></a> |
6970
| [@lit-protocol/logger](https://github.com/LIT-Protocol/js-sdk/tree/master/packages/logger) | ![logger](https://img.shields.io/badge/-universal-8A6496 'logger') | <a target="_blank" href="https://www.npmjs.com/package/@lit-protocol/logger"><img src="https://img.shields.io/npm/v/@lit-protocol/logger"/></a> |
7071
| [@lit-protocol/misc](https://github.com/LIT-Protocol/js-sdk/tree/master/packages/misc) | ![misc](https://img.shields.io/badge/-universal-8A6496 'misc') | <a target="_blank" href="https://www.npmjs.com/package/@lit-protocol/misc"><img src="https://img.shields.io/npm/v/@lit-protocol/misc"/></a> |
7172
| [@lit-protocol/nacl](https://github.com/LIT-Protocol/js-sdk/tree/master/packages/nacl) | ![nacl](https://img.shields.io/badge/-universal-8A6496 'nacl') | <a target="_blank" href="https://www.npmjs.com/package/@lit-protocol/nacl"><img src="https://img.shields.io/npm/v/@lit-protocol/nacl"/></a> |

local-tests/build.mjs

Lines changed: 6 additions & 30 deletions
Original file line numberDiff line numberDiff line change
@@ -1,18 +1,19 @@
11
import * as esbuild from 'esbuild';
22
import { nodeExternalsPlugin } from 'esbuild-node-externals';
33
import fs from 'fs';
4-
5-
const TEST_DIR = 'local-tests';
4+
import { fileURLToPath } from 'url';
5+
import { dirname, resolve } from 'path';
66

77
/**
88
* Builds the project using esbuild.
99
* @returns {Promise<void>} A promise that resolves when the build is complete.
1010
*/
1111
export const build = async () => {
1212
await esbuild.build({
13-
entryPoints: [`${TEST_DIR}/test.ts`],
14-
outfile: `./${TEST_DIR}/build/test.mjs`,
13+
entryPoints: [fileURLToPath(new URL('./index.ts', import.meta.url))],
14+
outfile: fileURLToPath(new URL('./index.js', import.meta.url)),
1515
bundle: true,
16+
globalName: 'tinnySdk',
1617
plugins: [
1718
nodeExternalsPlugin({
1819
allowList: [
@@ -27,39 +28,14 @@ export const build = async () => {
2728
platform: 'node',
2829
target: 'esnext',
2930
format: 'esm',
30-
inject: [`./${TEST_DIR}/shim.mjs`],
31+
inject: [fileURLToPath(new URL('./shim.mjs', import.meta.url))],
3132
mainFields: ['module', 'main'],
3233
});
3334
};
3435

35-
/**
36-
* Inserts a polyfill at the beginning of a file.
37-
* The polyfill ensures that the global `fetch` function is available.
38-
* @returns {void}
39-
*/
40-
export const postBuildPolyfill = () => {
41-
try {
42-
const file = fs.readFileSync(`./${TEST_DIR}/build/test.mjs`, 'utf8');
43-
const content = `import fetch from 'node-fetch';
44-
try {
45-
if (!globalThis.fetch) {
46-
globalThis.fetch = fetch;
47-
}
48-
} catch (error) {
49-
console.error('❌ Error in polyfill', error);
50-
}
51-
`;
52-
const newFile = content + file;
53-
fs.writeFileSync(`./${TEST_DIR}/build/test.mjs`, newFile);
54-
} catch (e) {
55-
throw new Error(`Error in postBuildPolyfill: ${e}`);
56-
}
57-
};
58-
5936
// Go!
6037
(async () => {
6138
const start = Date.now();
6239
await build();
63-
postBuildPolyfill();
6440
console.log(`[build.mjs] 🚀 Build time: ${Date.now() - start}ms`);
6541
})();

local-tests/index.ts

Lines changed: 33 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,33 @@
1+
import { TinnyEnvironment } from './setup/tinny-environment';
2+
import { runInBand, runTestsParallel } from './setup/tinny-operations';
3+
import * as tinnyTests from './tests';
4+
import { getEoaSessionSigs } from './setup/session-sigs/get-eoa-session-sigs';
5+
import { getLitActionSessionSigs } from './setup/session-sigs/get-lit-action-session-sigs';
6+
import { getPkpSessionSigs } from './setup/session-sigs/get-pkp-session-sigs';
7+
import { AccessControlConditions } from './setup/accs/accs';
8+
9+
export {
10+
TinnyEnvironment,
11+
runInBand,
12+
runTestsParallel,
13+
tinnyTests,
14+
getEoaSessionSigs,
15+
getLitActionSessionSigs,
16+
getPkpSessionSigs,
17+
AccessControlConditions
18+
};
19+
20+
// Usage
21+
// const devEnv = new TinnyEnvironment();
22+
23+
// await devEnv.init();
24+
25+
// const testConfig = {
26+
// tests: {
27+
// testEthAuthSigToEncryptDecryptString,
28+
// },
29+
// devEnv,
30+
// }
31+
32+
// const res = await runTestsParallel(testConfig);
33+
// console.log("res:", res);

local-tests/package.json

Lines changed: 97 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,97 @@
1+
{
2+
"name": "@lit-protocol/tinny",
3+
"version": "0.0.5",
4+
"description": "A package to run the test script for Lit Protocol with custom commands",
5+
"type": "module",
6+
"main": "./index.js",
7+
"typings": "./index.ts",
8+
"license": "MIT",
9+
"author": "Anson (https://github.com/ansonhkg)",
10+
"publishConfig": {
11+
"access": "public",
12+
"directory": "./"
13+
},
14+
"dependencies": {
15+
"@cosmjs/amino": "0.30.1",
16+
"@cosmjs/crypto": "0.30.1",
17+
"@cosmjs/encoding": "0.30.1",
18+
"@cosmjs/proto-signing": "0.30.1",
19+
"@cosmjs/stargate": "0.30.1",
20+
"@cypress/code-coverage": "^3.10.0",
21+
"@cypress/react": "^6.2.0",
22+
"@cypress/webpack-dev-server": "^2.3.0",
23+
"@lit-protocol/accs-schemas": "0.0.7",
24+
"@metamask/eth-sig-util": "5.0.2",
25+
"@mysten/sui.js": "^0.37.1",
26+
"@playwright/test": "^1.25.2",
27+
"@simplewebauthn/browser": "^7.2.0",
28+
"@simplewebauthn/typescript-types": "^7.0.0",
29+
"@spruceid/siwe-parser": "2.0.0",
30+
"@synthetixio/js": "^2.41.0",
31+
"@testing-library/cypress": "^8.0.3",
32+
"@testing-library/react": "^13.4.0",
33+
"@types/testing-library__cypress": "^5.0.9",
34+
"@walletconnect/core": "2.9.2",
35+
"@walletconnect/ethereum-provider": "2.9.2",
36+
"@walletconnect/jsonrpc-utils": "1.0.8",
37+
"@walletconnect/modal": "2.6.1",
38+
"@walletconnect/types": "2.9.2",
39+
"@walletconnect/utils": "2.9.2",
40+
"@walletconnect/web3wallet": "1.8.8",
41+
"@websaam/nx-esbuild": "^0.0.1",
42+
"ajv": "^8.12.0",
43+
"axios": "^0.27.2",
44+
"base64url": "^3.0.1",
45+
"bitcoinjs-lib": "^6.1.0",
46+
"blockstore-core": "^3.0.0",
47+
"browserify-zlib": "^0.2.0",
48+
"bs58": "^5.0.0",
49+
"bytes32": "^0.0.3",
50+
"cbor-web": "^9.0.1",
51+
"commander": "^9.4.0",
52+
"concurrently": "^7.4.0",
53+
"core-js": "^3.6.5",
54+
"cross-fetch": "3.1.4",
55+
"crypto-browserify": "^3.12.0",
56+
"cypress-wait-until": "^1.7.2",
57+
"cypress-watch-and-reload": "^1.10.3",
58+
"date-and-time": "^2.4.1",
59+
"dotenv": "^16.0.2",
60+
"dotenv-parse-variables": "^2.0.0",
61+
"download": "^8.0.0",
62+
"ethers": "^5.7.1",
63+
"etherscan-api": "^10.2.0",
64+
"find-config": "^1.0.0",
65+
"g": "^2.0.1",
66+
"https-browserify": "^1.0.0",
67+
"jose": "^4.14.4",
68+
"jszip": "^3.10.1",
69+
"micromodal": "^0.4.10",
70+
"multiformats": "^9.7.1",
71+
"nanoid": "3.3.4",
72+
"next": "13.3.0",
73+
"react": "18.0.0",
74+
"react-dom": "18.0.0",
75+
"regenerator-runtime": "0.13.7",
76+
"secp256k1": "^5.0.0",
77+
"serve": "^14.0.1",
78+
"siwe": "^2.0.5",
79+
"siwe-recap": "0.0.2-alpha.0",
80+
"stream-browserify": "^3.0.0",
81+
"stream-http": "^3.2.0",
82+
"synthetix-js": "^2.74.1",
83+
"tslib": "^2.3.0",
84+
"tweetnacl": "^1.0.3",
85+
"tweetnacl-util": "^0.15.1",
86+
"uint8arrays": "^4.0.3",
87+
"@openagenda/verror": "^3.1.4",
88+
"ipfs-unixfs-importer": "12.0.1",
89+
"@solana/web3.js": "^1.95.3",
90+
"bech32": "^2.0.0",
91+
"pako": "^2.1.0",
92+
"@lit-protocol/misc": "^7.0.0",
93+
"@lit-protocol/lit-node-client": "^7.0.0",
94+
"@lit-protocol/lit-auth-client": "^7.0.0",
95+
"@lit-protocol/contracts": "^0.0.71"
96+
}
97+
}

local-tests/setup/tinny-config.ts

Lines changed: 0 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -62,11 +62,6 @@ export interface ProcessEnvs {
6262
*/
6363
LIT_RPC_URL: string;
6464

65-
/**
66-
* This is usually used when you're running tests locally depending how many nodes you are running.
67-
*/
68-
BOOTSTRAP_URLS: string[];
69-
7065
/**
7166
* The list of private keys to use for testing.
7267
*/

local-tests/setup/tinny-environment.ts

Lines changed: 27 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -37,6 +37,7 @@ const DEFAULT_ANVIL_PRIVATE_KEYS = [
3737

3838
export class TinnyEnvironment {
3939
public network: LIT_NETWORK_VALUES;
40+
public customNetworkContext: any;
4041

4142
/**
4243
* Environment variables used in the process.
@@ -49,17 +50,12 @@ export class TinnyEnvironment {
4950
DEBUG: process.env['DEBUG'] === 'true',
5051
REQUEST_PER_KILOSECOND:
5152
parseInt(process.env['REQUEST_PER_KILOSECOND']) ||
52-
(process.env['NETWORK'] as LIT_NETWORK_VALUES) === 'datil-dev'
53+
(process.env['NETWORK'] as LIT_NETWORK_VALUES) === 'datil-dev'
5354
? 1
5455
: 200,
5556
LIT_RPC_URL: process.env['LIT_RPC_URL'],
5657
WAIT_FOR_KEY_INTERVAL:
5758
parseInt(process.env['WAIT_FOR_KEY_INTERVAL']) || 3000,
58-
BOOTSTRAP_URLS: process.env['BOOTSTRAP_URLS']?.split(',') || [
59-
'http://127.0.0.1:7470',
60-
'http://127.0.0.1:7471',
61-
'http://127.0.0.1:7472',
62-
],
6359
TIME_TO_RELEASE_KEY: parseInt(process.env['TIME_TO_RELEASE_KEY']) || 10000,
6460
RUN_IN_BAND: process.env['RUN_IN_BAND'] === 'true',
6561
RUN_IN_BAND_INTERVAL: parseInt(process.env['RUN_IN_BAND_INTERVAL']) || 5000,
@@ -111,15 +107,31 @@ export class TinnyEnvironment {
111107
private _shivaClient: ShivaClient = new ShivaClient();
112108
private _contractContext: LitContractContext | LitContractResolverContext;
113109

114-
constructor(network?: LIT_NETWORK_VALUES) {
110+
constructor(override?: Partial<ProcessEnvs> & { customNetworkContext?: any }) {
111+
112+
this.customNetworkContext = override?.customNetworkContext;
113+
114+
// Merge default processEnvs with custom overrides
115+
this.processEnvs = {
116+
...this.processEnvs,
117+
...override,
118+
};
119+
120+
// if there are only 1 private key, duplicate it to make it 10 cus we might not have enough
121+
// for the setup process
122+
if (this.processEnvs.PRIVATE_KEYS.length === 1) {
123+
this.processEnvs.PRIVATE_KEYS = new Array(10).fill(
124+
this.processEnvs.PRIVATE_KEYS[0]
125+
);
126+
}
127+
115128
// -- setup network
116-
this.network = network || this.processEnvs.NETWORK;
129+
this.network = override.NETWORK || this.processEnvs.NETWORK;
117130

118131
if (Object.values(LIT_NETWORK).indexOf(this.network) === -1) {
119132
throw new Error(
120-
`Invalid network environment. Please use one of ${Object.values(
121-
LIT_NETWORK
122-
)}`
133+
`Invalid network environment ${this.network
134+
}. Please use one of ${Object.values(LIT_NETWORK)}`
123135
);
124136
}
125137

@@ -241,7 +253,7 @@ export class TinnyEnvironment {
241253

242254
if (this.network === LIT_NETWORK.Custom || centralisation === 'unknown') {
243255
const networkContext =
244-
this?.testnet?.ContractContext ?? this._contractContext;
256+
this.customNetworkContext || (this?.testnet?.ContractContext ?? this._contractContext);
245257
this.litNodeClient = new LitNodeClient({
246258
litNetwork: LIT_NETWORK.Custom,
247259
rpcUrl: this.rpc,
@@ -347,8 +359,8 @@ export class TinnyEnvironment {
347359
* Creates a random person.
348360
* @returns A promise that resolves to the created person.
349361
*/
350-
async createRandomPerson() {
351-
return await this.createNewPerson('Alice');
362+
async createRandomPerson(name?: string) {
363+
return await this.createNewPerson(name || 'Alice');
352364
}
353365

354366
setUnavailable = (network: LIT_NETWORK_VALUES) => {
@@ -379,7 +391,7 @@ export class TinnyEnvironment {
379391

380392
await this.testnet.getTestnetConfig();
381393
} else if (this.network === LIT_NETWORK.Custom) {
382-
const context = await import('./networkContext.json');
394+
const context = this.customNetworkContext || await import('./networkContext.json');
383395
this._contractContext = context;
384396
}
385397

local-tests/test.ts

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -108,7 +108,6 @@ import { testBatchGeneratePrivateKeys } from './tests/wrapped-keys/testBatchGene
108108
import { testFailBatchGeneratePrivateKeysAtomic } from './tests/wrapped-keys/testFailStoreEncryptedKeyBatchIsAtomic';
109109

110110
import { setLitActionsCodeToLocal } from './tests/wrapped-keys/util';
111-
import { testUseEoaSessionSigsToRequestSingleResponse } from './tests/testUseEoaSessionSigsToRequestSingleResponse';
112111

113112
// Use the current LIT action code to test against
114113
setLitActionsCodeToLocal();
@@ -316,7 +315,9 @@ setLitActionsCodeToLocal();
316315
},
317316
devEnv,
318317
};
318+
319319
let res;
320+
320321
if (devEnv.processEnvs.RUN_IN_BAND) {
321322
res = await runInBand(testConfig);
322323
} else {

0 commit comments

Comments
 (0)