Skip to content

Feat/suport localchain network context from shiva #498

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
37 changes: 37 additions & 0 deletions local-tests/setup/shiva-client.ts
Original file line number Diff line number Diff line change
@@ -1,3 +1,6 @@
import { LitContractResolverContext } from '@lit-protocol/types';
import { ethers } from 'ethers';

export interface ShivaEnvs {
/**
* If runnnig no localchain this flag will stop the running testnet when the test
Expand Down Expand Up @@ -44,6 +47,40 @@ export class TestnetClient {
this._id = id;
}

/*
Returns the testnet information
pub struct TestNetInfo {
pub contract_addresses: ContractAddresses,
pub validator_addresses: Vec<String>,
pub contract_resolver_abi: String,
pub rpc_url: String,
pub epoch_length: i32,
}
*/
get Info(): any | undefined {
return this._info;
}

get ContractContext(): LitContractResolverContext | undefined {
const testNetConfig = this.Info;
if (!testNetConfig) {
return undefined;
}

const contractResolverAbi: string = testNetConfig.contractResolverAbi;
const contractResolverAddress =
testNetConfig.contractAddresses[`contract_resolver`];
const networkContext = {
abi: JSON.parse(contractResolverAbi),
resolverAddress: contractResolverAddress,
provider: new ethers.providers.JsonRpcProvider(
`http://${testNetConfig.rpcUrl}`
),
environment: 0, // test deployment uses env value 0 in test common
};
return networkContext;
}

/**
* Polls a given testnet for the ACTIVE state
* polls on a 500 milisecond interval
Expand Down
2 changes: 2 additions & 0 deletions local-tests/setup/tinny-config.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
import { LitNodeClient } from '@lit-protocol/lit-node-client';
import { LitContractResolverContext } from '@lit-protocol/types';

export enum LIT_TESTNET {
LOCALCHAIN = 'localchain',
Expand Down Expand Up @@ -96,4 +97,5 @@ export interface TinnyEnvConfig {
litNodeClient: LitNodeClient;
network: LIT_TESTNET;
processEnvs: ProcessEnvs;
contractContext?: LitContractResolverContext;
}
11 changes: 7 additions & 4 deletions local-tests/setup/tinny-environment.ts
Original file line number Diff line number Diff line change
Expand Up @@ -4,11 +4,11 @@ import { LitContracts } from '@lit-protocol/contracts-sdk';
import {
AuthSig,
CosmosAuthSig,
LitContractContext,
LitContractResolverContext,
SolanaAuthSig,
} from '@lit-protocol/types';
import { TinnyPerson } from './tinny-person';
import networkContext from './networkContext.json';

import { ethers } from 'ethers';
import { createSiweMessage, generateAuthSig } from '@lit-protocol/auth-helpers';
import { ShivaClient, TestnetClient } from './shiva-client';
Expand Down Expand Up @@ -196,13 +196,14 @@ export class TinnyEnvironment {
console.log('[𐬺🧪 Tinny Environment𐬺] Setting up LitNodeClient');

if (this.network === LIT_TESTNET.LOCALCHAIN) {
const networkContext = this._testnet.ContractContext;
this.litNodeClient = new LitNodeClient({
litNetwork: 'custom',
bootstrapUrls: this.processEnvs.BOOTSTRAP_URLS,
rpcUrl: this.processEnvs.LIT_RPC_URL,
debug: this.processEnvs.DEBUG,
checkNodeAttestation: false, // disable node attestation check for local testing
contractContext: networkContext as LitContractContext,
contractContext: networkContext,
});
} else if (this.network === LIT_TESTNET.MANZANO) {
this.litNodeClient = new LitNodeClient({
Expand Down Expand Up @@ -254,6 +255,7 @@ export class TinnyEnvironment {
litNodeClient: this.litNodeClient,
network: this.network,
processEnvs: this.processEnvs,
contractContext: this?._testnet?.ContractContext ?? undefined,
};
}

Expand Down Expand Up @@ -379,11 +381,12 @@ export class TinnyEnvironment {
* ====================================
*/
if (this.network === LIT_TESTNET.LOCALCHAIN) {
const networkContext = this._testnet.ContractContext;
this.contractsClient = new LitContracts({
signer: wallet,
debug: this.processEnvs.DEBUG,
rpc: this.processEnvs.LIT_RPC_URL, // anvil rpc
customContext: networkContext as unknown as LitContractContext,
customContext: networkContext,
});
} else {
// TODO: This wallet should be cached somehwere and reused to create delegation signatures.
Expand Down
2 changes: 1 addition & 1 deletion local-tests/setup/tinny-person.ts
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,6 @@ import {
import { ethers } from 'ethers';
import { LIT_TESTNET, PKPInfo, TinnyEnvConfig } from './tinny-config';
import { EthWalletProvider } from '@lit-protocol/lit-auth-client';
import networkContext from './networkContext.json';
import { AuthMethodScope } from '@lit-protocol/constants';

export class TinnyPerson {
Expand Down Expand Up @@ -102,6 +101,7 @@ export class TinnyPerson {
// * ====================================
// */
if (this.envConfig.network === LIT_TESTNET.LOCALCHAIN) {
const networkContext = this.envConfig.contractContext;
this.contractsClient = new LitContracts({
signer: this.wallet,
debug: this.envConfig.processEnvs.DEBUG,
Expand Down
Loading