diff --git a/packages/pic/src/pocket-ic-client-types.ts b/packages/pic/src/pocket-ic-client-types.ts index 6df3546..cace287 100644 --- a/packages/pic/src/pocket-ic-client-types.ts +++ b/packages/pic/src/pocket-ic-client-types.ts @@ -24,6 +24,7 @@ export interface CreateInstanceRequest { application?: ApplicationSubnetConfig[]; verifiedApplication?: VerifiedApplicationSubnetConfig[]; processingTimeoutMs?: number; + ingressMaxRetries?: number; icpConfig?: IcpConfig; icpFeatures?: IcpFeatures; } @@ -1147,14 +1148,12 @@ export function decodeIngressStatusResponse( //#region AwaitCanisterCall -export type AwaitCanisterCallRequest = SubmitCanisterCallResponse & { - rounds?: number; -}; +export type AwaitCanisterCallRequest = SubmitCanisterCallResponse; export type EncodedAwaitCanisterCallRequest = EncodedCanisterCallId; export function encodeAwaitCanisterCallRequest( - req: Omit, + req: AwaitCanisterCallRequest, ): EncodedAwaitCanisterCallRequest { return { effective_principal: encodeEffectivePrincipal(req.effectivePrincipal), diff --git a/packages/pic/src/pocket-ic-client.ts b/packages/pic/src/pocket-ic-client.ts index a3b1142..7b08f2b 100644 --- a/packages/pic/src/pocket-ic-client.ts +++ b/packages/pic/src/pocket-ic-client.ts @@ -94,6 +94,7 @@ export class PocketIcClient { private constructor( private readonly serverClient: Http2Client, private readonly instancePath: string, + private readonly ingressMaxRetries: number, ) {} public static async create( @@ -120,7 +121,14 @@ export class PocketIcClient { const instanceId = res.Created.instance_id; - return new PocketIcClient(serverClient, `/instances/${instanceId}`); + const ingressMaxRetries = + req?.ingressMaxRetries ?? AWAIT_INGRESS_STATUS_ROUNDS; + + return new PocketIcClient( + serverClient, + `/instances/${instanceId}`, + ingressMaxRetries, + ); } public async deleteInstance(): Promise { @@ -350,10 +358,9 @@ export class PocketIcClient { return decodeIngressStatusResponse(res); } - public async awaitCall({ - rounds = AWAIT_INGRESS_STATUS_ROUNDS, - ...req - }: AwaitCanisterCallRequest): Promise { + public async awaitCall( + req: AwaitCanisterCallRequest, + ): Promise { this.assertInstanceNotDeleted(); const encodedReq = { messageId: encodeAwaitCanisterCallRequest(req), @@ -362,7 +369,7 @@ export class PocketIcClient { caller: undefined, }; - for (let i = 0; i < rounds; i++) { + for (let i = 0; i < this.ingressMaxRetries; i++) { await this.tick(); const result = await this.ingressStatus(encodedReq); if (isNotNil(result)) { @@ -371,7 +378,7 @@ export class PocketIcClient { } throw new Error( - `PocketIC did not complete the update call within ${rounds} rounds`, + `PocketIC did not complete the update call within ${this.ingressMaxRetries} rounds`, ); } diff --git a/packages/pic/src/pocket-ic-types.ts b/packages/pic/src/pocket-ic-types.ts index d396365..87787a1 100644 --- a/packages/pic/src/pocket-ic-types.ts +++ b/packages/pic/src/pocket-ic-types.ts @@ -68,6 +68,10 @@ export interface CreateInstanceOptions { */ processingTimeoutMs?: number; + /** + * How many IngressStatusRounds all IC update calls should wait, till we get a timeout. + */ + ingressMaxRetries?: number; /** * Determines what non-mainnet features should be * enabled for the PocketIC instance.