Skip to content

Commit 0f1baec

Browse files
committed
refactor(WIP): making shiva work
1 parent 3ab3ad6 commit 0f1baec

File tree

1 file changed

+60
-60
lines changed

1 file changed

+60
-60
lines changed

packages/e2e/src/helper/shiva-client.ts

Lines changed: 60 additions & 60 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,3 @@
1-
import type { LitClientInstance } from '../types';
2-
31
/**
42
* Options used when Shiva spins up a brand-new testnet instance.
53
* Values mirror the Rust manager contract; all fields are optional for our wrapper.
@@ -70,12 +68,12 @@ export type ShivaClient = {
7068
baseUrl: string;
7169
testnetId: string;
7270
/** Fetch a one-off snapshot of the Lit context and per-node epochs. */
73-
inspectEpoch: () => Promise<EpochSnapshot>;
71+
// inspectEpoch: () => Promise<EpochSnapshot>;
7472
/**
7573
* Poll the Lit client until it reports an epoch different from {@link WaitForEpochOptions.baselineEpoch}.
7674
* Useful immediately after triggering an epoch change via Shiva.
7775
*/
78-
waitForEpochChange: (options: WaitForEpochOptions) => Promise<EpochSnapshot>;
76+
// waitForEpochChange: (options: WaitForEpochOptions) => Promise<EpochSnapshot>;
7977
/** Invoke Shiva's `/test/action/transition/epoch/wait/<id>` and wait for completion. */
8078
transitionEpochAndWait: () => Promise<boolean>;
8179
/** Stop a random node and wait for the subsequent epoch change. */
@@ -153,7 +151,7 @@ const getTestnetIds = async (baseUrl: string): Promise<string[]> => {
153151
return (await response.json()) as string[];
154152
};
155153

156-
const ensureTestnetId = async (
154+
const getOrCreateTestnetId = async (
157155
baseUrl: string,
158156
providedId?: string,
159157
createRequest?: TestNetCreateRequest
@@ -179,79 +177,81 @@ const ensureTestnetId = async (
179177
});
180178

181179
if (!response.testnet_id) {
182-
throw new Error('Shiva create testnet response did not include testnet_id');
180+
throw new Error(
181+
'Shiva create testnet response did not include testnet_id. Received: ' +
182+
JSON.stringify(response)
183+
);
183184
}
184185

185186
return response.testnet_id;
186187
};
187188

188-
const buildEpochSnapshot = (ctx: any): EpochSnapshot => {
189-
const nodeEpochEntries = Object.entries(
190-
ctx?.handshakeResult?.serverKeys ?? {}
191-
);
192-
const nodeEpochs = nodeEpochEntries.map(([url, data]: [string, any]) => ({
193-
url,
194-
epoch: data?.epoch,
195-
}));
196-
197-
const connected = ctx?.handshakeResult?.connectedNodes;
198-
const connectedCount =
199-
typeof connected?.size === 'number'
200-
? connected.size
201-
: Array.isArray(connected)
202-
? connected.length
203-
: undefined;
204-
205-
return {
206-
epoch: ctx?.latestConnectionInfo?.epochInfo?.number,
207-
nodeEpochs,
208-
threshold: ctx?.handshakeResult?.threshold,
209-
connectedCount,
210-
latestBlockhash: ctx?.latestBlockhash,
211-
rawContext: ctx,
212-
};
213-
};
189+
// const buildEpochSnapshot = (ctx: any): EpochSnapshot => {
190+
// const nodeEpochEntries = Object.entries(
191+
// ctx?.handshakeResult?.serverKeys ?? {}
192+
// );
193+
// const nodeEpochs = nodeEpochEntries.map(([url, data]: [string, any]) => ({
194+
// url,
195+
// epoch: data?.epoch,
196+
// }));
197+
198+
// const connected = ctx?.handshakeResult?.connectedNodes;
199+
// const connectedCount =
200+
// typeof connected?.size === 'number'
201+
// ? connected.size
202+
// : Array.isArray(connected)
203+
// ? connected.length
204+
// : undefined;
205+
206+
// return {
207+
// epoch: ctx?.latestConnectionInfo?.epochInfo?.number,
208+
// nodeEpochs,
209+
// threshold: ctx?.handshakeResult?.threshold,
210+
// connectedCount,
211+
// latestBlockhash: ctx?.latestBlockhash,
212+
// rawContext: ctx,
213+
// };
214+
// };
214215

215216
/**
216217
* Creates a Shiva client wrapper for the provided Lit client instance.
217218
* The wrapper talks to the Shiva manager REST endpoints, auto-discovers (or optionally creates) a testnet,
218219
* and exposes helpers for triggering and validating epoch transitions.
219220
*/
220221
export const createShivaClient = async (
221-
litClient: LitClientInstance,
222222
options: CreateShivaClientOptions
223223
): Promise<ShivaClient> => {
224224
const baseUrl = normaliseBaseUrl(options.baseUrl);
225-
const testnetId = await ensureTestnetId(
225+
const testnetId = await getOrCreateTestnetId(
226226
baseUrl,
227227
options.testnetId,
228228
options.createRequest
229229
);
230230

231-
const inspectEpoch = async () => {
232-
const ctx = await litClient.getContext();
233-
return buildEpochSnapshot(ctx);
234-
};
235-
236-
const waitForEpochChange = async ({
237-
baselineEpoch,
238-
timeoutMs = DEFAULT_TIMEOUT,
239-
intervalMs = DEFAULT_POLL_INTERVAL,
240-
}: WaitForEpochOptions) => {
241-
const deadline = Date.now() + timeoutMs;
242-
243-
while (Date.now() < deadline) {
244-
await new Promise((resolve) => setTimeout(resolve, intervalMs));
245-
const snapshot = await inspectEpoch();
246-
if (snapshot.epoch !== baselineEpoch) {
247-
return snapshot;
248-
}
249-
}
250-
251-
throw new Error(
252-
`Epoch did not change from ${baselineEpoch} within ${timeoutMs}ms`
253-
);
254-
};
231+
// const inspectEpoch = async () => {
232+
// const ctx = await litClient.getContext();
233+
// return buildEpochSnapshot(ctx);
234+
// };
235+
236+
// const waitForEpochChange = async ({
237+
// baselineEpoch,
238+
// timeoutMs = DEFAULT_TIMEOUT,
239+
// intervalMs = DEFAULT_POLL_INTERVAL,
240+
// }: WaitForEpochOptions) => {
241+
// const deadline = Date.now() + timeoutMs;
242+
243+
// while (Date.now() < deadline) {
244+
// await new Promise((resolve) => setTimeout(resolve, intervalMs));
245+
// const snapshot = await inspectEpoch();
246+
// if (snapshot.epoch !== baselineEpoch) {
247+
// return snapshot;
248+
// }
249+
// }
250+
251+
// throw new Error(
252+
// `Epoch did not change from ${baselineEpoch} within ${timeoutMs}ms`
253+
// );
254+
// };
255255

256256
const transitionEpochAndWait = async () => {
257257
const response = await fetchShiva<boolean>(
@@ -296,8 +296,8 @@ export const createShivaClient = async (
296296
return {
297297
baseUrl,
298298
testnetId,
299-
inspectEpoch,
300-
waitForEpochChange,
299+
// inspectEpoch,
300+
// waitForEpochChange,
301301
transitionEpochAndWait,
302302
stopRandomNodeAndWait,
303303
pollTestnetState,

0 commit comments

Comments
 (0)