@dfinity/pic
Version:
An Internet Computer Protocol canister testing library for TypeScript and JavaScript.
68 lines (67 loc) • 2.7 kB
TypeScript
import { IDL } from '@dfinity/candid';
import { Principal } from '@dfinity/principal';
import { Identity } from '@dfinity/agent';
import { PocketIcClient } from './pocket-ic-client';
import { ActorInterface } from './pocket-ic-actor';
export interface DeferredActorMethod<Args extends unknown[] = unknown[], Ret = unknown> {
(...args: Args): Promise<() => Promise<Ret>>;
}
export type DeferredActorInterface<T extends ActorInterface<T> = ActorInterface> = {
[K in keyof T]: DeferredActorMethod<Parameters<T[K]>, ReturnType<T[K]>>;
};
export type DeferredActor<T extends ActorInterface<T> = ActorInterface> = DeferredActorInterface<T> & {
/**
* @ignore
*/
new (): DeferredActor<T>;
/**
* Set a Principal to be used as sender for all calls to the canister.
*
* @param principal The Principal to set.
*
* @see [Principal](https://agent-js.icp.xyz/principal/classes/Principal.html)
*
* @example
* ```ts
* import { PocketIc } from '@dfinity/pic';
* import { Principal } from '@dfinity/principal';
* import { _SERVICE, idlFactory } from '../declarations';
*
* const wasmPath = resolve('..', '..', 'canister.wasm');
*
* const pic = await PocketIc.create();
* const fixture = await pic.setupCanister<_SERVICE>(idlFactory, wasmPath);
* const { actor } = fixture;
*
* actor.setPrincipal(Principal.anonymous());
* ```
*/
setPrincipal(principal: Principal): void;
/**
* Set a Principal to be used as sender for all calls to the canister.
* This is a convenience method over {@link setPrincipal} that accepts an
* Identity and internally extracts the Principal.
*
* @param identity The identity to set.
*
* @see [Identity](https://agent-js.icp.xyz/agent/interfaces/Identity.html)
* @see [Principal](https://agent-js.icp.xyz/principal/classes/Principal.html)
*
* @example
* ```ts
* import { PocketIc } from '@dfinity/pic';
* import { AnonymousIdentity } from '@dfinity/agent';
* import { _SERVICE, idlFactory } from '../declarations';
*
* const wasmPath = resolve('..', '..', 'canister.wasm');
*
* const pic = await PocketIc.create();
* const fixture = await pic.setupCanister<_SERVICE>(idlFactory, wasmPath);
* const { actor } = fixture;
*
* actor.setIdentity(new AnonymousIdentity());
* ```
*/
setIdentity(identity: Identity): void;
};
export declare function createDeferredActorClass<T extends ActorInterface<T> = ActorInterface>(interfaceFactory: IDL.InterfaceFactory, canisterId: Principal, pocketIcClient: PocketIcClient): DeferredActor<T>;