@dfinity/pic 0.12.0-b0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (63) hide show
  1. package/README.md +73 -0
  2. package/dist/error.d.ts +21 -0
  3. package/dist/error.js +55 -0
  4. package/dist/error.js.map +1 -0
  5. package/dist/http2-client.d.ts +27 -0
  6. package/dist/http2-client.js +137 -0
  7. package/dist/http2-client.js.map +1 -0
  8. package/dist/identity.d.ts +74 -0
  9. package/dist/identity.js +94 -0
  10. package/dist/identity.js.map +1 -0
  11. package/dist/index.d.ts +7 -0
  12. package/dist/index.js +24 -0
  13. package/dist/index.js.map +1 -0
  14. package/dist/management-canister.d.ts +45 -0
  15. package/dist/management-canister.js +71 -0
  16. package/dist/management-canister.js.map +1 -0
  17. package/dist/pocket-ic-actor.d.ts +85 -0
  18. package/dist/pocket-ic-actor.js +58 -0
  19. package/dist/pocket-ic-actor.js.map +1 -0
  20. package/dist/pocket-ic-client-types.d.ts +372 -0
  21. package/dist/pocket-ic-client-types.js +395 -0
  22. package/dist/pocket-ic-client-types.js.map +1 -0
  23. package/dist/pocket-ic-client.d.ts +31 -0
  24. package/dist/pocket-ic-client.js +152 -0
  25. package/dist/pocket-ic-client.js.map +1 -0
  26. package/dist/pocket-ic-deferred-actor.d.ts +67 -0
  27. package/dist/pocket-ic-deferred-actor.js +44 -0
  28. package/dist/pocket-ic-deferred-actor.js.map +1 -0
  29. package/dist/pocket-ic-server-types.d.ts +13 -0
  30. package/dist/pocket-ic-server-types.js +3 -0
  31. package/dist/pocket-ic-server-types.js.map +1 -0
  32. package/dist/pocket-ic-server.d.ts +53 -0
  33. package/dist/pocket-ic-server.js +126 -0
  34. package/dist/pocket-ic-server.js.map +1 -0
  35. package/dist/pocket-ic-types.d.ts +679 -0
  36. package/dist/pocket-ic-types.js +72 -0
  37. package/dist/pocket-ic-types.js.map +1 -0
  38. package/dist/pocket-ic.d.ts +972 -0
  39. package/dist/pocket-ic.js +1248 -0
  40. package/dist/pocket-ic.js.map +1 -0
  41. package/dist/util/candid.d.ts +3 -0
  42. package/dist/util/candid.js +21 -0
  43. package/dist/util/candid.js.map +1 -0
  44. package/dist/util/encoding.d.ts +6 -0
  45. package/dist/util/encoding.js +24 -0
  46. package/dist/util/encoding.js.map +1 -0
  47. package/dist/util/fs.d.ts +4 -0
  48. package/dist/util/fs.js +28 -0
  49. package/dist/util/fs.js.map +1 -0
  50. package/dist/util/index.d.ts +6 -0
  51. package/dist/util/index.js +23 -0
  52. package/dist/util/index.js.map +1 -0
  53. package/dist/util/is-nil.d.ts +2 -0
  54. package/dist/util/is-nil.js +11 -0
  55. package/dist/util/is-nil.js.map +1 -0
  56. package/dist/util/os.d.ts +4 -0
  57. package/dist/util/os.js +19 -0
  58. package/dist/util/os.js.map +1 -0
  59. package/dist/util/poll.d.ts +5 -0
  60. package/dist/util/poll.js +23 -0
  61. package/dist/util/poll.js.map +1 -0
  62. package/package.json +40 -0
  63. package/postinstall.mjs +25 -0
