Skip to content
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
7 changes: 3 additions & 4 deletions packages/pic/src/pocket-ic-client-types.ts
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,7 @@ export interface CreateInstanceRequest {
application?: ApplicationSubnetConfig[];
verifiedApplication?: VerifiedApplicationSubnetConfig[];
processingTimeoutMs?: number;
ingressMaxRetries?: number;
icpConfig?: IcpConfig;
icpFeatures?: IcpFeatures;
}
Expand Down Expand Up @@ -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<AwaitCanisterCallRequest, 'rounds'>,
req: AwaitCanisterCallRequest,
): EncodedAwaitCanisterCallRequest {
return {
effective_principal: encodeEffectivePrincipal(req.effectivePrincipal),
Expand Down
21 changes: 14 additions & 7 deletions packages/pic/src/pocket-ic-client.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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(
Expand All @@ -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<void> {
Expand Down Expand Up @@ -350,10 +358,9 @@ export class PocketIcClient {
return decodeIngressStatusResponse(res);
}

public async awaitCall({
rounds = AWAIT_INGRESS_STATUS_ROUNDS,
...req
}: AwaitCanisterCallRequest): Promise<AwaitCanisterCallResponse> {
public async awaitCall(
req: AwaitCanisterCallRequest,
): Promise<AwaitCanisterCallResponse> {
this.assertInstanceNotDeleted();
const encodedReq = {
messageId: encodeAwaitCanisterCallRequest(req),
Expand All @@ -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)) {
Expand All @@ -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`,
);
}

Expand Down
4 changes: 4 additions & 0 deletions packages/pic/src/pocket-ic-types.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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.
Expand Down