Skip to content

Commit

Permalink
feat: export utils & add custom networkContext in TinnyEnv constructor
Browse files Browse the repository at this point in the history
  • Loading branch information
Ansonhkg committed Dec 30, 2024
1 parent b976a41 commit 4fdeddd
Show file tree
Hide file tree
Showing 2 changed files with 23 additions and 9 deletions.
13 changes: 12 additions & 1 deletion local-tests/index.ts
Original file line number Diff line number Diff line change
@@ -1,8 +1,19 @@
import { TinnyEnvironment } from './setup/tinny-environment';
import { runInBand, runTestsParallel } from './setup/tinny-operations';
import * as tinnyTests from './tests';
import { getEoaSessionSigs } from './setup/session-sigs/get-eoa-session-sigs';
import { getLitActionSessionSigs } from './setup/session-sigs/get-lit-action-session-sigs';
import { getPkpSessionSigs } from './setup/session-sigs/get-pkp-session-sigs';

export { TinnyEnvironment, runInBand, runTestsParallel, tinnyTests };
export {
TinnyEnvironment,
runInBand,
runTestsParallel,
tinnyTests,
getEoaSessionSigs,
getLitActionSessionSigs,
getPkpSessionSigs,
};

// Usage
// const devEnv = new TinnyEnvironment();
Expand Down
19 changes: 11 additions & 8 deletions local-tests/setup/tinny-environment.ts
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,7 @@ import {
console.log('checking env', process.env['DEBUG']);
export class TinnyEnvironment {
public network: LIT_NETWORK_VALUES;
public customNetworkContext: any;

/**
* Environment variables used in the process.
Expand All @@ -36,7 +37,7 @@ export class TinnyEnvironment {
DEBUG: process.env['DEBUG'] === 'true',
REQUEST_PER_KILOSECOND:
parseInt(process.env['REQUEST_PER_KILOSECOND']) ||
(process.env['NETWORK'] as LIT_NETWORK_VALUES) === 'datil-dev'
(process.env['NETWORK'] as LIT_NETWORK_VALUES) === 'datil-dev'
? 1
: 200,
LIT_RPC_URL: process.env['LIT_RPC_URL'],
Expand Down Expand Up @@ -100,7 +101,10 @@ export class TinnyEnvironment {
private _shivaClient: ShivaClient = new ShivaClient();
private _contractContext: LitContractContext | LitContractResolverContext;

constructor(override?: Partial<ProcessEnvs>) {
constructor(override?: Partial<ProcessEnvs> & { customNetworkContext?: any }) {

this.customNetworkContext = override?.customNetworkContext;

// Merge default processEnvs with custom overrides
this.processEnvs = {
...this.processEnvs,
Expand All @@ -120,8 +124,7 @@ export class TinnyEnvironment {

if (Object.values(LIT_NETWORK).indexOf(this.network) === -1) {
throw new Error(
`Invalid network environment ${
this.network
`Invalid network environment ${this.network
}. Please use one of ${Object.values(LIT_NETWORK)}`
);
}
Expand Down Expand Up @@ -244,7 +247,7 @@ export class TinnyEnvironment {

if (this.network === LIT_NETWORK.Custom || centralisation === 'unknown') {
const networkContext =
this?.testnet?.ContractContext ?? this._contractContext;
this.customNetworkContext || (this?.testnet?.ContractContext ?? this._contractContext);
this.litNodeClient = new LitNodeClient({
litNetwork: LIT_NETWORK.Custom,
rpcUrl: this.rpc,
Expand Down Expand Up @@ -350,8 +353,8 @@ export class TinnyEnvironment {
* Creates a random person.
* @returns A promise that resolves to the created person.
*/
async createRandomPerson() {
return await this.createNewPerson('Alice');
async createRandomPerson(name?: string) {
return await this.createNewPerson(name || 'Alice');
}

setUnavailable = (network: LIT_NETWORK_VALUES) => {
Expand Down Expand Up @@ -382,7 +385,7 @@ export class TinnyEnvironment {

await this.testnet.getTestnetConfig();
} else if (this.network === LIT_NETWORK.Custom) {
const context = await import('./networkContext.json');
const context = this.customNetworkContext || await import('./networkContext.json');
this._contractContext = context;
}

Expand Down

0 comments on commit 4fdeddd

Please sign in to comment.