@@ -0,0 +1,972 @@
1
+ import { Principal } from '@dfinity/principal';
2
+ import { IDL } from '@dfinity/candid';
3
+ import { ActorInterface, Actor } from './pocket-ic-actor';
4
+ import { CanisterFixture, CreateCanisterOptions, CreateInstanceOptions, InstallCodeOptions, ReinstallCodeOptions, SetupCanisterOptions, UpgradeCanisterOptions, SubnetTopology, UpdateCanisterSettingsOptions, StartCanisterOptions, StopCanisterOptions, QueryCallOptions, UpdateCallOptions, PendingHttpsOutcall, MockPendingHttpsOutcallOptions } from './pocket-ic-types';
5
+ import { DeferredActor } from './pocket-ic-deferred-actor';
6
+ /**
7
+ * This class represents the main PocketIC client.
8
+ * It is responsible for interacting with the PocketIC server via the REST API.
9
+ * See {@link PocketIcServer} for details on the server to use with this client.
10
+ *
11
+ * @category API
12
+ *
13
+ * @example
14
+ * The easist way to use PocketIC is to use {@link setupCanister} convenience method:
15
+ * ```ts
16
+ * import { PocketIc, PocketIcServer } from '@dfinity/pic';
17
+ * import { _SERVICE, idlFactory } from '../declarations';
18
+ *
19
+ * const wasmPath = resolve('..', '..', 'canister.wasm');
20
+ *
21
+ * const picServer = await PocketIcServer.create();
22
+ * const pic = await PocketIc.create(picServer.getUrl());
23
+ *
24
+ * const fixture = await pic.setupCanister<_SERVICE>({ idlFactory, wasmPath });
25
+ * const { actor } = fixture;
26
+ *
27
+ * // perform tests...
28
+ *
29
+ * await pic.tearDown();
30
+ * await picServer.stop();
31
+ * ```
32
+ *
33
+ * If more control is needed, then the {@link createCanister}, {@link installCode} and
34
+ * {@link createActor} methods can be used directly:
35
+ * ```ts
36
+ * import { PocketIc, PocketIcServer } from '@dfinity/pic';
37
+ * import { _SERVICE, idlFactory } from '../declarations';
38
+ *
39
+ * const wasm = resolve('..', '..', 'canister.wasm');
40
+ *
41
+ * const picServer = await PocketIcServer.create();
42
+ * const pic = await PocketIc.create(picServer.getUrl());
43
+ *
44
+ * const canisterId = await pic.createCanister();
45
+ * await pic.installCode({ canisterId, wasm });
46
+ * const actor = pic.createActor<_SERVICE>({ idlFactory, canisterId });
47
+ *
48
+ * // perform tests...
49
+ *
50
+ * await pic.tearDown();
51
+ * await picServer.stop();
52
+ * ```
53
+ */
54
+ export declare class PocketIc {
55
+ private readonly client;
56
+ private constructor();
57
+ /**
58
+ * Creates a PocketIC instance.
59
+ *
60
+ * @param url The URL of an existing PocketIC server to connect to.
61
+ * @param options Options for creating the PocketIC instance see {@link CreateInstanceOptions}.
62
+ * @returns A new PocketIC instance.
63
+ *
64
+ * @example
65
+ * ```ts
66
+ * import { PocketIc, PocketIcServer } from '@dfinity/pic';
67
+ *
68
+ * const picServer = await PocketIcServer.create();
69
+ * const pic = await PocketIc.create(picServer.getUrl());
70
+ *
71
+ * const fixture = await pic.setupCanister<_SERVICE>({ idlFactory, wasmPath });
72
+ * const { actor } = fixture;
73
+ *
74
+ * await pic.tearDown();
75
+ * await picServer.stop();
76
+ * ```
77
+ */
78
+ static create(url: string, options?: CreateInstanceOptions): Promise<PocketIc>;
79
+ /**
80
+ * A convenience method that creates a new canister,
81
+ * installs the given WASM module to it and returns a typesafe {@link Actor}
82
+ * that implements the Candid interface of the canister.
83
+ * To just create a canister, see {@link createCanister}.
84
+ * To just install code to an existing canister, see {@link installCode}.
85
+ * To just create an Actor for an existing canister, see {@link createActor}.
86
+ *
87
+ * @param options Options for setting up the canister, see {@link SetupCanisterOptions}.
88
+ * @returns The {@link Actor} instance.
89
+ *
90
+ * @see [Candid](https://internetcomputer.org/docs/current/references/candid-ref)
91
+ * @see [Principal](https://agent-js.icp.xyz/principal/classes/Principal.html)
92
+ *
93
+ * @example
94
+ * ```ts
95
+ * import { PocketIc, PocketIcServer } from '@dfinity/pic';
96
+ * import { _SERVICE, idlFactory } from '../declarations';
97
+ *
98
+ * const wasmPath = resolve('..', '..', 'canister.wasm');
99
+ *
100
+ * const picServer = await PocketIcServer.create();
101
+ * const pic = await PocketIc.create(picServer.getUrl());
102
+ *
103
+ * const fixture = await pic.setupCanister<_SERVICE>({ idlFactory, wasmPath });
104
+ * const { actor } = fixture;
105
+ *
106
+ * await pic.tearDown();
107
+ * await picServer.stop();
108
+ * ```
109
+ */
110
+ setupCanister<T extends ActorInterface<T> = ActorInterface>({ sender, arg, wasm, idlFactory, computeAllocation, controllers, cycles, freezingThreshold, memoryAllocation, targetCanisterId, targetSubnetId, reservedCyclesLimit, }: SetupCanisterOptions): Promise<CanisterFixture<T>>;
111
+ /**
112
+ * Creates a new canister.
113
+ * For a more convenient way of creating a PocketIC instance,
114
+ * creating a canister and installing code, see {@link setupCanister}.
115
+ *
116
+ * @param options Options for creating the canister, see {@link CreateCanisterOptions}.
117
+ * @returns The Principal of the newly created canister.
118
+ *
119
+ * @see [Principal](https://agent-js.icp.xyz/principal/classes/Principal.html)
120
+ *
121
+ * @example
122
+ * ```ts
123
+ * import { PocketIc, PocketIcServer } from '@dfinity/pic';
124
+ *
125
+ * const picServer = await PocketIcServer.create();
126
+ * const pic = await PocketIc.create(picServer.getUrl());
127
+ *
128
+ * const canisterId = await pic.createCanister();
129
+ *
130
+ * await pic.tearDown();
131
+ * await picServer.stop();
132
+ * ```
133
+ */
134
+ createCanister({ sender, cycles, controllers, computeAllocation, freezingThreshold, memoryAllocation, reservedCyclesLimit, targetCanisterId, targetSubnetId, }?: CreateCanisterOptions): Promise<Principal>;
135
+ /**
136
+ * Starts the given canister.
137
+ *
138
+ * @param options Options for starting the canister, see {@link StartCanisterOptions}.
139
+ *
140
+ * @see [Principal](https://agent-js.icp.xyz/principal/classes/Principal.html)
141
+ *
142
+ * @example
143
+ * ```ts
144
+ * import { Principal } from '@dfinity/principal';
145
+ * import { PocketIc, PocketIcServer } from '@dfinity/pic';
146
+ *
147
+ * const canisterId = Principal.fromUint8Array(new Uint8Array([0]));
148
+ *
149
+ * const picServer = await PocketIcServer.create();
150
+ * const pic = await PocketIc.create(picServer.getUrl());
151
+ *
152
+ * await pic.startCanister({ canisterId });
153
+ *
154
+ * await pic.tearDown();
155
+ * await picServer.stop();
156
+ * ```
157
+ */
158
+ startCanister({ canisterId, sender, targetSubnetId, }: StartCanisterOptions): Promise<void>;
159
+ /**
160
+ * Stops the given canister.
161
+ *
162
+ * @param options Options for stopping the canister, see {@link StopCanisterOptions}.
163
+ *
164
+ * @see [Principal](https://agent-js.icp.xyz/principal/classes/Principal.html)
165
+ *
166
+ * @example
167
+ * ```ts
168
+ * import { Principal } from '@dfinity/principal';
169
+ * import { PocketIc, PocketIcServer } from '@dfinity/pic';
170
+ *
171
+ * const canisterId = Principal.fromUint8Array(new Uint8Array([0]));
172
+ *
173
+ * const picServer = await PocketIcServer.create();
174
+ * const pic = await PocketIc.create(picServer.getUrl());
175
+ *
176
+ * await pic.stopCanister({ canisterId });
177
+ *
178
+ * await pic.tearDown();
179
+ * await picServer.stop();
180
+ * ```
181
+ */
182
+ stopCanister({ canisterId, sender, targetSubnetId, }: StopCanisterOptions): Promise<void>;
183
+ /**
184
+ * Installs the given WASM module to the provided canister.
185
+ * To create a canister to install code to, see {@link createCanister}.
186
+ * For a more convenient way of creating a PocketIC instance,
187
+ * creating a canister and installing code, see {@link setupCanister}.
188
+ *
189
+ * @param options Options for installing the code, see {@link InstallCodeOptions}.
190
+ *
191
+ * @see [Principal](https://agent-js.icp.xyz/principal/classes/Principal.html)
192
+ *
193
+ * @example
194
+ * ```ts
195
+ * import { Principal } from '@dfinity/principal';
196
+ * import { PocketIc, PocketIcServer } from '@dfinity/pic';
197
+ * import { resolve } from 'node:path';
198
+ *
199
+ * const canisterId = Principal.fromUint8Array(new Uint8Array([0]));
200
+ * const wasm = resolve('..', '..', 'canister.wasm');
201
+ *
202
+ * const picServer = await PocketIcServer.create();
203
+ * const pic = await PocketIc.create(picServer.getUrl());
204
+ *
205
+ * await pic.installCode({ canisterId, wasm });
206
+ *
207
+ * await pic.tearDown();
208
+ * await picServer.stop();
209
+ * ```
210
+ */
211
+ installCode({ arg, sender, canisterId, wasm, targetSubnetId, }: InstallCodeOptions): Promise<void>;
212
+ /**
213
+ * Reinstalls the given WASM module to the provided canister.
214
+ * This will reset both the canister's heap and its stable memory.
215
+ * To create a canister to upgrade, see {@link createCanister}.
216
+ * To install the initial WASM module to a new canister, see {@link installCode}.
217
+ *
218
+ * @param options Options for reinstalling the code, see {@link ReinstallCodeOptions}.
219
+ *
220
+ * @see [Principal](https://agent-js.icp.xyz/principal/classes/Principal.html)
221
+ *
222
+ * @example
223
+ * ```ts
224
+ * import { Principal } from '@dfinity/principal';
225
+ * import { PocketIc, PocketIcServer } from '@dfinity/pic';
226
+ * import { resolve } from 'node:path';
227
+ *
228
+ * const canisterId = Principal.fromUint8Array(new Uint8Array([0]));
229
+ * const wasm = resolve('..', '..', 'canister.wasm');
230
+ *
231
+ * const picServer = await PocketIcServer.create();
232
+ * const pic = await PocketIc.create(picServer.getUrl());
233
+ *
234
+ * await pic.reinstallCode({ canisterId, wasm });
235
+ *
236
+ * await pic.tearDown();
237
+ * await picServer.stop();
238
+ * ```
239
+ */
240
+ reinstallCode({ sender, arg, canisterId, wasm, }: ReinstallCodeOptions): Promise<void>;
241
+ /**
242
+ * Upgrades the given canister with the given WASM module.
243
+ * This will reset the canister's heap, but preserve stable memory.
244
+ * To create a canister to upgrade to, see {@link createCanister}.
245
+ * To install the initial WASM module to a new canister, see {@link installCode}.
246
+ *
247
+ * @param options Options for upgrading the canister, see {@link UpgradeCanisterOptions}.
248
+ *
249
+ * @see [Principal](https://agent-js.icp.xyz/principal/classes/Principal.html)
250
+ *
251
+ * @example
252
+ * ```ts
253
+ * import { Principal } from '@dfinity/principal';
254
+ * import { PocketIc, PocketIcServer } from '@dfinity/pic';
255
+ * import { resolve } from 'node:path';
256
+ *
257
+ * const canisterId = Principal.fromUint8Array(new Uint8Array([0]));
258
+ * const wasm = resolve('..', '..', 'canister.wasm');
259
+ *
260
+ * const picServer = await PocketIcServer.create();
261
+ * const pic = await PocketIc.create(picServer.getUrl());
262
+ *
263
+ * await pic.upgradeCanister({ canisterId, wasm });
264
+ *
265
+ * await pic.tearDown();
266
+ * await picServer.stop();
267
+ * ```
268
+ */
269
+ upgradeCanister({ sender, arg, canisterId, wasm, }: UpgradeCanisterOptions): Promise<void>;
270
+ /**
271
+ * Updates the settings of the given canister.
272
+ *
273
+ * @param options Options for updating the canister settings, see {@link UpdateCanisterSettingsOptions}.
274
+ *
275
+ * @see [Principal](https://agent-js.icp.xyz/principal/classes/Principal.html)
276
+ *
277
+ * @example
278
+ * ```ts
279
+ * import { Principal } from '@dfinity/principal';
280
+ * import { PocketIc, PocketIcServer } from '@dfinity/pic';
281
+ *
282
+ * const canisterId = Principal.fromUint8Array(new Uint8Array([0]));
283
+ *
284
+ * const picServer = await PocketIcServer.create();
285
+ * const pic = await PocketIc.create(picServer.getUrl());
286
+ *
287
+ * await pic.updateCanisterSettings({
288
+ * canisterId,
289
+ * controllers: [Principal.fromUint8Array(new Uint8Array([1]))],
290
+ * });
291
+ *
292
+ * await pic.tearDown();
293
+ * await picServer.stop();
294
+ * ```
295
+ */
296
+ updateCanisterSettings({ canisterId, computeAllocation, controllers, freezingThreshold, memoryAllocation, reservedCyclesLimit, sender, }: UpdateCanisterSettingsOptions): Promise<void>;
297
+ /**
298
+ * Creates an {@link Actor} for the given canister.
299
+ * An {@link Actor} is a typesafe class that implements the Candid interface of a canister.
300
+ * To create a canister for the {@link Actor}, see {@link createCanister}.
301
+ * For a more convenient way of creating a PocketIC instance,
302
+ * creating a canister and installing code, see {@link setupCanister}.
303
+ *
304
+ * @param interfaceFactory The InterfaceFactory to use for the {@link Actor}.
305
+ * @param canisterId The Principal of the canister to create the {@link Actor} for.
306
+ * @typeparam T The type of the {@link Actor}. Must implement {@link ActorInterface}.
307
+ * @returns The {@link Actor} instance.
308
+ *
309
+ * @see [Principal](https://agent-js.icp.xyz/principal/classes/Principal.html)
310
+ * @see [InterfaceFactory](https://agent-js.icp.xyz/candid/modules/IDL.html#InterfaceFactory)
311
+ *
312
+ * @example
313
+ * ```ts
314
+ * import { Principal } from '@dfinity/principal';
315
+ * import { PocketIc, PocketIcServer } from '@dfinity/pic';
316
+ * import { _SERVICE, idlFactory } from '../declarations';
317
+ *
318
+ * const canisterId = Principal.fromUint8Array(new Uint8Array([0]));
319
+ * const wasm = resolve('..', '..', 'canister.wasm');
320
+ *
321
+ * const picServer = await PocketIcServer.create();
322
+ * const pic = await PocketIc.create(picServer.getUrl());
323
+ *
324
+ * const canisterId = await pic.createCanister();
325
+ * await pic.installCode({ canisterId, wasm });
326
+ * const actor = pic.createActor<_SERVICE>({ idlFactory, canisterId });
327
+ *
328
+ * await pic.tearDown();
329
+ * await picServer.stop();
330
+ * ```
331
+ */
332
+ createActor<T extends ActorInterface<T> = ActorInterface>(interfaceFactory: IDL.InterfaceFactory, canisterId: Principal): Actor<T>;
333
+ /**
334
+ * Creates a {@link DeferredActor} for the given canister.
335
+ * A {@link DeferredActor} is a typesafe class that implements the Candid interface of a canister.
336
+ *
337
+ * A {@link DeferredActor} in contrast to a normal {@link Actor} will submit the call to the PocketIc replica,
338
+ * but the call will not be executed immediately. Instead, the calls are queued and a `Promise` is returned
339
+ * by the {@link DeferredActor} that can be awaited to process the pending canister call.
340
+ *
341
+ * To create a canister for the {@link DeferredActor}, see {@link createCanister}.
342
+ * For a more convenient way of creating a PocketIC instance,
343
+ * creating a canister and installing code, see {@link setupCanister}.
344
+ *
345
+ * @param interfaceFactory The InterfaceFactory to use for the {@link DeferredActor}.
346
+ * @param canisterId The Principal of the canister to create the {@link DeferredActor} for.
347
+ * @typeparam T The type of the {@link DeferredActor}. Must implement {@link ActorInterface}.
348
+ * @returns The {@link DeferredActor} instance.
349
+ *
350
+ * @see [Principal](https://agent-js.icp.xyz/principal/classes/Principal.html)
351
+ * @see [InterfaceFactory](https://agent-js.icp.xyz/candid/modules/IDL.html#InterfaceFactory)
352
+ *
353
+ * @example
354
+ */
355
+ createDeferredActor<T extends ActorInterface<T> = ActorInterface>(interfaceFactory: IDL.InterfaceFactory, canisterId: Principal): DeferredActor<T>;
356
+ /**
357
+ * Makes a query call to the given canister.
358
+ *
359
+ * @param options Options for making the query call, see {@link QueryCallOptions}.
360
+ * @returns The Candid-encoded response of the query call.
361
+ *
362
+ * @example
363
+ * ```ts
364
+ * import { Principal } from '@dfinity/principal';
365
+ * import { PocketIc, PocketIcServer } from '@dfinity/pic';
366
+ * import { _SERVICE, idlFactory } from '../declarations';
367
+ *
368
+ * const wasm = resolve('..', '..', 'canister.wasm');
369
+ *
370
+ * const picServer = await PocketIcServer.create();
371
+ * const pic = await PocketIc.create(picServer.getUrl());
372
+ *
373
+ * canisterId = await pic.createCanister({
374
+ * sender: controllerIdentity.getPrincipal(),
375
+ * });
376
+ * await pic.installCode({ canisterId, wasm });
377
+ *
378
+ * const res = await pic.queryCall({
379
+ * canisterId,
380
+ * method: 'greet',
381
+ * });
382
+ *
383
+ * await pic.tearDown();
384
+ * await picServer.stop();
385
+ * ```
386
+ */
387
+ queryCall({ canisterId, method, arg, sender, targetSubnetId, }: QueryCallOptions): Promise<ArrayBufferLike>;
388
+ /**
389
+ * Makes an update call to the given canister.
390
+ *
391
+ * @param options Options for making the update call, see {@link UpdateCallOptions}.
392
+ * @returns The Candid-encoded response of the update call.
393
+ *
394
+ * @example
395
+ * ```ts
396
+ * import { Principal } from '@dfinity/principal';
397
+ * import { PocketIc, PocketIcServer } from '@dfinity/pic';
398
+ * import { _SERVICE, idlFactory } from '../declarations';
399
+ *
400
+ * const wasm = resolve('..', '..', 'canister.wasm');
401
+ *
402
+ * const picServer = await PocketIcServer.create();
403
+ * const pic = await PocketIc.create(picServer.getUrl());
404
+ *
405
+ * canisterId = await pic.createCanister({
406
+ * sender: controllerIdentity.getPrincipal(),
407
+ * });
408
+ * await pic.installCode({ canisterId, wasm });
409
+ *
410
+ * const res = await pic.updateCall({
411
+ * canisterId,
412
+ * method: 'greet',
413
+ * });
414
+ *
415
+ * await pic.tearDown();
416
+ * await picServer.stop();
417
+ * ```
418
+ */
419
+ updateCall({ canisterId, method, arg, sender, targetSubnetId, }: UpdateCallOptions): Promise<ArrayBufferLike>;
420
+ /**
421
+ * Deletes the PocketIC instance.
422
+ *
423
+ * @example
424
+ * ```ts
425
+ * import { PocketIc, PocketIcServer } from '@dfinity/pic';
426
+ *
427
+ * const picServer = await PocketIcServer.create();
428
+ * const pic = await PocketIc.create(picServer.getUrl());
429
+ *
430
+ * await pic.tearDown();
431
+ * await picServer.stop();
432
+ * ```
433
+ */
434
+ tearDown(): Promise<void>;
435
+ /**
436
+ * Make the IC produce and progress by one block. Accepts a parameter `times` to tick multiple times,
437
+ * the default is `1`.
438
+ *
439
+ * @param times The number of new blocks to produce and progress by. Defaults to `1`.
440
+ *
441
+ * ```ts
442
+ * import { PocketIc, PocketIcServer } from '@dfinity/pic';
443
+ *
444
+ * const picServer = await PocketIcServer.create();
445
+ * const pic = await PocketIc.create(picServer.getUrl());
446
+ *
447
+ * await pic.tick();
448
+ *
449
+ * // or to tick multiple times
450
+ * await pic.tick(3);
451
+ *
452
+ * await pic.tearDown();
453
+ * await picServer.stop();
454
+ * ```
455
+ */
456
+ tick(times?: number): Promise<void>;
457
+ /**
458
+ * Get the controllers of the specified canister.
459
+ *
460
+ * @param canisterId The Principal of the canister to get the controllers of.
461
+ * @returns The controllers of the specified canister.
462
+ *
463
+ * @see [Principal](https://agent-js.icp.xyz/principal/classes/Principal.html)
464
+ *
465
+ * @example
466
+ * ```ts
467
+ * import { Principal } from '@dfinity/principal';
468
+ *
469
+ * const canisterId = Principal.fromUint8Array(new Uint8Array([0]));
470
+ *
471
+ * const picServer = await PocketIcServer.create();
472
+ * const pic = await PocketIc.create(picServer.getUrl());
473
+ *
474
+ * const controllers = await pic.getControllers(canisterId);
475
+ *
476
+ * await pic.tearDown();
477
+ * await picServer.stop();
478
+ */
479
+ getControllers(canisterId: Principal): Promise<Principal[]>;
480
+ /**
481
+ * Get the current time of the IC in milliseconds since the Unix epoch.
482
+ *
483
+ * @returns The current time in milliseconds since the UNIX epoch.
484
+ *
485
+ * @example
486
+ * ```ts
487
+ * import { PocketIc, PocketIcServer } from '@dfinity/pic';
488
+ *
489
+ * const picServer = await PocketIcServer.create();
490
+ * const pic = await PocketIc.create(picServer.getUrl());
491
+ *
492
+ * const time = await pic.getTime();
493
+ *
494
+ * await pic.tearDown();
495
+ * await picServer.stop();
496
+ * ```
497
+ */
498
+ getTime(): Promise<number>;
499
+ /**
500
+ * Reset the time of the IC to the current time.
501
+ * {@link tick} should be called after calling this method in order for query calls
502
+ * and read state request to reflect the new time.
503
+ *
504
+ * Use {@link resetCertifiedTime} to set time and immediately have query calls and
505
+ * read state requests reflect the new time.
506
+ *
507
+ * @example
508
+ * ```ts
509
+ * import { PocketIc, PocketIcServer } from '@dfinity/pic';
510
+ *
511
+ * const picServer = await PocketIcServer.create();
512
+ * const pic = await PocketIc.create(picServer.getUrl());
513
+ *
514
+ * await pic.resetTime();
515
+ * await pic.tick();
516
+ *
517
+ * const time = await pic.getTime();
518
+ *
519
+ * await pic.tearDown();
520
+ * await picServer.stop();
521
+ * ```
522
+ */
523
+ resetTime(): Promise<void>;
524
+ /**
525
+ * Reset the time of the IC to the current time and immediately have query calls and
526
+ * read state requests reflect the new time.
527
+ *
528
+ * Use {@link resetTime} to reset time without immediately reflecting the new time.
529
+ *
530
+ * @example
531
+ * ```ts
532
+ * import { PocketIc, PocketIcServer } from '@dfinity/pic';
533
+ *
534
+ * const picServer = await PocketIcServer.create();
535
+ * const pic = await PocketIc.create(picServer.getUrl());
536
+ *
537
+ * await pic.resetCertifiedTime();
538
+ *
539
+ * const time = await pic.getTime();
540
+ *
541
+ * await pic.tearDown();
542
+ * await picServer.stop();
543
+ * ```
544
+ */
545
+ resetCertifiedTime(): Promise<void>;
546
+ /**
547
+ * Set the current time of the IC.
548
+ * {@link tick} should be called after calling this method in order for query calls
549
+ * and read state request to reflect the new time.
550
+ *
551
+ * Use {@link setCertifiedTime} to set time and immediately have query calls and
552
+ * read state requests reflect the new time.
553
+ *
554
+ * @param time The time to set in milliseconds since the Unix epoch.
555
+ *
556
+ * @example
557
+ * ```ts
558
+ * import { PocketIc, PocketIcServer } from '@dfinity/pic';
559
+ *
560
+ * const pic = await PocketIc.create();
561
+ *
562
+ * const date = new Date();
563
+ *
564
+ * const picServer = await PocketIcServer.create();
565
+ * const pic = await PocketIc.create(picServer.getUrl());
566
+ *
567
+ * await pic.setTime(date);
568
+ * // or
569
+ * await pic.setTime(date.getTime());
570
+ *
571
+ * await pic.tick();
572
+ *
573
+ * const time = await pic.getTime();
574
+ *
575
+ * await pic.tearDown();
576
+ * await picServer.stop();
577
+ * ```
578
+ */
579
+ setTime(time: Date | number): Promise<void>;
580
+ /**
581
+ * Set the current time of the IC and immediately have query calls and
582
+ * read state requests reflect the new time.
583
+ *
584
+ * Use {@link setTime} to set time without immediately reflecting the new time.
585
+ *
586
+ * @param time The time to set in milliseconds since the Unix epoch.
587
+ *
588
+ * @example
589
+ * ```ts
590
+ * import { PocketIc, PocketIcServer } from '@dfinity/pic';
591
+ *
592
+ * const pic = await PocketIc.create();
593
+ *
594
+ * const date = new Date();
595
+ *
596
+ * const picServer = await PocketIcServer.create();
597
+ * const pic = await PocketIc.create(picServer.getUrl());
598
+ *
599
+ * await pic.setCertifiedTime(date);
600
+ * // or
601
+ * await pic.setCertifiedTime(date.getTime());
602
+ *
603
+ * const time = await pic.getTime();
604
+ *
605
+ * await pic.tearDown();
606
+ * await picServer.stop();
607
+ * ```
608
+ */
609
+ setCertifiedTime(time: Date | number): Promise<void>;
610
+ /**
611
+ * Advance the time of the IC by the given duration in milliseconds.
612
+ * {@link tick} should be called after calling this method in order for query calls
613
+ * and read state requests to reflect the new time.
614
+ *
615
+ * Use {@link advanceCertifiedTime} to advance time and immediately have query calls and
616
+ * read state requests reflect the new time.
617
+ *
618
+ * @param duration The duration to advance the time by.
619
+ *
620
+ * @example
621
+ * ```ts
622
+ * import { PocketIc, PocketIcServer } from '@dfinity/pic';
623
+ *
624
+ * const picServer = await PocketIcServer.create();
625
+ * const pic = await PocketIc.create(picServer.getUrl());
626
+ *
627
+ * const initialTime = await pic.getTime();
628
+ * await pic.advanceTime(1_000);
629
+ * await pic.tick();
630
+ *
631
+ * const newTime = await pic.getTime();
632
+ *
633
+ * await pic.tearDown();
634
+ * await picServer.stop();
635
+ * ```
636
+ */
637
+ advanceTime(duration: number): Promise<void>;
638
+ /**
639
+ * Advance the time of the IC by the given duration in milliseconds and
640
+ * immediately have query calls and read state requests reflect the new time.
641
+ *
642
+ * Use {@link advanceTime} to advance time without immediately reflecting the new time.
643
+ *
644
+ * @param duration The duration to advance the time by.
645
+ *
646
+ * @example
647
+ * ```ts
648
+ * import { PocketIc, PocketIcServer } from '@dfinity/pic';
649
+ *
650
+ * const picServer = await PocketIcServer.create();
651
+ * const pic = await PocketIc.create(picServer.getUrl());
652
+ *
653
+ * const initialTime = await pic.getTime();
654
+ * await pic.advanceCertifiedTime(1_000);
655
+ *
656
+ * const newTime = await pic.getTime();
657
+ *
658
+ * await pic.tearDown();
659
+ * await picServer.stop();
660
+ * ```
661
+ */
662
+ advanceCertifiedTime(duration: number): Promise<void>;
663
+ /**
664
+ * Fetch the public key of the specified subnet.
665
+ *
666
+ * @param subnetId The Principal of the subnet to fetch the public key of.
667
+ * @returns The public key of the specified subnet.
668
+ *
669
+ * @example
670
+ * ```ts
671
+ * import { PocketIc, PocketIcServer } from '@dfinity/pic';
672
+ *
673
+ * const picServer = await PocketIcServer.create();
674
+ * const pic = await PocketIc.create(picServer.getUrl());
675
+ *
676
+ * const subnets = pic.getApplicationSubnets();
677
+ * const pubKey = await pic.getPubKey(subnets[0].id);
678
+ *
679
+ * await pic.tearDown();
680
+ * await picServer.stop();
681
+ * ```
682
+ */
683
+ getPubKey(subnetId: Principal): Promise<ArrayBufferLike>;
684
+ /**
685
+ * Gets the subnet Id of the provided canister Id.
686
+ *
687
+ * @param canisterId The Principal of the canister to get the subnet Id of.
688
+ * @returns The canister's subnet Id if the canister exists, `null` otherwise.
689
+ *
690
+ * @see [Principal](https://agent-js.icp.xyz/principal/classes/Principal.html)
691
+ *
692
+ * @example
693
+ * ```ts
694
+ * import { PocketIc, PocketIcServer } from '@dfinity/pic';
695
+ *
696
+ * const canisterId = Principal.fromUint8Array(new Uint8Array([0]));
697
+ *
698
+ * const picServer = await PocketIcServer.create();
699
+ * const pic = await PocketIc.create(picServer.getUrl());
700
+ *
701
+ * const subnetId = await pic.getCanisterSubnetId(canisterId);
702
+ *
703
+ * await pic.tearDown();
704
+ * await picServer.stop();
705
+ * ```
706
+ */
707
+ getCanisterSubnetId(canisterId: Principal): Promise<Principal | null>;
708
+ /**
709
+ * Get the topology of this instance's network.
710
+ * The topology is a list of subnets, each with a type and a list of canister ID ranges
711
+ * that can be deployed to that subnet.
712
+ * The instance network topology is configured via the {@link create} method.
713
+ *
714
+ * @returns An array of subnet topologies, see {@link SubnetTopology}.
715
+ */
716
+ getTopology(): Promise<SubnetTopology[]>;
717
+ /**
718
+ * Get the Bitcoin subnet topology for this instance's network.
719
+ * The instance network topology is configured via the {@link create} method.
720
+ *
721
+ * @returns The subnet topology for the Bitcoin subnet,
722
+ * if it exists on this instance's network.
723
+ */
724
+ getBitcoinSubnet(): Promise<SubnetTopology | undefined>;
725
+ /**
726
+ * Get the Fiduciary subnet topology for this instance's network.
727
+ * The instance network topology is configured via the {@link create} method.
728
+ *
729
+ * @returns The subnet topology for the Fiduciary subnet,
730
+ * if it exists on this instance's network.
731
+ */
732
+ getFiduciarySubnet(): Promise<SubnetTopology | undefined>;
733
+ /**
734
+ * Get the Internet Identity subnet topology for this instance's network.
735
+ * The instance network topology is configured via the {@link create} method.
736
+ *
737
+ * @returns The subnet topology for the Internet Identity subnet,
738
+ * if it exists on this instance's network.
739
+ */
740
+ getInternetIdentitySubnet(): Promise<SubnetTopology | undefined>;
741
+ /**
742
+ * Get the NNS subnet topology for this instance's network.
743
+ * The instance network topology is configured via the {@link create} method.
744
+ *
745
+ * @returns The subnet topology for the NNS subnet,
746
+ * if it exists on this instance's network.
747
+ */
748
+ getNnsSubnet(): Promise<SubnetTopology | undefined>;
749
+ /**
750
+ * Get the SNS subnet topology for this instance's network.
751
+ * The instance network topology is configured via the {@link create} method.
752
+ *
753
+ * @returns The subnet topology for the SNS subnet,
754
+ * if it exists on this instance's network.
755
+ */
756
+ getSnsSubnet(): Promise<SubnetTopology | undefined>;
757
+ /**
758
+ * Get all application subnet topologies for this instance's network.
759
+ * The instance network topology is configured via the {@link create} method.
760
+ *
761
+ * @returns An array of subnet topologies for each application subnet
762
+ * that exists on this instance's network.
763
+ */
764
+ getApplicationSubnets(): Promise<SubnetTopology[]>;
765
+ /**
766
+ * Get all system subnet topologies for this instance's network.
767
+ * The instance network topology is configured via the {@link create} method.
768
+ *
769
+ * @returns An array of subnet topologies for each system subnet
770
+ * that exists on this instance's network.
771
+ */
772
+ getSystemSubnets(): Promise<SubnetTopology[]>;
773
+ /**
774
+ * Gets the current cycle balance of the specified canister.
775
+ *
776
+ * @param canisterId The Principal of the canister to check.
777
+ * @returns The current cycles balance of the canister.
778
+ *
779
+ * @see [Principal](https://agent-js.icp.xyz/principal/classes/Principal.html)
780
+ *
781
+ * @example
782
+ * ```ts
783
+ * import { Principal } from '@dfinity/principal';
784
+ * import { PocketIc, PocketIcServer } from '@dfinity/pic';
785
+ *
786
+ * const canisterId = Principal.fromUint8Array(new Uint8Array([0]));
787
+ *
788
+ * const picServer = await PocketIcServer.create();
789
+ * const pic = await PocketIc.create(picServer.getUrl());
790
+ *
791
+ * const cyclesBalance = await pic.getCyclesBalance(canisterId);
792
+ *
793
+ * await pic.tearDown();
794
+ * await picServer.stop();
795
+ * ```
796
+ */
797
+ getCyclesBalance(canisterId: Principal): Promise<number>;
798
+ /**
799
+ * Add cycles to the specified canister.
800
+ *
801
+ * @param canisterId The Principal of the canister to add cycles to.
802
+ * @param amount The amount of cycles to add.
803
+ * @returns The new cycle balance of the canister.
804
+ *
805
+ * @see [Principal](https://agent-js.icp.xyz/principal/classes/Principal.html)
806
+ *
807
+ * @example
808
+ * ```ts
809
+ * import { Principal } from '@dfinity/principal';
810
+ * import { PocketIc, PocketIcServer } from '@dfinity/pic';
811
+ *
812
+ * const canisterId = Principal.fromUint8Array(new Uint8Array([0]));
813
+ *
814
+ * const picServer = await PocketIcServer.create();
815
+ * const pic = await PocketIc.create(picServer.getUrl());
816
+ *
817
+ * const newCyclesBalance = await pic.addCycles(canisterId, 10_000_000);
818
+ *
819
+ * await pic.tearDown();
820
+ * await picServer.stop();
821
+ * ```
822
+ */
823
+ addCycles(canisterId: Principal, amount: number): Promise<number>;
824
+ /**
825
+ * Set the stable memory of a given canister.
826
+ *
827
+ * @param canisterId The Principal of the canister to set the stable memory of.
828
+ * @param stableMemory A blob containing the stable memory to set.
829
+ *
830
+ * @see [Principal](https://agent-js.icp.xyz/principal/classes/Principal.html)
831
+ *
832
+ * @example
833
+ * ```ts
834
+ * import { Principal } from '@dfinity/principal';
835
+ * import { PocketIc, PocketIcServer } from '@dfinity/pic';
836
+ *
837
+ * const canisterId = Principal.fromUint8Array(new Uint8Array([0]));
838
+ * const stableMemory = new Uint8Array([0, 1, 2, 3, 4]);
839
+ *
840
+ * const picServer = await PocketIcServer.create();
841
+ * const pic = await PocketIc.create(picServer.getUrl());
842
+ *
843
+ * await pic.setStableMemory(canisterId, stableMemory);
844
+ *
845
+ * await pic.tearDown();
846
+ * await picServer.stop();
847
+ * ```
848
+ */
849
+ setStableMemory(canisterId: Principal, stableMemory: ArrayBufferLike): Promise<void>;
850
+ /**
851
+ * Get the stable memory of a given canister.
852
+ *
853
+ * @param canisterId The Principal of the canister to get the stable memory of.
854
+ * @returns A blob containing the canister's stable memory.
855
+ *
856
+ * @see [Principal](https://agent-js.icp.xyz/principal/classes/Principal.html)
857
+ *
858
+ * @example
859
+ * ```ts
860
+ * import { Principal } from '@dfinity/principal';
861
+ * import { PocketIc, PocketIcServer } from '@dfinity/pic';
862
+ *
863
+ * const canisterId = Principal.fromUint8Array(new Uint8Array([0]));
864
+ *
865
+ * const picServer = await PocketIcServer.create();
866
+ * const pic = await PocketIc.create(picServer.getUrl());
867
+ *
868
+ * const stableMemory = await pic.getStableMemory(canisterId);
869
+ *
870
+ * await pic.tearDown();
871
+ * await picServer.stop();
872
+ * ```
873
+ */
874
+ getStableMemory(canisterId: Principal): Promise<ArrayBufferLike>;
875
+ /**
876
+ * Get all pending HTTPS Outcalls across all subnets on this
877
+ * PocketIC instance.
878
+ *
879
+ * @returns An array of pending HTTPS Outcalls.
880
+ *
881
+ * @example
882
+ * ```ts
883
+ * import { Principal } from '@dfinity/principal';
884
+ * import { PocketIc, PocketIcServer } from '@dfinity/pic';
885
+ *
886
+ * const canisterId = Principal.fromUint8Array(new Uint8Array([0]));
887
+ *
888
+ * const picServer = await PocketIcServer.create();
889
+ * const pic = await PocketIc.create(picServer.getUrl());
890
+ *
891
+ * // queue the canister message that will send the HTTPS Outcall
892
+ * const executeGoogleSearch = await deferredActor.google_search();
893
+ *
894
+ * // tick for two rounds to allow the canister message to be processed
895
+ * // and for the HTTPS Outcall to be queued
896
+ * await pic.tick(2);
897
+ *
898
+ * // get all queued HTTPS Outcalls
899
+ * const pendingHttpsOutcalls = await pic.getPendingHttpsOutcalls();
900
+ *
901
+ * // get the first pending HTTPS Outcall
902
+ * const pendingGoogleSearchOutcall = pendingHttpsOutcalls[0];
903
+ *
904
+ * // mock the HTTPS Outcall
905
+ * await pic.mockPendingHttpsOutcall({
906
+ * requestId: pendingGoogleSearchOutcall.requestId,
907
+ * subnetId: pendingGoogleSearchOutcall.subnetId,
908
+ * response: {
909
+ * type: 'success',
910
+ * body: new TextEncoder().encode('Google search result'),
911
+ * statusCode: 200,
912
+ * headers: [],
913
+ * },
914
+ * });
915
+ *
916
+ * // finish executing the message, including the HTTPS Outcall
917
+ * const result = await executeGoogleSearch();
918
+ *
919
+ * await pic.tearDown();
920
+ * await picServer.stop();
921
+ * ```
922
+ */
923
+ getPendingHttpsOutcalls(): Promise<PendingHttpsOutcall[]>;
924
+ /**
925
+ * Mock a pending HTTPS Outcall.
926
+ *
927
+ * @param options Options for mocking the pending HTTPS Outcall, see {@link MockPendingHttpsOutcallOptions}.
928
+ *
929
+ * @example
930
+ * ```ts
931
+ * import { Principal } from '@dfinity/principal';
932
+ * import { PocketIc, PocketIcServer } from '@dfinity/pic';
933
+ *
934
+ * const canisterId = Principal.fromUint8Array(new Uint8Array([0]));
935
+ *
936
+ * const picServer = await PocketIcServer.create();
937
+ * const pic = await PocketIc.create(picServer.getUrl());
938
+ *
939
+ * // queue the canister message that will send the HTTPS Outcall
940
+ * const executeGoogleSearch = await deferredActor.google_search();
941
+ *
942
+ * // tick for two rounds to allow the canister message to be processed
943
+ * // and for the HTTPS Outcall to be queued
944
+ * await pic.tick(2);
945
+ *
946
+ * // get all queued HTTPS Outcalls
947
+ * const pendingHttpsOutcalls = await pic.getPendingHttpsOutcalls();
948
+ *
949
+ * // get the first pending HTTPS Outcall
950
+ * const pendingGoogleSearchOutcall = pendingHttpsOutcalls[0];
951
+ *
952
+ * // mock the HTTPS Outcall
953
+ * await pic.mockPendingHttpsOutcall({
954
+ * requestId: pendingGoogleSearchOutcall.requestId,
955
+ * subnetId: pendingGoogleSearchOutcall.subnetId,
956
+ * response: {
957
+ * type: 'success',
958
+ * body: new TextEncoder().encode('Google search result'),
959
+ * statusCode: 200,
960
+ * headers: [],
961
+ * },
962
+ * });
963
+ *
964
+ * // finish executing the message, including the HTTPS Outcall
965
+ * const result = await executeGoogleSearch();
966
+ *
967
+ * await pic.tearDown();
968
+ * await picServer.stop();
969
+ * ```
970
+ */
971
+ mockPendingHttpsOutcall({ requestId, response, subnetId, additionalResponses, }: MockPendingHttpsOutcallOptions): Promise<void>;
972
+ }