ic-mops 0.37.0 → 0.37.2

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 (64) hide show
  1. package/dist/package.json +2 -1
  2. package/package.json +2 -1
  3. package/dist/cli-local.d.ts +0 -2
  4. package/dist/cli-local.js +0 -2
  5. package/dist/commands/toolchain/mocv.d.ts +0 -1
  6. package/dist/commands/toolchain/mocv.js +0 -271
  7. package/dist/moc-wrapper.d.ts +0 -2
  8. package/dist/moc-wrapper.js +0 -8
  9. package/dist/out/cli.d.ts +0 -2
  10. package/dist/out/cli.js +0 -115242
  11. package/dist/pic-js/examples/clock/tests/clock/index.d.ts +0 -1
  12. package/dist/pic-js/examples/clock/tests/clock/index.js +0 -5
  13. package/dist/pic-js/examples/clock/tests/jest.config.d.ts +0 -3
  14. package/dist/pic-js/examples/clock/tests/jest.config.js +0 -8
  15. package/dist/pic-js/examples/clock/tests/src/clock.spec.d.ts +0 -1
  16. package/dist/pic-js/examples/clock/tests/src/clock.spec.js +0 -48
  17. package/dist/pic-js/examples/counter/tests/counter/index.d.ts +0 -1
  18. package/dist/pic-js/examples/counter/tests/counter/index.js +0 -5
  19. package/dist/pic-js/examples/counter/tests/jest.config.d.ts +0 -3
  20. package/dist/pic-js/examples/counter/tests/jest.config.js +0 -8
  21. package/dist/pic-js/examples/counter/tests/src/counter.spec.d.ts +0 -1
  22. package/dist/pic-js/examples/counter/tests/src/counter.spec.js +0 -80
  23. package/dist/pic-js/examples/todo/tests/jest.config.d.ts +0 -3
  24. package/dist/pic-js/examples/todo/tests/jest.config.js +0 -8
  25. package/dist/pic-js/examples/todo/tests/src/todo.spec.d.ts +0 -1
  26. package/dist/pic-js/examples/todo/tests/src/todo.spec.js +0 -211
  27. package/dist/pic-js/examples/todo/tests/todo/index.d.ts +0 -1
  28. package/dist/pic-js/examples/todo/tests/todo/index.js +0 -5
  29. package/dist/pic-js/packages/pic/src/error.d.ts +0 -12
  30. package/dist/pic-js/packages/pic/src/error.js +0 -36
  31. package/dist/pic-js/packages/pic/src/http-client.d.ts +0 -15
  32. package/dist/pic-js/packages/pic/src/http-client.js +0 -37
  33. package/dist/pic-js/packages/pic/src/identity.d.ts +0 -66
  34. package/dist/pic-js/packages/pic/src/identity.js +0 -86
  35. package/dist/pic-js/packages/pic/src/index.d.ts +0 -4
  36. package/dist/pic-js/packages/pic/src/index.js +0 -8
  37. package/dist/pic-js/packages/pic/src/management-canister.d.ts +0 -30
  38. package/dist/pic-js/packages/pic/src/management-canister.js +0 -43
  39. package/dist/pic-js/packages/pic/src/pocket-ic-actor.d.ts +0 -83
  40. package/dist/pic-js/packages/pic/src/pocket-ic-actor.js +0 -58
  41. package/dist/pic-js/packages/pic/src/pocket-ic-client-types.d.ts +0 -61
  42. package/dist/pic-js/packages/pic/src/pocket-ic-client-types.js +0 -2
  43. package/dist/pic-js/packages/pic/src/pocket-ic-client.d.ts +0 -24
  44. package/dist/pic-js/packages/pic/src/pocket-ic-client.js +0 -123
  45. package/dist/pic-js/packages/pic/src/pocket-ic-server.d.ts +0 -10
  46. package/dist/pic-js/packages/pic/src/pocket-ic-server.js +0 -55
  47. package/dist/pic-js/packages/pic/src/pocket-ic-types.d.ts +0 -40
  48. package/dist/pic-js/packages/pic/src/pocket-ic-types.js +0 -2
  49. package/dist/pic-js/packages/pic/src/pocket-ic.d.ts +0 -447
  50. package/dist/pic-js/packages/pic/src/pocket-ic.js +0 -551
  51. package/dist/pic-js/packages/pic/src/util/candid.d.ts +0 -1
  52. package/dist/pic-js/packages/pic/src/util/candid.js +0 -7
  53. package/dist/pic-js/packages/pic/src/util/encoding.d.ts +0 -5
  54. package/dist/pic-js/packages/pic/src/util/encoding.js +0 -19
  55. package/dist/pic-js/packages/pic/src/util/fs.d.ts +0 -4
  56. package/dist/pic-js/packages/pic/src/util/fs.js +0 -29
  57. package/dist/pic-js/packages/pic/src/util/index.d.ts +0 -5
  58. package/dist/pic-js/packages/pic/src/util/index.js +0 -21
  59. package/dist/pic-js/packages/pic/src/util/os.d.ts +0 -4
  60. package/dist/pic-js/packages/pic/src/util/os.js +0 -19
  61. package/dist/pic-js/packages/pic/src/util/poll.d.ts +0 -5
  62. package/dist/pic-js/packages/pic/src/util/poll.js +0 -28
  63. package/dist/templates/cli.d.ts +0 -2
  64. package/dist/templates/cli.js +0 -3660
