@dfinity/pic 0.16.1 → 0.17.1
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.
- package/dist/http2-client.d.ts +2 -0
- package/dist/http2-client.js +10 -6
- package/dist/http2-client.js.map +1 -1
- package/dist/identity.d.ts +3 -3
- package/dist/identity.js +3 -3
- package/dist/identity.js.map +1 -1
- package/dist/management-canister.d.ts +2 -2
- package/dist/management-canister.js +2 -2
- package/dist/management-canister.js.map +1 -1
- package/dist/pocket-ic-actor.d.ts +5 -5
- package/dist/pocket-ic-actor.js +2 -2
- package/dist/pocket-ic-actor.js.map +1 -1
- package/dist/pocket-ic-client-types.d.ts +14 -12
- package/dist/pocket-ic-client-types.js +9 -3
- package/dist/pocket-ic-client-types.js.map +1 -1
- package/dist/pocket-ic-client.d.ts +2 -0
- package/dist/pocket-ic-client.js +13 -5
- package/dist/pocket-ic-client.js.map +1 -1
- package/dist/pocket-ic-deferred-actor.d.ts +5 -5
- package/dist/pocket-ic-deferred-actor.js +2 -2
- package/dist/pocket-ic-deferred-actor.js.map +1 -1
- package/dist/pocket-ic-types.d.ts +20 -20
- package/dist/pocket-ic.d.ts +56 -28
- package/dist/pocket-ic.js +61 -28
- package/dist/pocket-ic.js.map +1 -1
- package/dist/util/candid.d.ts +1 -1
- package/dist/util/candid.js +1 -1
- package/dist/util/candid.js.map +1 -1
- package/dist/util/encoding.d.ts +1 -1
- package/dist/util/encoding.js +1 -1
- package/dist/util/encoding.js.map +1 -1
- package/package.json +4 -6
- package/postinstall.mjs +1 -1
|
@@ -1,6 +1,6 @@
|
|
|
1
|
-
import { Principal } from '@
|
|
1
|
+
import { Principal } from '@icp-sdk/core/principal';
|
|
2
2
|
import { ActorInterface, Actor } from './pocket-ic-actor';
|
|
3
|
-
import { IDL } from '@
|
|
3
|
+
import { IDL } from '@icp-sdk/core/candid';
|
|
4
4
|
import { CanisterInstallModeUpgradeOptions } from './management-canister';
|
|
5
5
|
export { type CanisterInstallModeUpgradeOptions } from './management-canister';
|
|
6
6
|
/**
|
|
@@ -348,14 +348,14 @@ export interface SetupCanisterOptions extends CreateCanisterOptions {
|
|
|
348
348
|
/**
|
|
349
349
|
* The WASM module to install to the canister.
|
|
350
350
|
* If a string is passed, it is treated as a path to a file.
|
|
351
|
-
* If an `
|
|
351
|
+
* If an `Uint8Array` is passed, it is treated as the WASM module itself.
|
|
352
352
|
*/
|
|
353
|
-
wasm:
|
|
353
|
+
wasm: Uint8Array | string;
|
|
354
354
|
/**
|
|
355
355
|
* Candid encoded argument to pass to the canister's init function.
|
|
356
|
-
* Defaults to an empty
|
|
356
|
+
* Defaults to an empty Uint8Array.
|
|
357
357
|
*/
|
|
358
|
-
arg?:
|
|
358
|
+
arg?: Uint8Array;
|
|
359
359
|
/**
|
|
360
360
|
* The principal to setup the canister as.
|
|
361
361
|
* Defaults to the anonymous principal.
|
|
@@ -491,14 +491,14 @@ export interface InstallCodeOptions {
|
|
|
491
491
|
/**
|
|
492
492
|
* The WASM module to install to the canister.
|
|
493
493
|
* If a string is passed, it is treated as a path to a file.
|
|
494
|
-
* If an `
|
|
494
|
+
* If an `Uint8Array` is passed, it is treated as the WASM module itself.
|
|
495
495
|
*/
|
|
496
|
-
wasm:
|
|
496
|
+
wasm: Uint8Array | string;
|
|
497
497
|
/**
|
|
498
498
|
* Candid encoded argument to pass to the canister's init function.
|
|
499
|
-
* Defaults to an empty
|
|
499
|
+
* Defaults to an empty Uint8Array.
|
|
500
500
|
*/
|
|
501
|
-
arg?:
|
|
501
|
+
arg?: Uint8Array;
|
|
502
502
|
/**
|
|
503
503
|
* The principal to install the code as.
|
|
504
504
|
* Defaults to the anonymous principal.
|
|
@@ -524,13 +524,13 @@ export interface ReinstallCodeOptions {
|
|
|
524
524
|
/**
|
|
525
525
|
* The WASM module to install to the canister.
|
|
526
526
|
* If a string is passed, it is treated as a path to a file.
|
|
527
|
-
* If an `
|
|
527
|
+
* If an `Uint8Array` is passed, it is treated as the WASM module itself.
|
|
528
528
|
*/
|
|
529
|
-
wasm:
|
|
529
|
+
wasm: Uint8Array | string;
|
|
530
530
|
/**
|
|
531
531
|
* Candid encoded argument to pass to the canister's init function.
|
|
532
532
|
*/
|
|
533
|
-
arg?:
|
|
533
|
+
arg?: Uint8Array;
|
|
534
534
|
/**
|
|
535
535
|
* The Principal to send the request as.
|
|
536
536
|
* Defaults to the anonymous principal.
|
|
@@ -552,13 +552,13 @@ export interface UpgradeCanisterOptions {
|
|
|
552
552
|
/**
|
|
553
553
|
* The WASM module to install to the canister.
|
|
554
554
|
* If a string is passed, it is treated as a path to a file.
|
|
555
|
-
* If an `
|
|
555
|
+
* If an `Uint8Array` is passed, it is treated as the WASM module itself.
|
|
556
556
|
*/
|
|
557
|
-
wasm:
|
|
557
|
+
wasm: Uint8Array | string;
|
|
558
558
|
/**
|
|
559
559
|
* Candid encoded argument to pass to the canister's init function.
|
|
560
560
|
*/
|
|
561
|
-
arg?:
|
|
561
|
+
arg?: Uint8Array;
|
|
562
562
|
/**
|
|
563
563
|
* The Principal to send the request as.
|
|
564
564
|
* Defaults to the anonymous principal.
|
|
@@ -608,9 +608,9 @@ export interface QueryCallOptions {
|
|
|
608
608
|
method: string;
|
|
609
609
|
/**
|
|
610
610
|
* A Candid encoded argument to pass to the canister's method.
|
|
611
|
-
* Defaults to an empty
|
|
611
|
+
* Defaults to an empty Uint8Array.
|
|
612
612
|
*/
|
|
613
|
-
arg?:
|
|
613
|
+
arg?: Uint8Array;
|
|
614
614
|
/**
|
|
615
615
|
* The ID of the subnet that the canister resides on.
|
|
616
616
|
*/
|
|
@@ -638,9 +638,9 @@ export interface UpdateCallOptions {
|
|
|
638
638
|
method: string;
|
|
639
639
|
/**
|
|
640
640
|
* A Candid encoded argument to pass to the canister's method.
|
|
641
|
-
* Defaults to an empty
|
|
641
|
+
* Defaults to an empty Uint8Array.
|
|
642
642
|
*/
|
|
643
|
-
arg?:
|
|
643
|
+
arg?: Uint8Array;
|
|
644
644
|
/**
|
|
645
645
|
* The ID of the subnet that the canister resides on.
|
|
646
646
|
*/
|
package/dist/pocket-ic.d.ts
CHANGED
|
@@ -1,5 +1,5 @@
|
|
|
1
|
-
import { Principal } from '@
|
|
2
|
-
import { IDL } from '@
|
|
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 '@
|
|
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 '@
|
|
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 '@
|
|
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 '@
|
|
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 '@
|
|
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 '@
|
|
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]));
|
|
@@ -311,7 +311,7 @@ export declare class PocketIc {
|
|
|
311
311
|
*
|
|
312
312
|
* @example
|
|
313
313
|
* ```ts
|
|
314
|
-
* import { Principal } from '@
|
|
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
|
*
|
|
@@ -349,8 +349,6 @@ export declare class PocketIc {
|
|
|
349
349
|
*
|
|
350
350
|
* @see [Principal](https://js.icp.build/core/latest/libs/principal/api/classes/principal/)
|
|
351
351
|
* @see [InterfaceFactory](https://js.icp.build/core/latest/libs/candid/api/namespaces/idl/type-aliases/interfacefactory/)
|
|
352
|
-
*
|
|
353
|
-
* @example
|
|
354
352
|
*/
|
|
355
353
|
createDeferredActor<T extends ActorInterface<T> = ActorInterface>(interfaceFactory: IDL.InterfaceFactory, canisterId: Principal): DeferredActor<T>;
|
|
356
354
|
/**
|
|
@@ -361,7 +359,7 @@ export declare class PocketIc {
|
|
|
361
359
|
*
|
|
362
360
|
* @example
|
|
363
361
|
* ```ts
|
|
364
|
-
* import { Principal } from '@
|
|
362
|
+
* import { Principal } from '@icp-sdk/core/principal';
|
|
365
363
|
* import { PocketIc, PocketIcServer } from '@dfinity/pic';
|
|
366
364
|
* import { _SERVICE, idlFactory } from '../declarations';
|
|
367
365
|
*
|
|
@@ -384,7 +382,7 @@ export declare class PocketIc {
|
|
|
384
382
|
* await picServer.stop();
|
|
385
383
|
* ```
|
|
386
384
|
*/
|
|
387
|
-
queryCall({ canisterId, method, arg, sender, targetSubnetId, }: QueryCallOptions): Promise<
|
|
385
|
+
queryCall({ canisterId, method, arg, sender, targetSubnetId, }: QueryCallOptions): Promise<Uint8Array>;
|
|
388
386
|
/**
|
|
389
387
|
* Makes an update call to the given canister.
|
|
390
388
|
*
|
|
@@ -393,7 +391,7 @@ export declare class PocketIc {
|
|
|
393
391
|
*
|
|
394
392
|
* @example
|
|
395
393
|
* ```ts
|
|
396
|
-
* import { Principal } from '@
|
|
394
|
+
* import { Principal } from '@icp-sdk/core/principal';
|
|
397
395
|
* import { PocketIc, PocketIcServer } from '@dfinity/pic';
|
|
398
396
|
* import { _SERVICE, idlFactory } from '../declarations';
|
|
399
397
|
*
|
|
@@ -416,7 +414,7 @@ export declare class PocketIc {
|
|
|
416
414
|
* await picServer.stop();
|
|
417
415
|
* ```
|
|
418
416
|
*/
|
|
419
|
-
updateCall({ canisterId, method, arg, sender, targetSubnetId, }: UpdateCallOptions): Promise<
|
|
417
|
+
updateCall({ canisterId, method, arg, sender, targetSubnetId, }: UpdateCallOptions): Promise<Uint8Array>;
|
|
420
418
|
/**
|
|
421
419
|
* Deletes the PocketIC instance.
|
|
422
420
|
*
|
|
@@ -464,7 +462,7 @@ export declare class PocketIc {
|
|
|
464
462
|
*
|
|
465
463
|
* @example
|
|
466
464
|
* ```ts
|
|
467
|
-
* import { Principal } from '@
|
|
465
|
+
* import { Principal } from '@icp-sdk/core/principal';
|
|
468
466
|
*
|
|
469
467
|
* const canisterId = Principal.fromUint8Array(new Uint8Array([0]));
|
|
470
468
|
*
|
|
@@ -475,6 +473,7 @@ export declare class PocketIc {
|
|
|
475
473
|
*
|
|
476
474
|
* await pic.tearDown();
|
|
477
475
|
* await picServer.stop();
|
|
476
|
+
* ```
|
|
478
477
|
*/
|
|
479
478
|
getControllers(canisterId: Principal): Promise<Principal[]>;
|
|
480
479
|
/**
|
|
@@ -680,7 +679,7 @@ export declare class PocketIc {
|
|
|
680
679
|
* await picServer.stop();
|
|
681
680
|
* ```
|
|
682
681
|
*/
|
|
683
|
-
getPubKey(subnetId: Principal): Promise<
|
|
682
|
+
getPubKey(subnetId: Principal): Promise<Uint8Array>;
|
|
684
683
|
/**
|
|
685
684
|
* Gets the subnet Id of the provided canister Id.
|
|
686
685
|
*
|
|
@@ -714,6 +713,35 @@ export declare class PocketIc {
|
|
|
714
713
|
* @returns An array of subnet topologies, see {@link SubnetTopology}.
|
|
715
714
|
*/
|
|
716
715
|
getTopology(): Promise<SubnetTopology[]>;
|
|
716
|
+
/**
|
|
717
|
+
* Get the default effective canister id for this PocketIC instance.
|
|
718
|
+
* This is useful when calling [`IcManagementCanister.provisionalCreateCanisterWithCycles`](https://js.icp.build/canisters/latest/api/ic-management/classes/icmanagementcanister#provisionalcreatecanisterwithcycles)
|
|
719
|
+
* on the management canister from `@icp-sdk/canisters/ic-management`.
|
|
720
|
+
*
|
|
721
|
+
* @returns The default effective canister id.
|
|
722
|
+
*
|
|
723
|
+
* @see [Principal](https://js.icp.build/core/latest/libs/principal/api/classes/principal/)
|
|
724
|
+
*
|
|
725
|
+
* @example
|
|
726
|
+
* ```ts
|
|
727
|
+
* import { PocketIc, PocketIcServer } from '@dfinity/pic';
|
|
728
|
+
* import { IcManagementCanister } from '@icp-sdk/canisters/ic-management';
|
|
729
|
+
*
|
|
730
|
+
* const picServer = await PocketIcServer.start();
|
|
731
|
+
* const pic = await PocketIc.create(picServer.getUrl());
|
|
732
|
+
*
|
|
733
|
+
* const defaultEffectiveCanisterId = await pic.getDefaultEffectiveCanisterId();
|
|
734
|
+
*
|
|
735
|
+
* const managementCanister = IcManagementCanister.create({ agent });
|
|
736
|
+
* const canisterId = await managementCanister.provisionalCreateCanisterWithCycles({
|
|
737
|
+
* canisterId: defaultEffectiveCanisterId,
|
|
738
|
+
* });
|
|
739
|
+
*
|
|
740
|
+
* await pic.tearDown();
|
|
741
|
+
* await picServer.stop();
|
|
742
|
+
* ```
|
|
743
|
+
*/
|
|
744
|
+
getDefaultEffectiveCanisterId(): Promise<Principal>;
|
|
717
745
|
/**
|
|
718
746
|
* Get the Bitcoin subnet topology for this instance's network.
|
|
719
747
|
* The instance network topology is configured via the {@link create} method.
|
|
@@ -780,7 +808,7 @@ export declare class PocketIc {
|
|
|
780
808
|
*
|
|
781
809
|
* @example
|
|
782
810
|
* ```ts
|
|
783
|
-
* import { Principal } from '@
|
|
811
|
+
* import { Principal } from '@icp-sdk/core/principal';
|
|
784
812
|
* import { PocketIc, PocketIcServer } from '@dfinity/pic';
|
|
785
813
|
*
|
|
786
814
|
* const canisterId = Principal.fromUint8Array(new Uint8Array([0]));
|
|
@@ -794,7 +822,7 @@ export declare class PocketIc {
|
|
|
794
822
|
* await picServer.stop();
|
|
795
823
|
* ```
|
|
796
824
|
*/
|
|
797
|
-
getCyclesBalance(canisterId: Principal): Promise<
|
|
825
|
+
getCyclesBalance(canisterId: Principal): Promise<bigint>;
|
|
798
826
|
/**
|
|
799
827
|
* Add cycles to the specified canister.
|
|
800
828
|
*
|
|
@@ -806,7 +834,7 @@ export declare class PocketIc {
|
|
|
806
834
|
*
|
|
807
835
|
* @example
|
|
808
836
|
* ```ts
|
|
809
|
-
* import { Principal } from '@
|
|
837
|
+
* import { Principal } from '@icp-sdk/core/principal';
|
|
810
838
|
* import { PocketIc, PocketIcServer } from '@dfinity/pic';
|
|
811
839
|
*
|
|
812
840
|
* const canisterId = Principal.fromUint8Array(new Uint8Array([0]));
|
|
@@ -814,13 +842,13 @@ export declare class PocketIc {
|
|
|
814
842
|
* const picServer = await PocketIcServer.start();
|
|
815
843
|
* const pic = await PocketIc.create(picServer.getUrl());
|
|
816
844
|
*
|
|
817
|
-
* const newCyclesBalance = await pic.addCycles(canisterId, 10_000_000);
|
|
845
|
+
* const newCyclesBalance = await pic.addCycles(canisterId, BigInt(10_000_000));
|
|
818
846
|
*
|
|
819
847
|
* await pic.tearDown();
|
|
820
848
|
* await picServer.stop();
|
|
821
849
|
* ```
|
|
822
850
|
*/
|
|
823
|
-
addCycles(canisterId: Principal, amount:
|
|
851
|
+
addCycles(canisterId: Principal, amount: bigint): Promise<bigint>;
|
|
824
852
|
/**
|
|
825
853
|
* Set the stable memory of a given canister.
|
|
826
854
|
*
|
|
@@ -831,7 +859,7 @@ export declare class PocketIc {
|
|
|
831
859
|
*
|
|
832
860
|
* @example
|
|
833
861
|
* ```ts
|
|
834
|
-
* import { Principal } from '@
|
|
862
|
+
* import { Principal } from '@icp-sdk/core/principal';
|
|
835
863
|
* import { PocketIc, PocketIcServer } from '@dfinity/pic';
|
|
836
864
|
*
|
|
837
865
|
* const canisterId = Principal.fromUint8Array(new Uint8Array([0]));
|
|
@@ -846,7 +874,7 @@ export declare class PocketIc {
|
|
|
846
874
|
* await picServer.stop();
|
|
847
875
|
* ```
|
|
848
876
|
*/
|
|
849
|
-
setStableMemory(canisterId: Principal, stableMemory:
|
|
877
|
+
setStableMemory(canisterId: Principal, stableMemory: Uint8Array): Promise<void>;
|
|
850
878
|
/**
|
|
851
879
|
* Get the stable memory of a given canister.
|
|
852
880
|
*
|
|
@@ -857,7 +885,7 @@ export declare class PocketIc {
|
|
|
857
885
|
*
|
|
858
886
|
* @example
|
|
859
887
|
* ```ts
|
|
860
|
-
* import { Principal } from '@
|
|
888
|
+
* import { Principal } from '@icp-sdk/core/principal';
|
|
861
889
|
* import { PocketIc, PocketIcServer } from '@dfinity/pic';
|
|
862
890
|
*
|
|
863
891
|
* const canisterId = Principal.fromUint8Array(new Uint8Array([0]));
|
|
@@ -871,7 +899,7 @@ export declare class PocketIc {
|
|
|
871
899
|
* await picServer.stop();
|
|
872
900
|
* ```
|
|
873
901
|
*/
|
|
874
|
-
getStableMemory(canisterId: Principal): Promise<
|
|
902
|
+
getStableMemory(canisterId: Principal): Promise<Uint8Array>;
|
|
875
903
|
/**
|
|
876
904
|
* Get all pending HTTPS Outcalls across all subnets on this
|
|
877
905
|
* PocketIC instance.
|
|
@@ -880,7 +908,7 @@ export declare class PocketIc {
|
|
|
880
908
|
*
|
|
881
909
|
* @example
|
|
882
910
|
* ```ts
|
|
883
|
-
* import { Principal } from '@
|
|
911
|
+
* import { Principal } from '@icp-sdk/core/principal';
|
|
884
912
|
* import { PocketIc, PocketIcServer } from '@dfinity/pic';
|
|
885
913
|
*
|
|
886
914
|
* const canisterId = Principal.fromUint8Array(new Uint8Array([0]));
|
|
@@ -928,7 +956,7 @@ export declare class PocketIc {
|
|
|
928
956
|
*
|
|
929
957
|
* @example
|
|
930
958
|
* ```ts
|
|
931
|
-
* import { Principal } from '@
|
|
959
|
+
* import { Principal } from '@icp-sdk/core/principal';
|
|
932
960
|
* import { PocketIc, PocketIcServer } from '@dfinity/pic';
|
|
933
961
|
*
|
|
934
962
|
* 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("@
|
|
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 '@
|
|
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 '@
|
|
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 '@
|
|
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 '@
|
|
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 '@
|
|
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 '@
|
|
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]));
|
|
@@ -468,7 +469,7 @@ class PocketIc {
|
|
|
468
469
|
*
|
|
469
470
|
* @example
|
|
470
471
|
* ```ts
|
|
471
|
-
* import { Principal } from '@
|
|
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
|
*
|
|
@@ -509,8 +510,6 @@ class PocketIc {
|
|
|
509
510
|
*
|
|
510
511
|
* @see [Principal](https://js.icp.build/core/latest/libs/principal/api/classes/principal/)
|
|
511
512
|
* @see [InterfaceFactory](https://js.icp.build/core/latest/libs/candid/api/namespaces/idl/type-aliases/interfacefactory/)
|
|
512
|
-
*
|
|
513
|
-
* @example
|
|
514
513
|
*/
|
|
515
514
|
createDeferredActor(interfaceFactory, canisterId) {
|
|
516
515
|
const DeferredActor = (0, pocket_ic_deferred_actor_1.createDeferredActorClass)(interfaceFactory, canisterId, this.client);
|
|
@@ -524,7 +523,7 @@ class PocketIc {
|
|
|
524
523
|
*
|
|
525
524
|
* @example
|
|
526
525
|
* ```ts
|
|
527
|
-
* import { Principal } from '@
|
|
526
|
+
* import { Principal } from '@icp-sdk/core/principal';
|
|
528
527
|
* import { PocketIc, PocketIcServer } from '@dfinity/pic';
|
|
529
528
|
* import { _SERVICE, idlFactory } from '../declarations';
|
|
530
529
|
*
|
|
@@ -569,7 +568,7 @@ class PocketIc {
|
|
|
569
568
|
*
|
|
570
569
|
* @example
|
|
571
570
|
* ```ts
|
|
572
|
-
* import { Principal } from '@
|
|
571
|
+
* import { Principal } from '@icp-sdk/core/principal';
|
|
573
572
|
* import { PocketIc, PocketIcServer } from '@dfinity/pic';
|
|
574
573
|
* import { _SERVICE, idlFactory } from '../declarations';
|
|
575
574
|
*
|
|
@@ -659,7 +658,7 @@ class PocketIc {
|
|
|
659
658
|
*
|
|
660
659
|
* @example
|
|
661
660
|
* ```ts
|
|
662
|
-
* import { Principal } from '@
|
|
661
|
+
* import { Principal } from '@icp-sdk/core/principal';
|
|
663
662
|
*
|
|
664
663
|
* const canisterId = Principal.fromUint8Array(new Uint8Array([0]));
|
|
665
664
|
*
|
|
@@ -670,6 +669,7 @@ class PocketIc {
|
|
|
670
669
|
*
|
|
671
670
|
* await pic.tearDown();
|
|
672
671
|
* await picServer.stop();
|
|
672
|
+
* ```
|
|
673
673
|
*/
|
|
674
674
|
async getControllers(canisterId) {
|
|
675
675
|
return await this.client.getControllers({ canisterId });
|
|
@@ -693,8 +693,8 @@ class PocketIc {
|
|
|
693
693
|
* ```
|
|
694
694
|
*/
|
|
695
695
|
async getTime() {
|
|
696
|
-
const {
|
|
697
|
-
return
|
|
696
|
+
const { nanosSinceEpoch } = await this.client.getTime();
|
|
697
|
+
return Number(nanosSinceEpoch / NANOS_PER_MILLISECOND);
|
|
698
698
|
}
|
|
699
699
|
/**
|
|
700
700
|
* Reset the time of the IC to the current time.
|
|
@@ -849,9 +849,10 @@ class PocketIc {
|
|
|
849
849
|
* ```
|
|
850
850
|
*/
|
|
851
851
|
async advanceTime(duration) {
|
|
852
|
-
const
|
|
853
|
-
const
|
|
854
|
-
|
|
852
|
+
const { nanosSinceEpoch } = await this.client.getTime();
|
|
853
|
+
const durationNanos = BigInt(duration) * NANOS_PER_MILLISECOND;
|
|
854
|
+
const newTimeNanos = nanosSinceEpoch + durationNanos;
|
|
855
|
+
await this.client.setTime({ nanosSinceEpoch: newTimeNanos });
|
|
855
856
|
}
|
|
856
857
|
/**
|
|
857
858
|
* Advance the time of the IC by the given duration in milliseconds and
|
|
@@ -878,9 +879,10 @@ class PocketIc {
|
|
|
878
879
|
* ```
|
|
879
880
|
*/
|
|
880
881
|
async advanceCertifiedTime(duration) {
|
|
881
|
-
const
|
|
882
|
-
const
|
|
883
|
-
|
|
882
|
+
const { nanosSinceEpoch } = await this.client.getTime();
|
|
883
|
+
const durationNanos = BigInt(duration) * NANOS_PER_MILLISECOND;
|
|
884
|
+
const newTimeNanos = nanosSinceEpoch + durationNanos;
|
|
885
|
+
await this.client.setCertifiedTime({ nanosSinceEpoch: newTimeNanos });
|
|
884
886
|
}
|
|
885
887
|
/**
|
|
886
888
|
* Fetch the public key of the specified subnet.
|
|
@@ -944,6 +946,37 @@ class PocketIc {
|
|
|
944
946
|
const topology = await this.client.getTopology();
|
|
945
947
|
return Object.values(topology);
|
|
946
948
|
}
|
|
949
|
+
/**
|
|
950
|
+
* Get the default effective canister id for this PocketIC instance.
|
|
951
|
+
* This is useful when calling [`IcManagementCanister.provisionalCreateCanisterWithCycles`](https://js.icp.build/canisters/latest/api/ic-management/classes/icmanagementcanister#provisionalcreatecanisterwithcycles)
|
|
952
|
+
* on the management canister from `@icp-sdk/canisters/ic-management`.
|
|
953
|
+
*
|
|
954
|
+
* @returns The default effective canister id.
|
|
955
|
+
*
|
|
956
|
+
* @see [Principal](https://js.icp.build/core/latest/libs/principal/api/classes/principal/)
|
|
957
|
+
*
|
|
958
|
+
* @example
|
|
959
|
+
* ```ts
|
|
960
|
+
* import { PocketIc, PocketIcServer } from '@dfinity/pic';
|
|
961
|
+
* import { IcManagementCanister } from '@icp-sdk/canisters/ic-management';
|
|
962
|
+
*
|
|
963
|
+
* const picServer = await PocketIcServer.start();
|
|
964
|
+
* const pic = await PocketIc.create(picServer.getUrl());
|
|
965
|
+
*
|
|
966
|
+
* const defaultEffectiveCanisterId = await pic.getDefaultEffectiveCanisterId();
|
|
967
|
+
*
|
|
968
|
+
* const managementCanister = IcManagementCanister.create({ agent });
|
|
969
|
+
* const canisterId = await managementCanister.provisionalCreateCanisterWithCycles({
|
|
970
|
+
* canisterId: defaultEffectiveCanisterId,
|
|
971
|
+
* });
|
|
972
|
+
*
|
|
973
|
+
* await pic.tearDown();
|
|
974
|
+
* await picServer.stop();
|
|
975
|
+
* ```
|
|
976
|
+
*/
|
|
977
|
+
async getDefaultEffectiveCanisterId() {
|
|
978
|
+
return await this.client.getDefaultEffectiveCanisterId();
|
|
979
|
+
}
|
|
947
980
|
/**
|
|
948
981
|
* Get the Bitcoin subnet topology for this instance's network.
|
|
949
982
|
* The instance network topology is configured via the {@link create} method.
|
|
@@ -1031,7 +1064,7 @@ class PocketIc {
|
|
|
1031
1064
|
*
|
|
1032
1065
|
* @example
|
|
1033
1066
|
* ```ts
|
|
1034
|
-
* import { Principal } from '@
|
|
1067
|
+
* import { Principal } from '@icp-sdk/core/principal';
|
|
1035
1068
|
* import { PocketIc, PocketIcServer } from '@dfinity/pic';
|
|
1036
1069
|
*
|
|
1037
1070
|
* const canisterId = Principal.fromUint8Array(new Uint8Array([0]));
|
|
@@ -1060,7 +1093,7 @@ class PocketIc {
|
|
|
1060
1093
|
*
|
|
1061
1094
|
* @example
|
|
1062
1095
|
* ```ts
|
|
1063
|
-
* import { Principal } from '@
|
|
1096
|
+
* import { Principal } from '@icp-sdk/core/principal';
|
|
1064
1097
|
* import { PocketIc, PocketIcServer } from '@dfinity/pic';
|
|
1065
1098
|
*
|
|
1066
1099
|
* const canisterId = Principal.fromUint8Array(new Uint8Array([0]));
|
|
@@ -1068,7 +1101,7 @@ class PocketIc {
|
|
|
1068
1101
|
* const picServer = await PocketIcServer.start();
|
|
1069
1102
|
* const pic = await PocketIc.create(picServer.getUrl());
|
|
1070
1103
|
*
|
|
1071
|
-
* const newCyclesBalance = await pic.addCycles(canisterId, 10_000_000);
|
|
1104
|
+
* const newCyclesBalance = await pic.addCycles(canisterId, BigInt(10_000_000));
|
|
1072
1105
|
*
|
|
1073
1106
|
* await pic.tearDown();
|
|
1074
1107
|
* await picServer.stop();
|
|
@@ -1088,7 +1121,7 @@ class PocketIc {
|
|
|
1088
1121
|
*
|
|
1089
1122
|
* @example
|
|
1090
1123
|
* ```ts
|
|
1091
|
-
* import { Principal } from '@
|
|
1124
|
+
* import { Principal } from '@icp-sdk/core/principal';
|
|
1092
1125
|
* import { PocketIc, PocketIcServer } from '@dfinity/pic';
|
|
1093
1126
|
*
|
|
1094
1127
|
* const canisterId = Principal.fromUint8Array(new Uint8Array([0]));
|
|
@@ -1119,7 +1152,7 @@ class PocketIc {
|
|
|
1119
1152
|
*
|
|
1120
1153
|
* @example
|
|
1121
1154
|
* ```ts
|
|
1122
|
-
* import { Principal } from '@
|
|
1155
|
+
* import { Principal } from '@icp-sdk/core/principal';
|
|
1123
1156
|
* import { PocketIc, PocketIcServer } from '@dfinity/pic';
|
|
1124
1157
|
*
|
|
1125
1158
|
* const canisterId = Principal.fromUint8Array(new Uint8Array([0]));
|
|
@@ -1145,7 +1178,7 @@ class PocketIc {
|
|
|
1145
1178
|
*
|
|
1146
1179
|
* @example
|
|
1147
1180
|
* ```ts
|
|
1148
|
-
* import { Principal } from '@
|
|
1181
|
+
* import { Principal } from '@icp-sdk/core/principal';
|
|
1149
1182
|
* import { PocketIc, PocketIcServer } from '@dfinity/pic';
|
|
1150
1183
|
*
|
|
1151
1184
|
* const canisterId = Principal.fromUint8Array(new Uint8Array([0]));
|
|
@@ -1195,7 +1228,7 @@ class PocketIc {
|
|
|
1195
1228
|
*
|
|
1196
1229
|
* @example
|
|
1197
1230
|
* ```ts
|
|
1198
|
-
* import { Principal } from '@
|
|
1231
|
+
* import { Principal } from '@icp-sdk/core/principal';
|
|
1199
1232
|
* import { PocketIc, PocketIcServer } from '@dfinity/pic';
|
|
1200
1233
|
*
|
|
1201
1234
|
* const canisterId = Principal.fromUint8Array(new Uint8Array([0]));
|