Skip to content

Commit 4fdeddd

Browse files
committed
feat: export utils & add custom networkContext in TinnyEnv constructor
1 parent b976a41 commit 4fdeddd

File tree

2 files changed

+23
-9
lines changed

2 files changed

+23
-9
lines changed

local-tests/index.ts

Lines changed: 12 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,19 @@
11
import { TinnyEnvironment } from './setup/tinny-environment';
22
import { runInBand, runTestsParallel } from './setup/tinny-operations';
33
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';
47

5-
export { TinnyEnvironment, runInBand, runTestsParallel, tinnyTests };
8+
export {
9+
TinnyEnvironment,
10+
runInBand,
11+
runTestsParallel,
12+
tinnyTests,
13+
getEoaSessionSigs,
14+
getLitActionSessionSigs,
15+
getPkpSessionSigs,
16+
};
617

718
// Usage
819
// const devEnv = new TinnyEnvironment();

local-tests/setup/tinny-environment.ts

Lines changed: 11 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -24,6 +24,7 @@ import {
2424
console.log('checking env', process.env['DEBUG']);
2525
export class TinnyEnvironment {
2626
public network: LIT_NETWORK_VALUES;
27+
public customNetworkContext: any;
2728

2829
/**
2930
* Environment variables used in the process.
@@ -36,7 +37,7 @@ export class TinnyEnvironment {
3637
DEBUG: process.env['DEBUG'] === 'true',
3738
REQUEST_PER_KILOSECOND:
3839
parseInt(process.env['REQUEST_PER_KILOSECOND']) ||
39-
(process.env['NETWORK'] as LIT_NETWORK_VALUES) === 'datil-dev'
40+
(process.env['NETWORK'] as LIT_NETWORK_VALUES) === 'datil-dev'
4041
? 1
4142
: 200,
4243
LIT_RPC_URL: process.env['LIT_RPC_URL'],
@@ -100,7 +101,10 @@ export class TinnyEnvironment {
100101
private _shivaClient: ShivaClient = new ShivaClient();
101102
private _contractContext: LitContractContext | LitContractResolverContext;
102103

103-
constructor(override?: Partial<ProcessEnvs>) {
104+
constructor(override?: Partial<ProcessEnvs> & { customNetworkContext?: any }) {
105+
106+
this.customNetworkContext = override?.customNetworkContext;
107+
104108
// Merge default processEnvs with custom overrides
105109
this.processEnvs = {
106110
...this.processEnvs,
@@ -120,8 +124,7 @@ export class TinnyEnvironment {
120124

121125
if (Object.values(LIT_NETWORK).indexOf(this.network) === -1) {
122126
throw new Error(
123-
`Invalid network environment ${
124-
this.network
127+
`Invalid network environment ${this.network
125128
}. Please use one of ${Object.values(LIT_NETWORK)}`
126129
);
127130
}
@@ -244,7 +247,7 @@ export class TinnyEnvironment {
244247

245248
if (this.network === LIT_NETWORK.Custom || centralisation === 'unknown') {
246249
const networkContext =
247-
this?.testnet?.ContractContext ?? this._contractContext;
250+
this.customNetworkContext || (this?.testnet?.ContractContext ?? this._contractContext);
248251
this.litNodeClient = new LitNodeClient({
249252
litNetwork: LIT_NETWORK.Custom,
250253
rpcUrl: this.rpc,
@@ -350,8 +353,8 @@ export class TinnyEnvironment {
350353
* Creates a random person.
351354
* @returns A promise that resolves to the created person.
352355
*/
353-
async createRandomPerson() {
354-
return await this.createNewPerson('Alice');
356+
async createRandomPerson(name?: string) {
357+
return await this.createNewPerson(name || 'Alice');
355358
}
356359

357360
setUnavailable = (network: LIT_NETWORK_VALUES) => {
@@ -382,7 +385,7 @@ export class TinnyEnvironment {
382385

383386
await this.testnet.getTestnetConfig();
384387
} else if (this.network === LIT_NETWORK.Custom) {
385-
const context = await import('./networkContext.json');
388+
const context = this.customNetworkContext || await import('./networkContext.json');
386389
this._contractContext = context;
387390
}
388391

0 commit comments

Comments
 (0)