@dfinity/pic 0.16.0 → 0.17.0

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.
@@ -1,7 +1,8 @@
1
- import { Principal } from '@dfinity/principal';
1
+ import { Principal } from '@icp-sdk/core/principal';
2
2
  import { ActorInterface, Actor } from './pocket-ic-actor';
3
- import { IDL } from '@dfinity/candid';
3
+ import { IDL } from '@icp-sdk/core/candid';
4
4
  import { CanisterInstallModeUpgradeOptions } from './management-canister';
5
+ export { type CanisterInstallModeUpgradeOptions } from './management-canister';
5
6
  /**
6
7
  * Options for creating a PocketIc instance.
7
8
  */
@@ -347,14 +348,14 @@ export interface SetupCanisterOptions extends CreateCanisterOptions {
347
348
  /**
348
349
  * The WASM module to install to the canister.
349
350
  * If a string is passed, it is treated as a path to a file.
350
- * If an `ArrayBufferLike` is passed, it is treated as the WASM module itself.
351
+ * If an `Uint8Array` is passed, it is treated as the WASM module itself.
351
352
  */
352
- wasm: ArrayBufferLike | string;
353
+ wasm: Uint8Array | string;
353
354
  /**
354
355
  * Candid encoded argument to pass to the canister's init function.
355
- * Defaults to an empty ArrayBuffer.
356
+ * Defaults to an empty Uint8Array.
356
357
  */
357
- arg?: ArrayBufferLike;
358
+ arg?: Uint8Array;
358
359
  /**
359
360
  * The principal to setup the canister as.
360
361
  * Defaults to the anonymous principal.
@@ -490,14 +491,14 @@ export interface InstallCodeOptions {
490
491
  /**
491
492
  * The WASM module to install to the canister.
492
493
  * If a string is passed, it is treated as a path to a file.
493
- * If an `ArrayBufferLike` is passed, it is treated as the WASM module itself.
494
+ * If an `Uint8Array` is passed, it is treated as the WASM module itself.
494
495
  */
495
- wasm: ArrayBufferLike | string;
496
+ wasm: Uint8Array | string;
496
497
  /**
497
498
  * Candid encoded argument to pass to the canister's init function.
498
- * Defaults to an empty ArrayBuffer.
499
+ * Defaults to an empty Uint8Array.
499
500
  */
500
- arg?: ArrayBufferLike;
501
+ arg?: Uint8Array;
501
502
  /**
502
503
  * The principal to install the code as.
503
504
  * Defaults to the anonymous principal.
@@ -523,13 +524,13 @@ export interface ReinstallCodeOptions {
523
524
  /**
524
525
  * The WASM module to install to the canister.
525
526
  * If a string is passed, it is treated as a path to a file.
526
- * If an `ArrayBufferLike` is passed, it is treated as the WASM module itself.
527
+ * If an `Uint8Array` is passed, it is treated as the WASM module itself.
527
528
  */
528
- wasm: ArrayBufferLike | string;
529
+ wasm: Uint8Array | string;
529
530
  /**
530
531
  * Candid encoded argument to pass to the canister's init function.
531
532
  */
532
- arg?: ArrayBufferLike;
533
+ arg?: Uint8Array;
533
534
  /**
534
535
  * The Principal to send the request as.
535
536
  * Defaults to the anonymous principal.
@@ -551,13 +552,13 @@ export interface UpgradeCanisterOptions {
551
552
  /**
552
553
  * The WASM module to install to the canister.
553
554
  * If a string is passed, it is treated as a path to a file.
554
- * If an `ArrayBufferLike` is passed, it is treated as the WASM module itself.
555
+ * If an `Uint8Array` is passed, it is treated as the WASM module itself.
555
556
  */
556
- wasm: ArrayBufferLike | string;
557
+ wasm: Uint8Array | string;
557
558
  /**
558
559
  * Candid encoded argument to pass to the canister's init function.
559
560
  */
560
- arg?: ArrayBufferLike;
561
+ arg?: Uint8Array;
561
562
  /**
562
563
  * The Principal to send the request as.
563
564
  * Defaults to the anonymous principal.
@@ -607,9 +608,9 @@ export interface QueryCallOptions {
607
608
  method: string;
608
609
  /**
609
610
  * A Candid encoded argument to pass to the canister's method.
610
- * Defaults to an empty ArrayBuffer.
611
+ * Defaults to an empty Uint8Array.
611
612
  */
612
- arg?: ArrayBufferLike;
613
+ arg?: Uint8Array;
613
614
  /**
614
615
  * The ID of the subnet that the canister resides on.
615
616
  */
@@ -637,9 +638,9 @@ export interface UpdateCallOptions {
637
638
  method: string;
638
639
  /**
639
640
  * A Candid encoded argument to pass to the canister's method.
640
- * Defaults to an empty ArrayBuffer.
641
+ * Defaults to an empty Uint8Array.
641
642
  */
642
- arg?: ArrayBufferLike;
643
+ arg?: Uint8Array;
643
644
  /**
644
645
  * The ID of the subnet that the canister resides on.
645
646
  */
@@ -1 +1 @@
1
- {"version":3,"file":"pocket-ic-types.js","sourceRoot":"","sources":["../src/pocket-ic-types.ts"],"names":[],"mappings":";;;AAmOA;;GAEG;AACH,IAAY,eAWX;AAXD,WAAY,eAAe;IACzB;;OAEG;IACH,8BAAW,CAAA;IAEX;;;OAGG;IACH,wCAAqB,CAAA;AACvB,CAAC,EAXW,eAAe,+BAAf,eAAe,QAW1B;AAED;;GAEG;AACH,IAAY,aAGX;AAHD,WAAY,aAAa;IACvB,sCAAqB,CAAA;IACrB,oCAAmB,CAAA;AACrB,CAAC,EAHW,aAAa,6BAAb,aAAa,QAGxB;AAyBD;;GAEG;AACH,IAAY,iBAKX;AALD,WAAY,iBAAiB;IAC3B;;OAEG;IACH,oDAA+B,CAAA;AACjC,CAAC,EALW,iBAAiB,iCAAjB,iBAAiB,QAK5B;AA6ED;;GAEG;AACH,IAAY,UAmCX;AAnCD,WAAY,UAAU;IACpB;;OAEG;IACH,yCAA2B,CAAA;IAE3B;;OAEG;IACH,iCAAmB,CAAA;IAEnB;;OAEG;IACH,qCAAuB,CAAA;IAEvB;;OAEG;IACH,qCAAuB,CAAA;IAEvB;;OAEG;IACH,yBAAW,CAAA;IAEX;;OAEG;IACH,yBAAW,CAAA;IAEX;;OAEG;IACH,+BAAiB,CAAA;AACnB,CAAC,EAnCW,UAAU,0BAAV,UAAU,QAmCrB;AAkaD;;GAEG;AACH,IAAY,kBAeX;AAfD,WAAY,kBAAkB;IAC5B;;OAEG;IACH,iCAAW,CAAA;IAEX;;OAEG;IACH,mCAAa,CAAA;IAEb;;OAEG;IACH,mCAAa,CAAA;AACf,CAAC,EAfW,kBAAkB,kCAAlB,kBAAkB,QAe7B;AAiFD,2BAA2B"}
1
+ {"version":3,"file":"pocket-ic-types.js","sourceRoot":"","sources":["../src/pocket-ic-types.ts"],"names":[],"mappings":";;;AAsOA;;GAEG;AACH,IAAY,eAWX;AAXD,WAAY,eAAe;IACzB;;OAEG;IACH,8BAAW,CAAA;IAEX;;;OAGG;IACH,wCAAqB,CAAA;AACvB,CAAC,EAXW,eAAe,+BAAf,eAAe,QAW1B;AAED;;GAEG;AACH,IAAY,aAGX;AAHD,WAAY,aAAa;IACvB,sCAAqB,CAAA;IACrB,oCAAmB,CAAA;AACrB,CAAC,EAHW,aAAa,6BAAb,aAAa,QAGxB;AAyBD;;GAEG;AACH,IAAY,iBAKX;AALD,WAAY,iBAAiB;IAC3B;;OAEG;IACH,oDAA+B,CAAA;AACjC,CAAC,EALW,iBAAiB,iCAAjB,iBAAiB,QAK5B;AA6ED;;GAEG;AACH,IAAY,UAmCX;AAnCD,WAAY,UAAU;IACpB;;OAEG;IACH,yCAA2B,CAAA;IAE3B;;OAEG;IACH,iCAAmB,CAAA;IAEnB;;OAEG;IACH,qCAAuB,CAAA;IAEvB;;OAEG;IACH,qCAAuB,CAAA;IAEvB;;OAEG;IACH,yBAAW,CAAA;IAEX;;OAEG;IACH,yBAAW,CAAA;IAEX;;OAEG;IACH,+BAAiB,CAAA;AACnB,CAAC,EAnCW,UAAU,0BAAV,UAAU,QAmCrB;AAkaD;;GAEG;AACH,IAAY,kBAeX;AAfD,WAAY,kBAAkB;IAC5B;;OAEG;IACH,iCAAW,CAAA;IAEX;;OAEG;IACH,mCAAa,CAAA;IAEb;;OAEG;IACH,mCAAa,CAAA;AACf,CAAC,EAfW,kBAAkB,kCAAlB,kBAAkB,QAe7B;AAiFD,2BAA2B"}
@@ -1,5 +1,5 @@
1
- import { Principal } from '@dfinity/principal';
2
- import { IDL } from '@dfinity/candid';
1
+ import { Principal } from '@icp-sdk/core/principal';
2
+ import { IDL } from '@icp-sdk/core/candid';
3
3
  import { ActorInterface, Actor } from './pocket-ic-actor';
4
4
  import { CanisterFixture, CreateCanisterOptions, CreateInstanceOptions, InstallCodeOptions, ReinstallCodeOptions, SetupCanisterOptions, UpgradeCanisterOptions, SubnetTopology, UpdateCanisterSettingsOptions, StartCanisterOptions, StopCanisterOptions, QueryCallOptions, UpdateCallOptions, PendingHttpsOutcall, MockPendingHttpsOutcallOptions } from './pocket-ic-types';
5
5
  import { DeferredActor } from './pocket-ic-deferred-actor';
@@ -141,7 +141,7 @@ export declare class PocketIc {
141
141
  *
142
142
  * @example
143
143
  * ```ts
144
- * import { Principal } from '@dfinity/principal';
144
+ * import { Principal } from '@icp-sdk/core/principal';
145
145
  * import { PocketIc, PocketIcServer } from '@dfinity/pic';
146
146
  *
147
147
  * const canisterId = Principal.fromUint8Array(new Uint8Array([0]));
@@ -165,7 +165,7 @@ export declare class PocketIc {
165
165
  *
166
166
  * @example
167
167
  * ```ts
168
- * import { Principal } from '@dfinity/principal';
168
+ * import { Principal } from '@icp-sdk/core/principal';
169
169
  * import { PocketIc, PocketIcServer } from '@dfinity/pic';
170
170
  *
171
171
  * const canisterId = Principal.fromUint8Array(new Uint8Array([0]));
@@ -192,7 +192,7 @@ export declare class PocketIc {
192
192
  *
193
193
  * @example
194
194
  * ```ts
195
- * import { Principal } from '@dfinity/principal';
195
+ * import { Principal } from '@icp-sdk/core/principal';
196
196
  * import { PocketIc, PocketIcServer } from '@dfinity/pic';
197
197
  * import { resolve } from 'node:path';
198
198
  *
@@ -221,7 +221,7 @@ export declare class PocketIc {
221
221
  *
222
222
  * @example
223
223
  * ```ts
224
- * import { Principal } from '@dfinity/principal';
224
+ * import { Principal } from '@icp-sdk/core/principal';
225
225
  * import { PocketIc, PocketIcServer } from '@dfinity/pic';
226
226
  * import { resolve } from 'node:path';
227
227
  *
@@ -250,7 +250,7 @@ export declare class PocketIc {
250
250
  *
251
251
  * @example
252
252
  * ```ts
253
- * import { Principal } from '@dfinity/principal';
253
+ * import { Principal } from '@icp-sdk/core/principal';
254
254
  * import { PocketIc, PocketIcServer } from '@dfinity/pic';
255
255
  * import { resolve } from 'node:path';
256
256
  *
@@ -276,7 +276,7 @@ export declare class PocketIc {
276
276
  *
277
277
  * @example
278
278
  * ```ts
279
- * import { Principal } from '@dfinity/principal';
279
+ * import { Principal } from '@icp-sdk/core/principal';
280
280
  * import { PocketIc, PocketIcServer } from '@dfinity/pic';
281
281
  *
282
282
  * const canisterId = Principal.fromUint8Array(new Uint8Array([0]));
@@ -303,7 +303,7 @@ export declare class PocketIc {
303
303
  *
304
304
  * @param interfaceFactory The InterfaceFactory to use for the {@link Actor}.
305
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}.
306
+ * @typeParam T The type of the {@link Actor}. Must implement {@link ActorInterface}.
307
307
  * @returns The {@link Actor} instance.
308
308
  *
309
309
  * @see [Principal](https://js.icp.build/core/latest/libs/principal/api/classes/principal/)
@@ -311,7 +311,7 @@ export declare class PocketIc {
311
311
  *
312
312
  * @example
313
313
  * ```ts
314
- * import { Principal } from '@dfinity/principal';
314
+ * import { Principal } from '@icp-sdk/core/principal';
315
315
  * import { PocketIc, PocketIcServer } from '@dfinity/pic';
316
316
  * import { _SERVICE, idlFactory } from '../declarations';
317
317
  *
@@ -344,7 +344,7 @@ export declare class PocketIc {
344
344
  *
345
345
  * @param interfaceFactory The InterfaceFactory to use for the {@link DeferredActor}.
346
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}.
347
+ * @typeParam T The type of the {@link DeferredActor}. Must implement {@link ActorInterface}.
348
348
  * @returns The {@link DeferredActor} instance.
349
349
  *
350
350
  * @see [Principal](https://js.icp.build/core/latest/libs/principal/api/classes/principal/)
@@ -361,7 +361,7 @@ export declare class PocketIc {
361
361
  *
362
362
  * @example
363
363
  * ```ts
364
- * import { Principal } from '@dfinity/principal';
364
+ * import { Principal } from '@icp-sdk/core/principal';
365
365
  * import { PocketIc, PocketIcServer } from '@dfinity/pic';
366
366
  * import { _SERVICE, idlFactory } from '../declarations';
367
367
  *
@@ -384,7 +384,7 @@ export declare class PocketIc {
384
384
  * await picServer.stop();
385
385
  * ```
386
386
  */
387
- queryCall({ canisterId, method, arg, sender, targetSubnetId, }: QueryCallOptions): Promise<ArrayBufferLike>;
387
+ queryCall({ canisterId, method, arg, sender, targetSubnetId, }: QueryCallOptions): Promise<Uint8Array>;
388
388
  /**
389
389
  * Makes an update call to the given canister.
390
390
  *
@@ -393,7 +393,7 @@ export declare class PocketIc {
393
393
  *
394
394
  * @example
395
395
  * ```ts
396
- * import { Principal } from '@dfinity/principal';
396
+ * import { Principal } from '@icp-sdk/core/principal';
397
397
  * import { PocketIc, PocketIcServer } from '@dfinity/pic';
398
398
  * import { _SERVICE, idlFactory } from '../declarations';
399
399
  *
@@ -416,7 +416,7 @@ export declare class PocketIc {
416
416
  * await picServer.stop();
417
417
  * ```
418
418
  */
419
- updateCall({ canisterId, method, arg, sender, targetSubnetId, }: UpdateCallOptions): Promise<ArrayBufferLike>;
419
+ updateCall({ canisterId, method, arg, sender, targetSubnetId, }: UpdateCallOptions): Promise<Uint8Array>;
420
420
  /**
421
421
  * Deletes the PocketIC instance.
422
422
  *
@@ -464,7 +464,7 @@ export declare class PocketIc {
464
464
  *
465
465
  * @example
466
466
  * ```ts
467
- * import { Principal } from '@dfinity/principal';
467
+ * import { Principal } from '@icp-sdk/core/principal';
468
468
  *
469
469
  * const canisterId = Principal.fromUint8Array(new Uint8Array([0]));
470
470
  *
@@ -680,7 +680,7 @@ export declare class PocketIc {
680
680
  * await picServer.stop();
681
681
  * ```
682
682
  */
683
- getPubKey(subnetId: Principal): Promise<ArrayBufferLike>;
683
+ getPubKey(subnetId: Principal): Promise<Uint8Array>;
684
684
  /**
685
685
  * Gets the subnet Id of the provided canister Id.
686
686
  *
@@ -714,6 +714,35 @@ export declare class PocketIc {
714
714
  * @returns An array of subnet topologies, see {@link SubnetTopology}.
715
715
  */
716
716
  getTopology(): Promise<SubnetTopology[]>;
717
+ /**
718
+ * Get the default effective canister id for this PocketIC instance.
719
+ * This is useful when calling [`IcManagementCanister.provisionalCreateCanisterWithCycles`](https://js.icp.build/canisters/latest/api/ic-management/classes/icmanagementcanister#provisionalcreatecanisterwithcycles)
720
+ * on the management canister from `@icp-sdk/canisters/ic-management`.
721
+ *
722
+ * @returns The default effective canister id.
723
+ *
724
+ * @see [Principal](https://js.icp.build/core/latest/libs/principal/api/classes/principal/)
725
+ *
726
+ * @example
727
+ * ```ts
728
+ * import { PocketIc, PocketIcServer } from '@dfinity/pic';
729
+ * import { IcManagementCanister } from '@icp-sdk/canisters/ic-management';
730
+ *
731
+ * const picServer = await PocketIcServer.start();
732
+ * const pic = await PocketIc.create(picServer.getUrl());
733
+ *
734
+ * const defaultEffectiveCanisterId = await pic.getDefaultEffectiveCanisterId();
735
+ *
736
+ * const managementCanister = IcManagementCanister.create({ agent });
737
+ * const canisterId = await managementCanister.provisionalCreateCanisterWithCycles({
738
+ * canisterId: defaultEffectiveCanisterId,
739
+ * });
740
+ *
741
+ * await pic.tearDown();
742
+ * await picServer.stop();
743
+ * ```
744
+ */
745
+ getDefaultEffectiveCanisterId(): Promise<Principal>;
717
746
  /**
718
747
  * Get the Bitcoin subnet topology for this instance's network.
719
748
  * The instance network topology is configured via the {@link create} method.
@@ -780,7 +809,7 @@ export declare class PocketIc {
780
809
  *
781
810
  * @example
782
811
  * ```ts
783
- * import { Principal } from '@dfinity/principal';
812
+ * import { Principal } from '@icp-sdk/core/principal';
784
813
  * import { PocketIc, PocketIcServer } from '@dfinity/pic';
785
814
  *
786
815
  * const canisterId = Principal.fromUint8Array(new Uint8Array([0]));
@@ -794,7 +823,7 @@ export declare class PocketIc {
794
823
  * await picServer.stop();
795
824
  * ```
796
825
  */
797
- getCyclesBalance(canisterId: Principal): Promise<number>;
826
+ getCyclesBalance(canisterId: Principal): Promise<bigint>;
798
827
  /**
799
828
  * Add cycles to the specified canister.
800
829
  *
@@ -806,7 +835,7 @@ export declare class PocketIc {
806
835
  *
807
836
  * @example
808
837
  * ```ts
809
- * import { Principal } from '@dfinity/principal';
838
+ * import { Principal } from '@icp-sdk/core/principal';
810
839
  * import { PocketIc, PocketIcServer } from '@dfinity/pic';
811
840
  *
812
841
  * const canisterId = Principal.fromUint8Array(new Uint8Array([0]));
@@ -820,7 +849,7 @@ export declare class PocketIc {
820
849
  * await picServer.stop();
821
850
  * ```
822
851
  */
823
- addCycles(canisterId: Principal, amount: number): Promise<number>;
852
+ addCycles(canisterId: Principal, amount: bigint): Promise<bigint>;
824
853
  /**
825
854
  * Set the stable memory of a given canister.
826
855
  *
@@ -831,7 +860,7 @@ export declare class PocketIc {
831
860
  *
832
861
  * @example
833
862
  * ```ts
834
- * import { Principal } from '@dfinity/principal';
863
+ * import { Principal } from '@icp-sdk/core/principal';
835
864
  * import { PocketIc, PocketIcServer } from '@dfinity/pic';
836
865
  *
837
866
  * const canisterId = Principal.fromUint8Array(new Uint8Array([0]));
@@ -846,7 +875,7 @@ export declare class PocketIc {
846
875
  * await picServer.stop();
847
876
  * ```
848
877
  */
849
- setStableMemory(canisterId: Principal, stableMemory: ArrayBufferLike): Promise<void>;
878
+ setStableMemory(canisterId: Principal, stableMemory: Uint8Array): Promise<void>;
850
879
  /**
851
880
  * Get the stable memory of a given canister.
852
881
  *
@@ -857,7 +886,7 @@ export declare class PocketIc {
857
886
  *
858
887
  * @example
859
888
  * ```ts
860
- * import { Principal } from '@dfinity/principal';
889
+ * import { Principal } from '@icp-sdk/core/principal';
861
890
  * import { PocketIc, PocketIcServer } from '@dfinity/pic';
862
891
  *
863
892
  * const canisterId = Principal.fromUint8Array(new Uint8Array([0]));
@@ -871,7 +900,7 @@ export declare class PocketIc {
871
900
  * await picServer.stop();
872
901
  * ```
873
902
  */
874
- getStableMemory(canisterId: Principal): Promise<ArrayBufferLike>;
903
+ getStableMemory(canisterId: Principal): Promise<Uint8Array>;
875
904
  /**
876
905
  * Get all pending HTTPS Outcalls across all subnets on this
877
906
  * PocketIC instance.
@@ -880,7 +909,7 @@ export declare class PocketIc {
880
909
  *
881
910
  * @example
882
911
  * ```ts
883
- * import { Principal } from '@dfinity/principal';
912
+ * import { Principal } from '@icp-sdk/core/principal';
884
913
  * import { PocketIc, PocketIcServer } from '@dfinity/pic';
885
914
  *
886
915
  * const canisterId = Principal.fromUint8Array(new Uint8Array([0]));
@@ -928,7 +957,7 @@ export declare class PocketIc {
928
957
  *
929
958
  * @example
930
959
  * ```ts
931
- * import { Principal } from '@dfinity/principal';
960
+ * import { Principal } from '@icp-sdk/core/principal';
932
961
  * import { PocketIc, PocketIcServer } from '@dfinity/pic';
933
962
  *
934
963
  * const canisterId = Principal.fromUint8Array(new Uint8Array([0]));
package/dist/pocket-ic.js CHANGED
@@ -1,13 +1,14 @@
1
1
  "use strict";
2
2
  Object.defineProperty(exports, "__esModule", { value: true });
3
3
  exports.PocketIc = void 0;
4
- const principal_1 = require("@dfinity/principal");
4
+ const principal_1 = require("@icp-sdk/core/principal");
5
5
  const util_1 = require("./util");
6
6
  const pocket_ic_client_1 = require("./pocket-ic-client");
7
7
  const pocket_ic_actor_1 = require("./pocket-ic-actor");
8
8
  const pocket_ic_types_1 = require("./pocket-ic-types");
9
9
  const management_canister_1 = require("./management-canister");
10
10
  const pocket_ic_deferred_actor_1 = require("./pocket-ic-deferred-actor");
11
+ const NANOS_PER_MILLISECOND = BigInt(1_000_000);
11
12
  /**
12
13
  * This class represents the main PocketIC client.
13
14
  * It is responsible for interacting with the PocketIC server via the REST API.
@@ -192,7 +193,7 @@ class PocketIc {
192
193
  *
193
194
  * @example
194
195
  * ```ts
195
- * import { Principal } from '@dfinity/principal';
196
+ * import { Principal } from '@icp-sdk/core/principal';
196
197
  * import { PocketIc, PocketIcServer } from '@dfinity/pic';
197
198
  *
198
199
  * const canisterId = Principal.fromUint8Array(new Uint8Array([0]));
@@ -231,7 +232,7 @@ class PocketIc {
231
232
  *
232
233
  * @example
233
234
  * ```ts
234
- * import { Principal } from '@dfinity/principal';
235
+ * import { Principal } from '@icp-sdk/core/principal';
235
236
  * import { PocketIc, PocketIcServer } from '@dfinity/pic';
236
237
  *
237
238
  * const canisterId = Principal.fromUint8Array(new Uint8Array([0]));
@@ -273,7 +274,7 @@ class PocketIc {
273
274
  *
274
275
  * @example
275
276
  * ```ts
276
- * import { Principal } from '@dfinity/principal';
277
+ * import { Principal } from '@icp-sdk/core/principal';
277
278
  * import { PocketIc, PocketIcServer } from '@dfinity/pic';
278
279
  * import { resolve } from 'node:path';
279
280
  *
@@ -325,7 +326,7 @@ class PocketIc {
325
326
  *
326
327
  * @example
327
328
  * ```ts
328
- * import { Principal } from '@dfinity/principal';
329
+ * import { Principal } from '@icp-sdk/core/principal';
329
330
  * import { PocketIc, PocketIcServer } from '@dfinity/pic';
330
331
  * import { resolve } from 'node:path';
331
332
  *
@@ -372,7 +373,7 @@ class PocketIc {
372
373
  *
373
374
  * @example
374
375
  * ```ts
375
- * import { Principal } from '@dfinity/principal';
376
+ * import { Principal } from '@icp-sdk/core/principal';
376
377
  * import { PocketIc, PocketIcServer } from '@dfinity/pic';
377
378
  * import { resolve } from 'node:path';
378
379
  *
@@ -416,7 +417,7 @@ class PocketIc {
416
417
  *
417
418
  * @example
418
419
  * ```ts
419
- * import { Principal } from '@dfinity/principal';
420
+ * import { Principal } from '@icp-sdk/core/principal';
420
421
  * import { PocketIc, PocketIcServer } from '@dfinity/pic';
421
422
  *
422
423
  * const canisterId = Principal.fromUint8Array(new Uint8Array([0]));
@@ -460,7 +461,7 @@ class PocketIc {
460
461
  *
461
462
  * @param interfaceFactory The InterfaceFactory to use for the {@link Actor}.
462
463
  * @param canisterId The Principal of the canister to create the {@link Actor} for.
463
- * @typeparam T The type of the {@link Actor}. Must implement {@link ActorInterface}.
464
+ * @typeParam T The type of the {@link Actor}. Must implement {@link ActorInterface}.
464
465
  * @returns The {@link Actor} instance.
465
466
  *
466
467
  * @see [Principal](https://js.icp.build/core/latest/libs/principal/api/classes/principal/)
@@ -468,7 +469,7 @@ class PocketIc {
468
469
  *
469
470
  * @example
470
471
  * ```ts
471
- * import { Principal } from '@dfinity/principal';
472
+ * import { Principal } from '@icp-sdk/core/principal';
472
473
  * import { PocketIc, PocketIcServer } from '@dfinity/pic';
473
474
  * import { _SERVICE, idlFactory } from '../declarations';
474
475
  *
@@ -504,7 +505,7 @@ class PocketIc {
504
505
  *
505
506
  * @param interfaceFactory The InterfaceFactory to use for the {@link DeferredActor}.
506
507
  * @param canisterId The Principal of the canister to create the {@link DeferredActor} for.
507
- * @typeparam T The type of the {@link DeferredActor}. Must implement {@link ActorInterface}.
508
+ * @typeParam T The type of the {@link DeferredActor}. Must implement {@link ActorInterface}.
508
509
  * @returns The {@link DeferredActor} instance.
509
510
  *
510
511
  * @see [Principal](https://js.icp.build/core/latest/libs/principal/api/classes/principal/)
@@ -524,7 +525,7 @@ class PocketIc {
524
525
  *
525
526
  * @example
526
527
  * ```ts
527
- * import { Principal } from '@dfinity/principal';
528
+ * import { Principal } from '@icp-sdk/core/principal';
528
529
  * import { PocketIc, PocketIcServer } from '@dfinity/pic';
529
530
  * import { _SERVICE, idlFactory } from '../declarations';
530
531
  *
@@ -569,7 +570,7 @@ class PocketIc {
569
570
  *
570
571
  * @example
571
572
  * ```ts
572
- * import { Principal } from '@dfinity/principal';
573
+ * import { Principal } from '@icp-sdk/core/principal';
573
574
  * import { PocketIc, PocketIcServer } from '@dfinity/pic';
574
575
  * import { _SERVICE, idlFactory } from '../declarations';
575
576
  *
@@ -659,7 +660,7 @@ class PocketIc {
659
660
  *
660
661
  * @example
661
662
  * ```ts
662
- * import { Principal } from '@dfinity/principal';
663
+ * import { Principal } from '@icp-sdk/core/principal';
663
664
  *
664
665
  * const canisterId = Principal.fromUint8Array(new Uint8Array([0]));
665
666
  *
@@ -693,8 +694,8 @@ class PocketIc {
693
694
  * ```
694
695
  */
695
696
  async getTime() {
696
- const { millisSinceEpoch } = await this.client.getTime();
697
- return millisSinceEpoch;
697
+ const { nanosSinceEpoch } = await this.client.getTime();
698
+ return Number(nanosSinceEpoch / NANOS_PER_MILLISECOND);
698
699
  }
699
700
  /**
700
701
  * Reset the time of the IC to the current time.
@@ -849,9 +850,10 @@ class PocketIc {
849
850
  * ```
850
851
  */
851
852
  async advanceTime(duration) {
852
- const currentTime = await this.getTime();
853
- const newTime = currentTime + duration;
854
- await this.setTime(newTime);
853
+ const { nanosSinceEpoch } = await this.client.getTime();
854
+ const durationNanos = BigInt(duration) * NANOS_PER_MILLISECOND;
855
+ const newTimeNanos = nanosSinceEpoch + durationNanos;
856
+ await this.client.setTime({ nanosSinceEpoch: newTimeNanos });
855
857
  }
856
858
  /**
857
859
  * Advance the time of the IC by the given duration in milliseconds and
@@ -878,9 +880,10 @@ class PocketIc {
878
880
  * ```
879
881
  */
880
882
  async advanceCertifiedTime(duration) {
881
- const currentTime = await this.getTime();
882
- const newTime = currentTime + duration;
883
- await this.setCertifiedTime(newTime);
883
+ const { nanosSinceEpoch } = await this.client.getTime();
884
+ const durationNanos = BigInt(duration) * NANOS_PER_MILLISECOND;
885
+ const newTimeNanos = nanosSinceEpoch + durationNanos;
886
+ await this.client.setCertifiedTime({ nanosSinceEpoch: newTimeNanos });
884
887
  }
885
888
  /**
886
889
  * Fetch the public key of the specified subnet.
@@ -944,6 +947,37 @@ class PocketIc {
944
947
  const topology = await this.client.getTopology();
945
948
  return Object.values(topology);
946
949
  }
950
+ /**
951
+ * Get the default effective canister id for this PocketIC instance.
952
+ * This is useful when calling [`IcManagementCanister.provisionalCreateCanisterWithCycles`](https://js.icp.build/canisters/latest/api/ic-management/classes/icmanagementcanister#provisionalcreatecanisterwithcycles)
953
+ * on the management canister from `@icp-sdk/canisters/ic-management`.
954
+ *
955
+ * @returns The default effective canister id.
956
+ *
957
+ * @see [Principal](https://js.icp.build/core/latest/libs/principal/api/classes/principal/)
958
+ *
959
+ * @example
960
+ * ```ts
961
+ * import { PocketIc, PocketIcServer } from '@dfinity/pic';
962
+ * import { IcManagementCanister } from '@icp-sdk/canisters/ic-management';
963
+ *
964
+ * const picServer = await PocketIcServer.start();
965
+ * const pic = await PocketIc.create(picServer.getUrl());
966
+ *
967
+ * const defaultEffectiveCanisterId = await pic.getDefaultEffectiveCanisterId();
968
+ *
969
+ * const managementCanister = IcManagementCanister.create({ agent });
970
+ * const canisterId = await managementCanister.provisionalCreateCanisterWithCycles({
971
+ * canisterId: defaultEffectiveCanisterId,
972
+ * });
973
+ *
974
+ * await pic.tearDown();
975
+ * await picServer.stop();
976
+ * ```
977
+ */
978
+ async getDefaultEffectiveCanisterId() {
979
+ return await this.client.getDefaultEffectiveCanisterId();
980
+ }
947
981
  /**
948
982
  * Get the Bitcoin subnet topology for this instance's network.
949
983
  * The instance network topology is configured via the {@link create} method.
@@ -1031,7 +1065,7 @@ class PocketIc {
1031
1065
  *
1032
1066
  * @example
1033
1067
  * ```ts
1034
- * import { Principal } from '@dfinity/principal';
1068
+ * import { Principal } from '@icp-sdk/core/principal';
1035
1069
  * import { PocketIc, PocketIcServer } from '@dfinity/pic';
1036
1070
  *
1037
1071
  * const canisterId = Principal.fromUint8Array(new Uint8Array([0]));
@@ -1060,7 +1094,7 @@ class PocketIc {
1060
1094
  *
1061
1095
  * @example
1062
1096
  * ```ts
1063
- * import { Principal } from '@dfinity/principal';
1097
+ * import { Principal } from '@icp-sdk/core/principal';
1064
1098
  * import { PocketIc, PocketIcServer } from '@dfinity/pic';
1065
1099
  *
1066
1100
  * const canisterId = Principal.fromUint8Array(new Uint8Array([0]));
@@ -1088,7 +1122,7 @@ class PocketIc {
1088
1122
  *
1089
1123
  * @example
1090
1124
  * ```ts
1091
- * import { Principal } from '@dfinity/principal';
1125
+ * import { Principal } from '@icp-sdk/core/principal';
1092
1126
  * import { PocketIc, PocketIcServer } from '@dfinity/pic';
1093
1127
  *
1094
1128
  * const canisterId = Principal.fromUint8Array(new Uint8Array([0]));
@@ -1119,7 +1153,7 @@ class PocketIc {
1119
1153
  *
1120
1154
  * @example
1121
1155
  * ```ts
1122
- * import { Principal } from '@dfinity/principal';
1156
+ * import { Principal } from '@icp-sdk/core/principal';
1123
1157
  * import { PocketIc, PocketIcServer } from '@dfinity/pic';
1124
1158
  *
1125
1159
  * const canisterId = Principal.fromUint8Array(new Uint8Array([0]));
@@ -1145,7 +1179,7 @@ class PocketIc {
1145
1179
  *
1146
1180
  * @example
1147
1181
  * ```ts
1148
- * import { Principal } from '@dfinity/principal';
1182
+ * import { Principal } from '@icp-sdk/core/principal';
1149
1183
  * import { PocketIc, PocketIcServer } from '@dfinity/pic';
1150
1184
  *
1151
1185
  * const canisterId = Principal.fromUint8Array(new Uint8Array([0]));
@@ -1195,7 +1229,7 @@ class PocketIc {
1195
1229
  *
1196
1230
  * @example
1197
1231
  * ```ts
1198
- * import { Principal } from '@dfinity/principal';
1232
+ * import { Principal } from '@icp-sdk/core/principal';
1199
1233
  * import { PocketIc, PocketIcServer } from '@dfinity/pic';
1200
1234
  *
1201
1235
  * const canisterId = Principal.fromUint8Array(new Uint8Array([0]));