@@ -1,86 +0,0 @@
1
- "use strict";
2
- Object.defineProperty(exports, "__esModule", { value: true });
3
- exports.generateRandomIdentity = exports.createIdentity = void 0;
4
- const node_crypto_1 = require("node:crypto");
5
- const bip39_1 = require("bip39");
6
- const identity_1 = require("@dfinity/identity");
7
- /**
8
- * Create an Identity from a seed phrase.
9
- * The seed phrase can be any arbitrary string.
10
- *
11
- * The Identity is generated deterministically from the seed phrase,
12
- * so subsequent calls to this function with the same seed phrase will
13
- * produce the same Identity.
14
- *
15
- * This is useful for tests where a persistent Identity is necessary
16
- * but it's easier to store the seed phrase than the Identity itself.
17
- *
18
- * @category API
19
- * @param seedPhrase The seed phrase to create the identity from. Can be any arbitrary string.
20
- * @returns An identity created from the seed phrase.
21
- *
22
- * @see [Identity](https://agent-js.icp.xyz/agent/interfaces/Identity.html)
23
- *
24
- * @example
25
- * ```ts
26
- * import { PocketIc, createIdentity } from '@hadronous/pic';
27
- * import { AnonymousIdentity } from '@dfinity/agent';
28
- * import { _SERVICE, idlFactory } from '../declarations';
29
- *
30
- * const wasmPath = resolve('..', '..', 'canister.wasm');
31
- *
32
- * const pic = await PocketIc.create();
33
- * const fixture = await pic.setupCanister<_SERVICE>(idlFactory, wasmPath);
34
- * const { actor } = fixture;
35
- *
36
- * const bob = createIdentity('SuperSecretSeedPhraseForBob');
37
- * actor.setIdentity(bob);
38
- * ```
39
- */
40
- function createIdentity(seedPhrase) {
41
- const hash = (0, node_crypto_1.createHash)('sha256');
42
- hash.update(seedPhrase);
43
- const digest = hash.digest('hex').slice(0, 32);
44
- const encodedDigest = new TextEncoder().encode(digest);
45
- return identity_1.Ed25519KeyIdentity.generate(encodedDigest);
46
- }
47
- exports.createIdentity = createIdentity;
48
- function generateMnemonic() {
49
- const entropy = (0, node_crypto_1.randomBytes)(16);
50
- return (0, bip39_1.entropyToMnemonic)(entropy);
51
- }
52
- /**
53
- * Create an Identity from a randomly generated bip39 seed phrase.
54
- * Subsequent calls to this function will produce different Identities
55
- * with an extremely low probability of collision.
56
- *
57
- * This is useful for tests where it is important to avoid conflicts arising
58
- * from multiple identities accessing the same canister and maintaining
59
- * the necessary seed phrases would become cumbersome.
60
- *
61
- * @category API
62
- * @returns An identity created from a random seed phrase.
63
- *
64
- * @see [Identity](https://agent-js.icp.xyz/agent/interfaces/Identity.html)
65
- *
66
- * @example
67
- * ```ts
68
- * import { PocketIc, generateRandomIdentity } from '@hadronous/pic';
69
- * import { AnonymousIdentity } from '@dfinity/agent';
70
- * import { _SERVICE, idlFactory } from '../declarations';
71
- *
72
- * const wasmPath = resolve('..', '..', 'canister.wasm');
73
- *
74
- * const pic = await PocketIc.create();
75
- * const fixture = await pic.setupCanister<_SERVICE>(idlFactory, wasmPath);
76
- * const { actor } = fixture;
77
- *
78
- * const bob = generateRandomIdentity();
79
- * actor.setIdentity(bob);
80
- * ```
81
- */
82
- function generateRandomIdentity() {
83
- const mnemonic = generateMnemonic();
84
- return createIdentity(mnemonic);
85
- }
86
- exports.generateRandomIdentity = generateRandomIdentity;
@@ -1,4 +0,0 @@
1
- export { createIdentity, generateRandomIdentity } from './identity';
2
- export type { Actor, ActorInterface, ActorMethod } from './pocket-ic-actor';
3
- export { PocketIc } from './pocket-ic';
4
- export type { CanisterFixture, CreateCanisterOptions } from './pocket-ic-types';
@@ -1,8 +0,0 @@
1
- "use strict";
2
- Object.defineProperty(exports, "__esModule", { value: true });
3
- exports.PocketIc = exports.generateRandomIdentity = exports.createIdentity = void 0;
4
- var identity_1 = require("./identity");
5
- Object.defineProperty(exports, "createIdentity", { enumerable: true, get: function () { return identity_1.createIdentity; } });
6
- Object.defineProperty(exports, "generateRandomIdentity", { enumerable: true, get: function () { return identity_1.generateRandomIdentity; } });
7
- var pocket_ic_1 = require("./pocket-ic");
8
- Object.defineProperty(exports, "PocketIc", { enumerable: true, get: function () { return pocket_ic_1.PocketIc; } });
@@ -1,30 +0,0 @@
1
- import { IDL } from '@dfinity/candid';
2
- import { Principal } from '@dfinity/principal';
3
- export declare const MANAGEMENT_CANISTER_ID: Principal;
4
- export interface CanisterSettings {
5
- controllers: Principal[];
6
- compute_allocation: [] | [bigint];
7
- memory_allocation: [] | [bigint];
8
- freezing_threshold: [] | [bigint];
9
- }
10
- export declare const CanisterSettings: IDL.OptClass<Record<string, any>>;
11
- export interface CreateCanisterRequest {
12
- settings: [] | [CanisterSettings];
13
- amount: [] | [bigint];
14
- }
15
- export declare function encodeCreateCanisterRequest(arg: CreateCanisterRequest): Uint8Array;
16
- export interface CreateCanisterResponse {
17
- canister_id: Principal;
18
- }
19
- export declare function decodeCreateCanisterResponse(arg: Uint8Array): CreateCanisterResponse;
20
- export interface InstallCodeRequest {
21
- arg: Uint8Array;
22
- wasm_module: Uint8Array;
23
- mode: {
24
- reinstall?: null;
25
- upgrade?: null;
26
- install?: null;
27
- };
28
- canister_id: Principal;
29
- }
30
- export declare function encodeInstallCodeRequest(arg: InstallCodeRequest): Uint8Array;
@@ -1,43 +0,0 @@
1
- "use strict";
2
- Object.defineProperty(exports, "__esModule", { value: true });
3
- exports.encodeInstallCodeRequest = exports.decodeCreateCanisterResponse = exports.encodeCreateCanisterRequest = exports.CanisterSettings = exports.MANAGEMENT_CANISTER_ID = void 0;
4
- const candid_1 = require("@dfinity/candid");
5
- const principal_1 = require("@dfinity/principal");
6
- exports.MANAGEMENT_CANISTER_ID = principal_1.Principal.fromText('aaaaa-aa');
7
- exports.CanisterSettings = candid_1.IDL.Opt(candid_1.IDL.Record({
8
- controllers: candid_1.IDL.Opt(candid_1.IDL.Vec(candid_1.IDL.Principal)),
9
- compute_allocation: candid_1.IDL.Opt(candid_1.IDL.Nat),
10
- memory_allocation: candid_1.IDL.Opt(candid_1.IDL.Nat),
11
- freezing_threshold: candid_1.IDL.Opt(candid_1.IDL.Nat),
12
- }));
13
- const CreateCanisterRequest = candid_1.IDL.Record({
14
- settings: exports.CanisterSettings,
15
- amount: candid_1.IDL.Opt(candid_1.IDL.Nat),
16
- });
17
- function encodeCreateCanisterRequest(arg) {
18
- return new Uint8Array(candid_1.IDL.encode([CreateCanisterRequest], [arg]));
19
- }
20
- exports.encodeCreateCanisterRequest = encodeCreateCanisterRequest;
21
- const CreateCanisterResponse = candid_1.IDL.Record({
22
- canister_id: candid_1.IDL.Principal,
23
- });
24
- function decodeCreateCanisterResponse(arg) {
25
- const [payload] = candid_1.IDL.decode([CreateCanisterResponse], arg);
26
- // [TODO] - type check?
27
- return payload;
28
- }
29
- exports.decodeCreateCanisterResponse = decodeCreateCanisterResponse;
30
- const InstallCodeRequest = candid_1.IDL.Record({
31
- arg: candid_1.IDL.Vec(candid_1.IDL.Nat8),
32
- wasm_module: candid_1.IDL.Vec(candid_1.IDL.Nat8),
33
- mode: candid_1.IDL.Variant({
34
- reinstall: candid_1.IDL.Null,
35
- upgrade: candid_1.IDL.Null,
36
- install: candid_1.IDL.Null,
37
- }),
38
- canister_id: candid_1.IDL.Principal,
39
- });
40
- function encodeInstallCodeRequest(arg) {
41
- return new Uint8Array(candid_1.IDL.encode([InstallCodeRequest], [arg]));
42
- }
43
- exports.encodeInstallCodeRequest = encodeInstallCodeRequest;
@@ -1,83 +0,0 @@
1
- import { IDL } from '@dfinity/candid';
2
- import { Principal } from '@dfinity/principal';
3
- import { Identity } from '@dfinity/agent';
4
- import { PocketIcClient } from './pocket-ic-client';
5
- /**
6
- * Typesafe method of a canister.
7
- *
8
- * @category Types
9
- */
10
- export interface ActorMethod<Args extends unknown[] = unknown[], Ret = unknown> {
11
- (...args: Args): Promise<Ret>;
12
- }
13
- /**
14
- * Candid interface of a canister.
15
- *
16
- * @category Types
17
- */
18
- export type ActorInterface = Record<string, ActorMethod>;
19
- /**
20
- * A typesafe class that implements the Candid interface of a canister.
21
- * This is acquired by calling {@link PocketIc.setupCanister | setupCanister}
22
- * or {@link PocketIc.createActor | createActor}.
23
- *
24
- * @category API
25
- * @typeparam T The type of the {@link Actor}. Must implement {@link ActorInterface}.
26
- * @interface
27
- */
28
- export type Actor<T = ActorInterface> = T & {
29
- /**
30
- * @ignore
31
- */
32
- new (): Actor<T>;
33
- /**
34
- * Set a Principal to be used as sender for all calls to the canister.
35
- *
36
- * @param principal The Principal to set.
37
- *
38
- * @see [Principal](https://agent-js.icp.xyz/principal/classes/Principal.html)
39
- *
40
- * @example
41
- * ```ts
42
- * import { PocketIc } from '@hadronous/pic';
43
- * import { Principal } from '@dfinity/principal';
44
- * import { _SERVICE, idlFactory } from '../declarations';
45
- *
46
- * const wasmPath = resolve('..', '..', 'canister.wasm');
47
- *
48
- * const pic = await PocketIc.create();
49
- * const fixture = await pic.setupCanister<_SERVICE>(idlFactory, wasmPath);
50
- * const { actor } = fixture;
51
- *
52
- * actor.setPrincipal(Principal.anonymous());
53
- * ```
54
- */
55
- setPrincipal(principal: Principal): void;
56
- /**
57
- * Set a Principal to be used as sender for all calls to the canister.
58
- * This is a convenience method over {@link setPrincipal} that accepts an
59
- * Identity and internally extracts the Principal.
60
- *
61
- * @param identity The identity to set.
62
- *
63
- * @see [Identity](https://agent-js.icp.xyz/agent/interfaces/Identity.html)
64
- * @see [Principal](https://agent-js.icp.xyz/principal/classes/Principal.html)
65
- *
66
- * @example
67
- * ```ts
68
- * import { PocketIc } from '@hadronous/pic';
69
- * import { AnonymousIdentity } from '@dfinity/agent';
70
- * import { _SERVICE, idlFactory } from '../declarations';
71
- *
72
- * const wasmPath = resolve('..', '..', 'canister.wasm');
73
- *
74
- * const pic = await PocketIc.create();
75
- * const fixture = await pic.setupCanister<_SERVICE>(idlFactory, wasmPath);
76
- * const { actor } = fixture;
77
- *
78
- * actor.setIdentity(new AnonymousIdentity());
79
- * ```
80
- */
81
- setIdentity(identity: Identity): void;
82
- };
83
- export declare function createActorClass<T = ActorInterface>(interfaceFactory: IDL.InterfaceFactory, canisterId: Principal, pocketIcClient: PocketIcClient): Actor<T>;
@@ -1,58 +0,0 @@
1
- "use strict";
2
- Object.defineProperty(exports, "__esModule", { value: true });
3
- exports.createActorClass = void 0;
4
- const candid_1 = require("@dfinity/candid");
5
- const principal_1 = require("@dfinity/principal");
6
- function createActorClass(interfaceFactory, canisterId, pocketIcClient) {
7
- const service = interfaceFactory({ IDL: candid_1.IDL });
8
- let sender = null;
9
- function decodeReturnValue(types, msg) {
10
- const returnValues = candid_1.IDL.decode(types, msg);
11
- switch (returnValues.length) {
12
- case 0:
13
- return undefined;
14
- case 1:
15
- return returnValues[0];
16
- default:
17
- return returnValues;
18
- }
19
- }
20
- function createActorMethod(methodName, func) {
21
- if (func.annotations.includes('query') ||
22
- func.annotations.includes('composite_query')) {
23
- return createQueryMethod(methodName, func);
24
- }
25
- return createCallMethod(methodName, func);
26
- }
27
- function getSender() {
28
- return sender ?? principal_1.Principal.anonymous();
29
- }
30
- function createQueryMethod(methodName, func) {
31
- return async function (...args) {
32
- const arg = candid_1.IDL.encode(func.argTypes, args);
33
- const sender = getSender();
34
- const response = await pocketIcClient.queryCall(canisterId, sender, methodName, new Uint8Array(arg));
35
- return decodeReturnValue(func.retTypes, response);
36
- };
37
- }
38
- function createCallMethod(methodName, func) {
39
- return async function (...args) {
40
- const arg = candid_1.IDL.encode(func.argTypes, args);
41
- const sender = getSender();
42
- const response = await pocketIcClient.updateCall(canisterId, sender, methodName, new Uint8Array(arg));
43
- return decodeReturnValue(func.retTypes, response);
44
- };
45
- }
46
- function Actor() { }
47
- Actor.prototype.setPrincipal = function (newSender) {
48
- sender = newSender;
49
- };
50
- Actor.prototype.setIdentity = function (identity) {
51
- sender = identity.getPrincipal();
52
- };
53
- service._fields.forEach(([methodName, func]) => {
54
- Actor.prototype[methodName] = createActorMethod(methodName, func);
55
- });
56
- return Actor;
57
- }
58
- exports.createActorClass = createActorClass;
@@ -1,61 +0,0 @@
1
- export interface CreateInstanceSuccessResponse {
2
- Created: {
3
- instance_id: number;
4
- };
5
- }
6
- export interface CreateInstanceErrorResponse {
7
- Error: {
8
- message: string;
9
- };
10
- }
11
- export type CreateInstanceResponse = CreateInstanceSuccessResponse | CreateInstanceErrorResponse;
12
- export interface CanisterCallRequest {
13
- sender: string;
14
- canister_id: string;
15
- method: string;
16
- payload: string;
17
- }
18
- export interface CanisterCallSuccessResponse {
19
- Ok: {
20
- Reply: string;
21
- };
22
- }
23
- export interface CanisterCallErrorResponse {
24
- Err: {
25
- code: string;
26
- description: string;
27
- };
28
- }
29
- export type CanisterCallResponse = CanisterCallSuccessResponse | CanisterCallErrorResponse;
30
- export interface GetTimeResponse {
31
- nanos_since_epoch: number;
32
- }
33
- export interface SetTimeRequest {
34
- nanos_since_epoch: number;
35
- }
36
- export interface CheckCanisterExistsRequest {
37
- canister_id: string;
38
- }
39
- export interface GetCanisterCyclesBalanceRequest {
40
- canister_id: string;
41
- }
42
- export interface GetCanisterCyclesBalanceResponse {
43
- cycles: number;
44
- }
45
- export interface AddCanisterCyclesRequest {
46
- canister_id: string;
47
- amount: number;
48
- }
49
- export interface AddCanisterCyclesResponse {
50
- cycles: number;
51
- }
52
- export interface SetStableMemoryRequest {
53
- canister_id: string;
54
- blob_id: number[];
55
- }
56
- export interface GetStableMemoryRequest {
57
- canister_id: string;
58
- }
59
- export interface GetStableMemoryResponse {
60
- blob: string;
61
- }
@@ -1,2 +0,0 @@
1
- "use strict";
2
- Object.defineProperty(exports, "__esModule", { value: true });
@@ -1,24 +0,0 @@
1
- import { Principal } from '@dfinity/principal';
2
- export declare class PocketIcClient {
3
- private readonly instanceUrl;
4
- private readonly serverUrl;
5
- private constructor();
6
- static create(url: string): Promise<PocketIcClient>;
7
- private static createInstance;
8
- deleteInstance(): Promise<void>;
9
- tick(): Promise<void>;
10
- getTime(): Promise<number>;
11
- setTime(time: number): Promise<void>;
12
- fetchRootKey(): Promise<Uint8Array>;
13
- checkCanisterExists(canisterId: Principal): Promise<boolean>;
14
- getCyclesBalance(canisterId: Principal): Promise<number>;
15
- addCycles(canisterId: Principal, amount: number): Promise<number>;
16
- uploadBlob(blob: Uint8Array): Promise<Uint8Array>;
17
- setStableMemory(canisterId: Principal, blobId: Uint8Array): Promise<void>;
18
- getStableMemory(canisterId: Principal): Promise<Uint8Array>;
19
- updateCall(canisterId: Principal, sender: Principal, method: string, payload: Uint8Array): Promise<Uint8Array>;
20
- queryCall(canisterId: Principal, sender: Principal, method: string, payload: Uint8Array): Promise<Uint8Array>;
21
- private canisterCall;
22
- private post;
23
- private get;
24
- }
@@ -1,123 +0,0 @@
1
- "use strict";
2
- Object.defineProperty(exports, "__esModule", { value: true });
3
- exports.PocketIcClient = void 0;
4
- const util_1 = require("./util");
5
- const http_client_1 = require("./http-client");
6
- const PROCESSING_TIME_HEADER = 'processing-timeout-ms';
7
- const PROCESSING_TIME_VALUE_MS = 300000;
8
- const PROCESSING_HEADER = {
9
- [PROCESSING_TIME_HEADER]: PROCESSING_TIME_VALUE_MS.toString(),
10
- };
11
- class PocketIcClient {
12
- constructor(instanceUrl, serverUrl) {
13
- this.instanceUrl = instanceUrl;
14
- this.serverUrl = serverUrl;
15
- }
16
- static async create(url) {
17
- const instanceId = await PocketIcClient.createInstance(url);
18
- return new PocketIcClient(`${url}/instances/${instanceId}`, url);
19
- }
20
- static async createInstance(url) {
21
- const response = await http_client_1.HttpClient.post(`${url}/instances`);
22
- if ('Error' in response) {
23
- throw new Error(response.Error.message);
24
- }
25
- return response.Created.instance_id;
26
- }
27
- async deleteInstance() {
28
- await fetch(this.instanceUrl, {
29
- method: 'DELETE',
30
- });
31
- }
32
- async tick() {
33
- return await this.post('/update/tick');
34
- }
35
- async getTime() {
36
- const response = await this.get('/read/get_time');
37
- return response.nanos_since_epoch / 1000000;
38
- }
39
- async setTime(time) {
40
- await this.post('/update/set_time', {
41
- nanos_since_epoch: time * 1000000,
42
- });
43
- }
44
- async fetchRootKey() {
45
- return await this.post('/read/root_key');
46
- }
47
- async checkCanisterExists(canisterId) {
48
- return await this.post('/read/canister_exists', { canister_id: (0, util_1.base64EncodePrincipal)(canisterId) });
49
- }
50
- async getCyclesBalance(canisterId) {
51
- const response = await this.post('/read/get_cycles', {
52
- canister_id: (0, util_1.base64EncodePrincipal)(canisterId),
53
- });
54
- return response.cycles;
55
- }
56
- async addCycles(canisterId, amount) {
57
- const response = await this.post('/update/add_cycles', {
58
- canister_id: (0, util_1.base64EncodePrincipal)(canisterId),
59
- amount,
60
- });
61
- return response.cycles;
62
- }
63
- async uploadBlob(blob) {
64
- const response = await fetch(`${this.serverUrl}/blobstore`, {
65
- method: 'POST',
66
- body: blob,
67
- });
68
- const responseText = await response.text();
69
- return new Uint8Array((0, util_1.hexDecode)(responseText));
70
- }
71
- async setStableMemory(canisterId, blobId) {
72
- const request = {
73
- canister_id: (0, util_1.base64EncodePrincipal)(canisterId),
74
- blob_id: Array.from(blobId),
75
- };
76
- const response = await fetch(`${this.instanceUrl}/update/set_stable_memory`, {
77
- method: 'POST',
78
- headers: {
79
- ...http_client_1.JSON_HEADER,
80
- ...PROCESSING_HEADER,
81
- },
82
- body: JSON.stringify(request),
83
- });
84
- (0, http_client_1.handleFetchError)(response);
85
- }
86
- async getStableMemory(canisterId) {
87
- const response = await this.post('/read/get_stable_memory', {
88
- canister_id: (0, util_1.base64EncodePrincipal)(canisterId),
89
- });
90
- return (0, util_1.base64Decode)(response.blob);
91
- }
92
- async updateCall(canisterId, sender, method, payload) {
93
- return await this.canisterCall('/update/execute_ingress_message', canisterId, sender, method, payload);
94
- }
95
- async queryCall(canisterId, sender, method, payload) {
96
- return await this.canisterCall('/read/query', canisterId, sender, method, payload);
97
- }
98
- async canisterCall(endpoint, canisterId, sender, method, payload) {
99
- let rawCanisterCall = {
100
- sender: (0, util_1.base64EncodePrincipal)(sender),
101
- canister_id: (0, util_1.base64EncodePrincipal)(canisterId),
102
- method,
103
- payload: (0, util_1.base64Encode)(payload),
104
- };
105
- const response = await this.post(endpoint, rawCanisterCall);
106
- if ('Err' in response) {
107
- throw new Error(response.Err.description);
108
- }
109
- return (0, util_1.base64Decode)(response.Ok.Reply);
110
- }
111
- async post(endpoint, body) {
112
- return await http_client_1.HttpClient.post(`${this.instanceUrl}${endpoint}`, {
113
- body,
114
- headers: PROCESSING_HEADER,
115
- });
116
- }
117
- async get(endpoint) {
118
- return await http_client_1.HttpClient.get(`${this.instanceUrl}${endpoint}`, {
119
- headers: PROCESSING_HEADER,
120
- });
121
- }
122
- }
123
- exports.PocketIcClient = PocketIcClient;
@@ -1,10 +0,0 @@
1
- export declare class PocketIcServer {
2
- private readonly serverProcess;
3
- private readonly url;
4
- private constructor();
5
- static start(): Promise<PocketIcServer>;
6
- getUrl(): string;
7
- stop(): void;
8
- private static getBinPath;
9
- private static assertBinExists;
10
- }
@@ -1,55 +0,0 @@
1
- "use strict";
2
- Object.defineProperty(exports, "__esModule", { value: true });
3
- exports.PocketIcServer = void 0;
4
- const node_child_process_1 = require("node:child_process");
5
- const node_path_1 = require("node:path");
6
- const error_1 = require("./error");
7
- const util_1 = require("./util");
8
- class PocketIcServer {
9
- constructor(serverProcess, portNumber) {
10
- this.serverProcess = serverProcess;
11
- this.url = `http://127.0.0.1:${portNumber}`;
12
- }
13
- static async start() {
14
- const binPath = this.getBinPath();
15
- await this.assertBinExists(binPath);
16
- const pid = process.ppid;
17
- const picFilePrefix = `pocket_ic_${pid}`;
18
- const portFilePath = (0, util_1.tmpFile)(`${picFilePrefix}.port`);
19
- const readyFilePath = (0, util_1.tmpFile)(`${picFilePrefix}.ready`);
20
- const serverProcess = (0, node_child_process_1.spawn)(binPath, ['--pid', pid.toString()], {
21
- stdio: 'ignore',
22
- });
23
- serverProcess.on('error', error => {
24
- if ((0, util_1.isArm)() && (0, util_1.isDarwin)()) {
25
- throw new error_1.BinStartMacOSArmError(error);
26
- }
27
- throw new error_1.BinStartError(error);
28
- });
29
- return await (0, util_1.poll)(async () => {
30
- const isPocketIcReady = await (0, util_1.exists)(readyFilePath);
31
- if (isPocketIcReady) {
32
- const portString = await (0, util_1.readFileAsString)(portFilePath);
33
- const port = parseInt(portString);
34
- return new PocketIcServer(serverProcess, port);
35
- }
36
- throw new error_1.BinTimeoutError();
37
- });
38
- }
39
- getUrl() {
40
- return this.url;
41
- }
42
- stop() {
43
- this.serverProcess.unref();
44
- }
45
- static getBinPath() {
46
- return (0, node_path_1.resolve)(__dirname, '..', 'pocket-ic');
47
- }
48
- static async assertBinExists(binPath) {
49
- const binExists = await (0, util_1.exists)(binPath);
50
- if (!binExists) {
51
- throw new error_1.BinNotFoundError(binPath);
52
- }
53
- }
54
- }
55
- exports.PocketIcServer = PocketIcServer;
@@ -1,40 +0,0 @@
1
- import { Principal } from '@dfinity/principal';
2
- import { ActorInterface, Actor } from './pocket-ic-actor';
3
- /**
4
- * A canister testing fixture for PocketIC that provides essential testing primitives
5
- * such as an {@link Actor} and CanisterId.
6
- *
7
- * @category Types
8
- * @see [Principal](https://agent-js.icp.xyz/principal/classes/Principal.html)
9
- */
10
- export interface CanisterFixture<T = ActorInterface> {
11
- /**
12
- * The {@link Actor} instance.
13
- */
14
- actor: Actor<T>;
15
- /**
16
- * The Principal of the canister.
17
- */
18
- canisterId: Principal;
19
- }
20
- /**
21
- * Options for creating a canister.
22
- *
23
- * @param cycles The amount of cycles to send to the canister.
24
- * Defaults to 1_000_000_000_000_000_000n.
25
- * @param controllers The controllers of the canister.
26
- * Defaults to the sender, which defaults to the anonymous principal.
27
- * @param computeAllocation The compute allocation of the canister.
28
- * @param memoryAllocation The memory allocation of the canister.
29
- * @param freezingThreshold The freezing threshold of the canister.
30
- *
31
- * @category Types
32
- * @see [Principal](https://agent-js.icp.xyz/principal/classes/Principal.html)
33
- */
34
- export interface CreateCanisterOptions {
35
- cycles?: bigint;
36
- controllers?: Principal[];
37
- computeAllocation?: bigint;
38
- memoryAllocation?: bigint;
39
- freezingThreshold?: bigint;
40
- }
@@ -1,2 +0,0 @@
1
- "use strict";
2
- Object.defineProperty(exports, "__esModule", { value: true });