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.
- package/dist/package.json +2 -1
- package/package.json +2 -1
- package/dist/cli-local.d.ts +0 -2
- package/dist/cli-local.js +0 -2
- package/dist/commands/toolchain/mocv.d.ts +0 -1
- package/dist/commands/toolchain/mocv.js +0 -271
- package/dist/moc-wrapper.d.ts +0 -2
- package/dist/moc-wrapper.js +0 -8
- package/dist/out/cli.d.ts +0 -2
- package/dist/out/cli.js +0 -115242
- package/dist/pic-js/examples/clock/tests/clock/index.d.ts +0 -1
- package/dist/pic-js/examples/clock/tests/clock/index.js +0 -5
- package/dist/pic-js/examples/clock/tests/jest.config.d.ts +0 -3
- package/dist/pic-js/examples/clock/tests/jest.config.js +0 -8
- package/dist/pic-js/examples/clock/tests/src/clock.spec.d.ts +0 -1
- package/dist/pic-js/examples/clock/tests/src/clock.spec.js +0 -48
- package/dist/pic-js/examples/counter/tests/counter/index.d.ts +0 -1
- package/dist/pic-js/examples/counter/tests/counter/index.js +0 -5
- package/dist/pic-js/examples/counter/tests/jest.config.d.ts +0 -3
- package/dist/pic-js/examples/counter/tests/jest.config.js +0 -8
- package/dist/pic-js/examples/counter/tests/src/counter.spec.d.ts +0 -1
- package/dist/pic-js/examples/counter/tests/src/counter.spec.js +0 -80
- package/dist/pic-js/examples/todo/tests/jest.config.d.ts +0 -3
- package/dist/pic-js/examples/todo/tests/jest.config.js +0 -8
- package/dist/pic-js/examples/todo/tests/src/todo.spec.d.ts +0 -1
- package/dist/pic-js/examples/todo/tests/src/todo.spec.js +0 -211
- package/dist/pic-js/examples/todo/tests/todo/index.d.ts +0 -1
- package/dist/pic-js/examples/todo/tests/todo/index.js +0 -5
- package/dist/pic-js/packages/pic/src/error.d.ts +0 -12
- package/dist/pic-js/packages/pic/src/error.js +0 -36
- package/dist/pic-js/packages/pic/src/http-client.d.ts +0 -15
- package/dist/pic-js/packages/pic/src/http-client.js +0 -37
- package/dist/pic-js/packages/pic/src/identity.d.ts +0 -66
- package/dist/pic-js/packages/pic/src/identity.js +0 -86
- package/dist/pic-js/packages/pic/src/index.d.ts +0 -4
- package/dist/pic-js/packages/pic/src/index.js +0 -8
- package/dist/pic-js/packages/pic/src/management-canister.d.ts +0 -30
- package/dist/pic-js/packages/pic/src/management-canister.js +0 -43
- package/dist/pic-js/packages/pic/src/pocket-ic-actor.d.ts +0 -83
- package/dist/pic-js/packages/pic/src/pocket-ic-actor.js +0 -58
- package/dist/pic-js/packages/pic/src/pocket-ic-client-types.d.ts +0 -61
- package/dist/pic-js/packages/pic/src/pocket-ic-client-types.js +0 -2
- package/dist/pic-js/packages/pic/src/pocket-ic-client.d.ts +0 -24
- package/dist/pic-js/packages/pic/src/pocket-ic-client.js +0 -123
- package/dist/pic-js/packages/pic/src/pocket-ic-server.d.ts +0 -10
- package/dist/pic-js/packages/pic/src/pocket-ic-server.js +0 -55
- package/dist/pic-js/packages/pic/src/pocket-ic-types.d.ts +0 -40
- package/dist/pic-js/packages/pic/src/pocket-ic-types.js +0 -2
- package/dist/pic-js/packages/pic/src/pocket-ic.d.ts +0 -447
- package/dist/pic-js/packages/pic/src/pocket-ic.js +0 -551
- package/dist/pic-js/packages/pic/src/util/candid.d.ts +0 -1
- package/dist/pic-js/packages/pic/src/util/candid.js +0 -7
- package/dist/pic-js/packages/pic/src/util/encoding.d.ts +0 -5
- package/dist/pic-js/packages/pic/src/util/encoding.js +0 -19
- package/dist/pic-js/packages/pic/src/util/fs.d.ts +0 -4
- package/dist/pic-js/packages/pic/src/util/fs.js +0 -29
- package/dist/pic-js/packages/pic/src/util/index.d.ts +0 -5
- package/dist/pic-js/packages/pic/src/util/index.js +0 -21
- package/dist/pic-js/packages/pic/src/util/os.d.ts +0 -4
- package/dist/pic-js/packages/pic/src/util/os.js +0 -19
- package/dist/pic-js/packages/pic/src/util/poll.d.ts +0 -5
- package/dist/pic-js/packages/pic/src/util/poll.js +0 -28
- package/dist/templates/cli.d.ts +0 -2
- package/dist/templates/cli.js +0 -3660
|
@@ -1,551 +0,0 @@
|
|
|
1
|
-
"use strict";
|
|
2
|
-
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
-
exports.PocketIc = void 0;
|
|
4
|
-
const principal_1 = require("@dfinity/principal");
|
|
5
|
-
const util_1 = require("./util");
|
|
6
|
-
const pocket_ic_server_1 = require("./pocket-ic-server");
|
|
7
|
-
const pocket_ic_client_1 = require("./pocket-ic-client");
|
|
8
|
-
const pocket_ic_actor_1 = require("./pocket-ic-actor");
|
|
9
|
-
const management_canister_1 = require("./management-canister");
|
|
10
|
-
/**
|
|
11
|
-
* PocketIC is a local development environment for Internet Computer canisters.
|
|
12
|
-
*
|
|
13
|
-
* @category API
|
|
14
|
-
*
|
|
15
|
-
* @example
|
|
16
|
-
* The easist way to use PocketIC is to use {@link setupCanister} convenience method:
|
|
17
|
-
* ```ts
|
|
18
|
-
* import { PocketIc } from '@hadronous/pic';
|
|
19
|
-
* import { _SERVICE, idlFactory } from '../declarations';
|
|
20
|
-
*
|
|
21
|
-
* const wasmPath = resolve('..', '..', 'canister.wasm');
|
|
22
|
-
*
|
|
23
|
-
* const pic = await PocketIc.create();
|
|
24
|
-
* const fixture = await pic.setupCanister<_SERVICE>(idlFactory, wasmPath);
|
|
25
|
-
* const { actor } = fixture;
|
|
26
|
-
*
|
|
27
|
-
* // perform tests...
|
|
28
|
-
*
|
|
29
|
-
* await pic.tearDown();
|
|
30
|
-
* ```
|
|
31
|
-
*
|
|
32
|
-
* If more control is needed, then the {@link createCanister}, {@link installCode} and
|
|
33
|
-
* {@link createActor} methods can be used directly:
|
|
34
|
-
* ```ts
|
|
35
|
-
* import { PocketIc } from '@hadronous/pic';
|
|
36
|
-
* import { _SERVICE, idlFactory } from '../declarations';
|
|
37
|
-
*
|
|
38
|
-
* const wasmPath = resolve('..', '..', 'canister.wasm');
|
|
39
|
-
*
|
|
40
|
-
* const pic = await PocketIc.create();
|
|
41
|
-
*
|
|
42
|
-
* const canisterId = await pic.createCanister();
|
|
43
|
-
* await pic.installCode(canisterId, wasmPath);
|
|
44
|
-
* const actor = pic.createActor<_SERVICE>(idlFactory, canisterId);
|
|
45
|
-
*
|
|
46
|
-
* // perform tests...
|
|
47
|
-
*
|
|
48
|
-
* await pic.tearDown();
|
|
49
|
-
* ```
|
|
50
|
-
*/
|
|
51
|
-
class PocketIc {
|
|
52
|
-
constructor(client, server) {
|
|
53
|
-
this.client = client;
|
|
54
|
-
this.server = server;
|
|
55
|
-
}
|
|
56
|
-
/**
|
|
57
|
-
* Starts the PocketIC server and creates a PocketIC instance.
|
|
58
|
-
*
|
|
59
|
-
* @returns A new PocketIC instance.
|
|
60
|
-
*
|
|
61
|
-
* @example
|
|
62
|
-
* ```ts
|
|
63
|
-
* import { PocketIc } from '@hadronous/pic';
|
|
64
|
-
*
|
|
65
|
-
* const pic = await PocketIc.create();
|
|
66
|
-
* ```
|
|
67
|
-
*/
|
|
68
|
-
static async create() {
|
|
69
|
-
const server = await pocket_ic_server_1.PocketIcServer.start();
|
|
70
|
-
const client = await pocket_ic_client_1.PocketIcClient.create(server.getUrl());
|
|
71
|
-
return new PocketIc(client, server);
|
|
72
|
-
}
|
|
73
|
-
/**
|
|
74
|
-
* Creates a PocketIC instance that connects to an existing PocketIC server.
|
|
75
|
-
*
|
|
76
|
-
* @param url The URL of an existing PocketIC server to connect to.
|
|
77
|
-
* @returns A new PocketIC instance.
|
|
78
|
-
*
|
|
79
|
-
* @example
|
|
80
|
-
* ```ts
|
|
81
|
-
* import { PocketIc } from '@hadronous/pic';
|
|
82
|
-
*
|
|
83
|
-
* const url = 'http://localhost:8080';
|
|
84
|
-
* const pic = await PocketIc.createFromUrl(url);
|
|
85
|
-
* ```
|
|
86
|
-
*/
|
|
87
|
-
static async createFromUrl(url) {
|
|
88
|
-
const client = await pocket_ic_client_1.PocketIcClient.create(url);
|
|
89
|
-
return new PocketIc(client);
|
|
90
|
-
}
|
|
91
|
-
/**
|
|
92
|
-
* A convenience method that creates a new canister,
|
|
93
|
-
* installs the given WASM module to it and returns a typesafe {@link Actor}
|
|
94
|
-
* that implements the Candid interface of the canister.
|
|
95
|
-
* To just create a canister, see {@link createCanister}.
|
|
96
|
-
* To just install code to an existing canister, see {@link installCode}.
|
|
97
|
-
* To just create an Actor for an existing canister, see {@link createActor}.
|
|
98
|
-
*
|
|
99
|
-
* @param interfaceFactory The interface factory to use for the {@link Actor}.
|
|
100
|
-
* @param wasm The WASM module to install to the canister.
|
|
101
|
-
* If a string is passed, it is treated as a path to a file.
|
|
102
|
-
* If an Uint8Array is passed, it is treated as the WASM module itself.
|
|
103
|
-
* @param createCanisterOptions Options for creating the canister, see {@link CreateCanisterOptions}.
|
|
104
|
-
* @param arg Candid encoded argument to pass to the canister's init function.
|
|
105
|
-
* @param sender The Principal to send the request as.
|
|
106
|
-
* @returns The {@link Actor} instance.
|
|
107
|
-
*
|
|
108
|
-
* @see [Candid](https://internetcomputer.org/docs/current/references/candid-ref)
|
|
109
|
-
* @see [Principal](https://agent-js.icp.xyz/principal/classes/Principal.html)
|
|
110
|
-
*
|
|
111
|
-
* @example
|
|
112
|
-
* ```ts
|
|
113
|
-
* import { PocketIc } from '@hadronous/pic';
|
|
114
|
-
* import { _SERVICE, idlFactory } from '../declarations';
|
|
115
|
-
*
|
|
116
|
-
* const wasmPath = resolve('..', '..', 'canister.wasm');
|
|
117
|
-
*
|
|
118
|
-
* const pic = await PocketIc.create();
|
|
119
|
-
* const fixture = await pic.setupCanister<_SERVICE>(idlFactory, wasmPath);
|
|
120
|
-
* const { actor } = fixture;
|
|
121
|
-
* ```
|
|
122
|
-
*/
|
|
123
|
-
async setupCanister(interfaceFactory, wasm, createCanisterOptions = {}, arg = new Uint8Array(), sender = principal_1.Principal.anonymous()) {
|
|
124
|
-
const canisterId = await this.createCanister(createCanisterOptions, sender);
|
|
125
|
-
await this.installCode(canisterId, wasm, arg, sender);
|
|
126
|
-
const actor = this.createActor(interfaceFactory, canisterId);
|
|
127
|
-
return { actor, canisterId };
|
|
128
|
-
}
|
|
129
|
-
/**
|
|
130
|
-
* Creates a new canister.
|
|
131
|
-
* For a more convenient way of creating a PocketIC instance,
|
|
132
|
-
* creating a canister and installing code, see {@link setupCanister}.
|
|
133
|
-
*
|
|
134
|
-
* @param options Options for creating the canister, see {@link CreateCanisterOptions}.
|
|
135
|
-
* @param sender The Principal to send the request as.
|
|
136
|
-
* @returns The Principal of the newly created canister.
|
|
137
|
-
*
|
|
138
|
-
* @see [Principal](https://agent-js.icp.xyz/principal/classes/Principal.html)
|
|
139
|
-
*
|
|
140
|
-
* @example
|
|
141
|
-
* ```ts
|
|
142
|
-
* import { PocketIc } from '@hadronous/pic';
|
|
143
|
-
*
|
|
144
|
-
* const pic = await PocketIc.create();
|
|
145
|
-
* const canisterId = await pic.createCanister();
|
|
146
|
-
* ```
|
|
147
|
-
*/
|
|
148
|
-
async createCanister(options = {}, sender = principal_1.Principal.anonymous()) {
|
|
149
|
-
const cycles = options.cycles ?? 1000000000000000000n;
|
|
150
|
-
const payload = (0, management_canister_1.encodeCreateCanisterRequest)({
|
|
151
|
-
settings: [
|
|
152
|
-
{
|
|
153
|
-
controllers: options.controllers ?? [],
|
|
154
|
-
compute_allocation: (0, util_1.optionalBigInt)(options.computeAllocation),
|
|
155
|
-
memory_allocation: (0, util_1.optionalBigInt)(options.memoryAllocation),
|
|
156
|
-
freezing_threshold: (0, util_1.optionalBigInt)(options.freezingThreshold),
|
|
157
|
-
},
|
|
158
|
-
],
|
|
159
|
-
amount: [cycles],
|
|
160
|
-
});
|
|
161
|
-
const res = await this.client.updateCall(management_canister_1.MANAGEMENT_CANISTER_ID, sender, 'provisional_create_canister_with_cycles', payload);
|
|
162
|
-
return (0, management_canister_1.decodeCreateCanisterResponse)(res).canister_id;
|
|
163
|
-
}
|
|
164
|
-
/**
|
|
165
|
-
* Installs the given WASM module to the provided canister.
|
|
166
|
-
* To create a canister to install code to, see {@link createCanister}.
|
|
167
|
-
* For a more convenient way of creating a PocketIC instance,
|
|
168
|
-
* creating a canister and installing code, see {@link setupCanister}.
|
|
169
|
-
*
|
|
170
|
-
* @param canisterId The Principal of the canister to install the code to.
|
|
171
|
-
* @param wasm The WASM module to install to the canister.
|
|
172
|
-
* If a string is passed, it is treated as a path to a file.
|
|
173
|
-
* If an Uint8Array is passed, it is treated as the WASM module itself.
|
|
174
|
-
* @param arg Candid encoded argument to pass to the canister's init function.
|
|
175
|
-
* @param sender The Principal to send the request as.
|
|
176
|
-
*
|
|
177
|
-
* @see [Principal](https://agent-js.icp.xyz/principal/classes/Principal.html)
|
|
178
|
-
*
|
|
179
|
-
* @example
|
|
180
|
-
* ```ts
|
|
181
|
-
* import { Principal } from '@dfinity/principal';
|
|
182
|
-
* import { PocketIc } from '@hadronous/pic';
|
|
183
|
-
* import { resolve } from 'node:path';
|
|
184
|
-
*
|
|
185
|
-
* const canisterId = Principal.fromUint8Array(new Uint8Array([0]));
|
|
186
|
-
* const wasmPath = resolve('..', '..', 'canister.wasm');
|
|
187
|
-
*
|
|
188
|
-
* const pic = await PocketIc.create();
|
|
189
|
-
* await pic.installCode(canisterId, wasmPath);
|
|
190
|
-
* ```
|
|
191
|
-
*/
|
|
192
|
-
async installCode(canisterId, wasm, arg = new Uint8Array(), sender = principal_1.Principal.anonymous()) {
|
|
193
|
-
if (typeof wasm === 'string') {
|
|
194
|
-
wasm = await (0, util_1.readFileAsBytes)(wasm);
|
|
195
|
-
}
|
|
196
|
-
const payload = (0, management_canister_1.encodeInstallCodeRequest)({
|
|
197
|
-
arg,
|
|
198
|
-
canister_id: canisterId,
|
|
199
|
-
mode: {
|
|
200
|
-
install: null,
|
|
201
|
-
},
|
|
202
|
-
wasm_module: wasm,
|
|
203
|
-
});
|
|
204
|
-
await this.client.updateCall(management_canister_1.MANAGEMENT_CANISTER_ID, sender, 'install_code', payload);
|
|
205
|
-
}
|
|
206
|
-
/**
|
|
207
|
-
* Reinstalls the given WASM module to the provided canister.
|
|
208
|
-
* This will reset both the canister's heap and its stable memory.
|
|
209
|
-
* To create a canister to upgrade, see {@link createCanister}.
|
|
210
|
-
* To install the initial WASM module to a new canister, see {@link installCode}.
|
|
211
|
-
*
|
|
212
|
-
* @param canisterId The Principal of the canister to reinstall code to.
|
|
213
|
-
* @param wasm The WASM module to install to the canister.
|
|
214
|
-
* If a string is passed, it is treated as a path to a file.
|
|
215
|
-
* If an Uint8Array is passed, it is treated as the WASM module itself.
|
|
216
|
-
* @param arg Candid encoded argument to pass to the canister's init function.
|
|
217
|
-
* @param sender The Principal to send the request as.
|
|
218
|
-
*
|
|
219
|
-
* @see [Principal](https://agent-js.icp.xyz/principal/classes/Principal.html)
|
|
220
|
-
*
|
|
221
|
-
* @example
|
|
222
|
-
* ```ts
|
|
223
|
-
* import { Principal } from '@dfinity/principal';
|
|
224
|
-
* import { PocketIc } from '@hadronous/pic';
|
|
225
|
-
* import { resolve } from 'node:path';
|
|
226
|
-
*
|
|
227
|
-
* const canisterId = Principal.fromUint8Array(new Uint8Array([0]));
|
|
228
|
-
* const wasmPath = resolve('..', '..', 'canister.wasm');
|
|
229
|
-
*
|
|
230
|
-
* const pic = await PocketIc.create();
|
|
231
|
-
* await pic.reinstallCode(canisterId, wasmPath);
|
|
232
|
-
* ```
|
|
233
|
-
*/
|
|
234
|
-
async reinstallCode(canisterId, wasm, arg = new Uint8Array(), sender = principal_1.Principal.anonymous()) {
|
|
235
|
-
if (typeof wasm === 'string') {
|
|
236
|
-
wasm = await (0, util_1.readFileAsBytes)(wasm);
|
|
237
|
-
}
|
|
238
|
-
const payload = (0, management_canister_1.encodeInstallCodeRequest)({
|
|
239
|
-
arg,
|
|
240
|
-
canister_id: canisterId,
|
|
241
|
-
mode: {
|
|
242
|
-
reinstall: null,
|
|
243
|
-
},
|
|
244
|
-
wasm_module: wasm,
|
|
245
|
-
});
|
|
246
|
-
await this.client.updateCall(management_canister_1.MANAGEMENT_CANISTER_ID, sender, 'install_code', payload);
|
|
247
|
-
}
|
|
248
|
-
/**
|
|
249
|
-
* Upgrades the given canister with the given WASM module.
|
|
250
|
-
* This will reset the canister's heap, but preserve stable memory.
|
|
251
|
-
* To create a canister to upgrade to, see {@link createCanister}.
|
|
252
|
-
* To install the initial WASM module to a new canister, see {@link installCode}.
|
|
253
|
-
*
|
|
254
|
-
* @param canisterId The Principal of the canister to upgrade.
|
|
255
|
-
* @param wasm The WASM module to install to the canister.
|
|
256
|
-
* If a string is passed, it is treated as a path to a file.
|
|
257
|
-
* If an Uint8Array is passed, it is treated as the WASM module itself.
|
|
258
|
-
* @param arg Candid encoded argument to pass to the canister's init function.
|
|
259
|
-
* @param sender The Principal to send the request as.
|
|
260
|
-
*
|
|
261
|
-
* @see [Principal](https://agent-js.icp.xyz/principal/classes/Principal.html)
|
|
262
|
-
*
|
|
263
|
-
* @example
|
|
264
|
-
* ```ts
|
|
265
|
-
* import { Principal } from '@dfinity/principal';
|
|
266
|
-
* import { PocketIc } from '@hadronous/pic';
|
|
267
|
-
* import { resolve } from 'node:path';
|
|
268
|
-
*
|
|
269
|
-
* const canisterId = Principal.fromUint8Array(new Uint8Array([0]));
|
|
270
|
-
* const wasmPath = resolve('..', '..', 'canister.wasm');
|
|
271
|
-
*
|
|
272
|
-
* const pic = await PocketIc.create();
|
|
273
|
-
* await pic.upgradeCanister(canisterId, wasmPath);
|
|
274
|
-
* ```
|
|
275
|
-
*/
|
|
276
|
-
async upgradeCanister(canisterId, wasm, arg = new Uint8Array(), sender = principal_1.Principal.anonymous()) {
|
|
277
|
-
if (typeof wasm === 'string') {
|
|
278
|
-
wasm = await (0, util_1.readFileAsBytes)(wasm);
|
|
279
|
-
}
|
|
280
|
-
const payload = (0, management_canister_1.encodeInstallCodeRequest)({
|
|
281
|
-
arg,
|
|
282
|
-
canister_id: canisterId,
|
|
283
|
-
mode: {
|
|
284
|
-
upgrade: null,
|
|
285
|
-
},
|
|
286
|
-
wasm_module: wasm,
|
|
287
|
-
});
|
|
288
|
-
await this.client.updateCall(management_canister_1.MANAGEMENT_CANISTER_ID, sender, 'install_code', payload);
|
|
289
|
-
}
|
|
290
|
-
/**
|
|
291
|
-
* Creates an {@link Actor} for the given canister.
|
|
292
|
-
* An {@link Actor} is a typesafe class that implements the Candid interface of a canister.
|
|
293
|
-
* To create a canister for the Actor, see {@link createCanister}.
|
|
294
|
-
* For a more convenient way of creating a PocketIC instance,
|
|
295
|
-
* creating a canister and installing code, see {@link setupCanister}.
|
|
296
|
-
*
|
|
297
|
-
* @param interfaceFactory The InterfaceFactory to use for the {@link Actor}.
|
|
298
|
-
* @param canisterId The Principal of the canister to create the Actor for.
|
|
299
|
-
* @typeparam T The type of the {@link Actor}. Must implement {@link ActorInterface}.
|
|
300
|
-
* @returns The {@link Actor} instance.
|
|
301
|
-
*
|
|
302
|
-
* @see [Principal](https://agent-js.icp.xyz/principal/classes/Principal.html)
|
|
303
|
-
* @see [InterfaceFactory](https://agent-js.icp.xyz/candid/modules/IDL.html#InterfaceFactory)
|
|
304
|
-
*
|
|
305
|
-
* @example
|
|
306
|
-
* ```ts
|
|
307
|
-
* import { Principal } from '@dfinity/principal';
|
|
308
|
-
* import { PocketIc } from '@hadronous/pic';
|
|
309
|
-
* import { _SERVICE, idlFactory } from '../declarations';
|
|
310
|
-
*
|
|
311
|
-
* const canisterId = Principal.fromUint8Array(new Uint8Array([0]));
|
|
312
|
-
*
|
|
313
|
-
* const pic = await PocketIc.create();
|
|
314
|
-
* const fixture = await pic.setupCanister<_SERVICE>(idlFactory, wasmPath);
|
|
315
|
-
* const { actor } = fixture;
|
|
316
|
-
* ```
|
|
317
|
-
*/
|
|
318
|
-
createActor(interfaceFactory, canisterId) {
|
|
319
|
-
const Actor = (0, pocket_ic_actor_1.createActorClass)(interfaceFactory, canisterId, this.client);
|
|
320
|
-
return new Actor();
|
|
321
|
-
}
|
|
322
|
-
/**
|
|
323
|
-
* Deletes the PocketIC instance and disconnects from the server.
|
|
324
|
-
*
|
|
325
|
-
* @example
|
|
326
|
-
* ```ts
|
|
327
|
-
* import { PocketIc } from '@hadronous/pic';
|
|
328
|
-
*
|
|
329
|
-
* const pic = await PocketIc.create();
|
|
330
|
-
* await pic.tearDown();
|
|
331
|
-
* ```
|
|
332
|
-
*/
|
|
333
|
-
async tearDown() {
|
|
334
|
-
await this.client.deleteInstance();
|
|
335
|
-
this.server?.stop();
|
|
336
|
-
}
|
|
337
|
-
/**
|
|
338
|
-
* Make the IC produce and progress by one block.
|
|
339
|
-
*
|
|
340
|
-
* ```ts
|
|
341
|
-
* import { PocketIc } from '@hadronous/pic';
|
|
342
|
-
*
|
|
343
|
-
* const pic = await PocketIc.create();
|
|
344
|
-
* await pic.tick();
|
|
345
|
-
* ```
|
|
346
|
-
*/
|
|
347
|
-
async tick() {
|
|
348
|
-
return await this.client.tick();
|
|
349
|
-
}
|
|
350
|
-
/**
|
|
351
|
-
* Get the current time of the IC in milliseconds since the Unix epoch.
|
|
352
|
-
*
|
|
353
|
-
* @returns The current time in milliseconds since the UNIX epoch.
|
|
354
|
-
*
|
|
355
|
-
* @example
|
|
356
|
-
* ```ts
|
|
357
|
-
* import { PocketIc } from '@hadronous/pic';
|
|
358
|
-
*
|
|
359
|
-
* const pic = await PocketIc.create();
|
|
360
|
-
*
|
|
361
|
-
* const time = await pic.getTime();
|
|
362
|
-
* ```
|
|
363
|
-
*/
|
|
364
|
-
async getTime() {
|
|
365
|
-
return await this.client.getTime();
|
|
366
|
-
}
|
|
367
|
-
/**
|
|
368
|
-
* Reset the time of the IC to the current time.
|
|
369
|
-
*
|
|
370
|
-
* @example
|
|
371
|
-
* ```ts
|
|
372
|
-
* import { PocketIc } from '@hadronous/pic';
|
|
373
|
-
*
|
|
374
|
-
* const pic = await PocketIc.create();
|
|
375
|
-
*
|
|
376
|
-
* await pic.resetTime();
|
|
377
|
-
* const time = await pic.getTime();
|
|
378
|
-
* ```
|
|
379
|
-
*/
|
|
380
|
-
async resetTime() {
|
|
381
|
-
await this.setTime(Date.now());
|
|
382
|
-
}
|
|
383
|
-
/**
|
|
384
|
-
* Set the current time of the IC.
|
|
385
|
-
*
|
|
386
|
-
* @param time The time to set in milliseconds since the Unix epoch.
|
|
387
|
-
*
|
|
388
|
-
* @example
|
|
389
|
-
* ```ts
|
|
390
|
-
* import { PocketIc } from '@hadronous/pic';
|
|
391
|
-
*
|
|
392
|
-
* const pic = await PocketIc.create();
|
|
393
|
-
*
|
|
394
|
-
* const date = new Date();
|
|
395
|
-
* await pic.setTime(date.getTime());
|
|
396
|
-
* const time = await pic.getTime();
|
|
397
|
-
* ```
|
|
398
|
-
*/
|
|
399
|
-
async setTime(time) {
|
|
400
|
-
await this.client.setTime(time);
|
|
401
|
-
}
|
|
402
|
-
/**
|
|
403
|
-
* Advance the time of the IC by the given duration in milliseconds.
|
|
404
|
-
*
|
|
405
|
-
* @param duration The duration to advance the time by.
|
|
406
|
-
*
|
|
407
|
-
* @example
|
|
408
|
-
* ```ts
|
|
409
|
-
* import { PocketIc } from '@hadronous/pic';
|
|
410
|
-
*
|
|
411
|
-
* const pic = await PocketIc.create();
|
|
412
|
-
*
|
|
413
|
-
* const initialTime = await pic.getTime();
|
|
414
|
-
* await pic.advanceTime(1_000);
|
|
415
|
-
* const newTime = await pic.getTime();
|
|
416
|
-
* ```
|
|
417
|
-
*/
|
|
418
|
-
async advanceTime(duration) {
|
|
419
|
-
const currentTime = await this.getTime();
|
|
420
|
-
const newTime = currentTime + duration;
|
|
421
|
-
await this.setTime(newTime);
|
|
422
|
-
}
|
|
423
|
-
/**
|
|
424
|
-
* Fetch the root key of the IC.
|
|
425
|
-
*
|
|
426
|
-
* @returns The root key of the IC.
|
|
427
|
-
*
|
|
428
|
-
* @example
|
|
429
|
-
* ```ts
|
|
430
|
-
* import { PocketIc } from '@hadronous/pic';
|
|
431
|
-
*
|
|
432
|
-
* const pic = await PocketIc.create();
|
|
433
|
-
* const rootKey = await pic.fetchRootKey();
|
|
434
|
-
*/
|
|
435
|
-
async fetchRootKey() {
|
|
436
|
-
return await this.client.fetchRootKey();
|
|
437
|
-
}
|
|
438
|
-
/**
|
|
439
|
-
* Checks if the provided canister exists.
|
|
440
|
-
*
|
|
441
|
-
* @param canisterId The Principal of the canister to check.
|
|
442
|
-
* @returns `true` if the canister exists, `false` otherwise.
|
|
443
|
-
*
|
|
444
|
-
* @see [Principal](https://agent-js.icp.xyz/principal/classes/Principal.html)
|
|
445
|
-
*
|
|
446
|
-
* @example
|
|
447
|
-
* ```ts
|
|
448
|
-
* import { PocketIc } from '@hadronous/pic';
|
|
449
|
-
*
|
|
450
|
-
* const canisterId = Principal.fromUint8Array(new Uint8Array([0]));
|
|
451
|
-
*
|
|
452
|
-
* const pic = await PocketIc.create();
|
|
453
|
-
* const canisterExists = await pic.checkCanisterExists(canisterId);
|
|
454
|
-
* ```
|
|
455
|
-
*/
|
|
456
|
-
async checkCanisterExists(canisterId) {
|
|
457
|
-
return await this.client.checkCanisterExists(canisterId);
|
|
458
|
-
}
|
|
459
|
-
/**
|
|
460
|
-
* Gets the current cycle balance of the specified canister.
|
|
461
|
-
*
|
|
462
|
-
* @param canisterId The Principal of the canister to check.
|
|
463
|
-
* @returns The current cycles balance of the canister.
|
|
464
|
-
*
|
|
465
|
-
* @see [Principal](https://agent-js.icp.xyz/principal/classes/Principal.html)
|
|
466
|
-
*
|
|
467
|
-
* @example
|
|
468
|
-
* ```ts
|
|
469
|
-
* import { Principal } from '@dfinity/principal';
|
|
470
|
-
* import { PocketIc } from '@hadronous/pic';
|
|
471
|
-
*
|
|
472
|
-
* const canisterId = Principal.fromUint8Array(new Uint8Array([0]));
|
|
473
|
-
*
|
|
474
|
-
* const pic = await PocketIc.create();
|
|
475
|
-
* const cyclesBalance = await pic.getCyclesBalance(canisterId);
|
|
476
|
-
* ```
|
|
477
|
-
*/
|
|
478
|
-
async getCyclesBalance(canisterId) {
|
|
479
|
-
return await this.client.getCyclesBalance(canisterId);
|
|
480
|
-
}
|
|
481
|
-
/**
|
|
482
|
-
* Add cycles to the specified canister.
|
|
483
|
-
*
|
|
484
|
-
* @param canisterId The Principal of the canister to add cycles to.
|
|
485
|
-
* @param amount The amount of cycles to add.
|
|
486
|
-
* @returns The new cycle balance of the canister.
|
|
487
|
-
*
|
|
488
|
-
* @see [Principal](https://agent-js.icp.xyz/principal/classes/Principal.html)
|
|
489
|
-
*
|
|
490
|
-
* @example
|
|
491
|
-
* ```ts
|
|
492
|
-
* import { Principal } from '@dfinity/principal';
|
|
493
|
-
* import { PocketIc } from '@hadronous/pic';
|
|
494
|
-
*
|
|
495
|
-
* const canisterId = Principal.fromUint8Array(new Uint8Array([0]));
|
|
496
|
-
*
|
|
497
|
-
* const pic = await PocketIc.create();
|
|
498
|
-
* const newCyclesBalance = await pic.addCycles(canisterId, 10_000_000);
|
|
499
|
-
* ```
|
|
500
|
-
*/
|
|
501
|
-
async addCycles(canisterId, amount) {
|
|
502
|
-
return await this.client.addCycles(canisterId, amount);
|
|
503
|
-
}
|
|
504
|
-
/**
|
|
505
|
-
* Set the stable memory of a given canister.
|
|
506
|
-
*
|
|
507
|
-
* @param canisterId The Principal of the canister to set the stable memory of.
|
|
508
|
-
* @param stableMemory A blob containing the stable memory to set.
|
|
509
|
-
*
|
|
510
|
-
* @see [Principal](https://agent-js.icp.xyz/principal/classes/Principal.html)
|
|
511
|
-
*
|
|
512
|
-
* @example
|
|
513
|
-
* ```ts
|
|
514
|
-
* import { Principal } from '@dfinity/principal';
|
|
515
|
-
* import { PocketIc } from '@hadronous/pic';
|
|
516
|
-
*
|
|
517
|
-
* const canisterId = Principal.fromUint8Array(new Uint8Array([0]));
|
|
518
|
-
* const stableMemory = new Uint8Array([0, 1, 2, 3, 4]);
|
|
519
|
-
*
|
|
520
|
-
* const pic = await PocketIc.create();
|
|
521
|
-
* await pic.setStableMemory(canisterId, stableMemory);
|
|
522
|
-
* ```
|
|
523
|
-
*/
|
|
524
|
-
async setStableMemory(canisterId, stableMemory) {
|
|
525
|
-
const blobId = await this.client.uploadBlob(stableMemory);
|
|
526
|
-
await this.client.setStableMemory(canisterId, blobId);
|
|
527
|
-
}
|
|
528
|
-
/**
|
|
529
|
-
* Get the stable memory of a given canister.
|
|
530
|
-
*
|
|
531
|
-
* @param canisterId The Principal of the canister to get the stable memory of.
|
|
532
|
-
* @returns A blob containing the canister's stable memory.
|
|
533
|
-
*
|
|
534
|
-
* @see [Principal](https://agent-js.icp.xyz/principal/classes/Principal.html)
|
|
535
|
-
*
|
|
536
|
-
* @example
|
|
537
|
-
* ```ts
|
|
538
|
-
* import { Principal } from '@dfinity/principal';
|
|
539
|
-
* import { PocketIc } from '@hadronous/pic';
|
|
540
|
-
*
|
|
541
|
-
* const canisterId = Principal.fromUint8Array(new Uint8Array([0]));
|
|
542
|
-
*
|
|
543
|
-
* const pic = await PocketIc.create();
|
|
544
|
-
* const stableMemory = await pic.getStableMemory(canisterId);
|
|
545
|
-
* ```
|
|
546
|
-
*/
|
|
547
|
-
async getStableMemory(canisterId) {
|
|
548
|
-
return await this.client.getStableMemory(canisterId);
|
|
549
|
-
}
|
|
550
|
-
}
|
|
551
|
-
exports.PocketIc = PocketIc;
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
export declare function optionalBigInt(value: bigint | undefined | null): [] | [bigint];
|
|
@@ -1,5 +0,0 @@
|
|
|
1
|
-
import { Principal } from '@dfinity/principal';
|
|
2
|
-
export declare function base64Encode(payload: Uint8Array): string;
|
|
3
|
-
export declare function base64EncodePrincipal(principal: Principal): string;
|
|
4
|
-
export declare function base64Decode(payload: string): Uint8Array;
|
|
5
|
-
export declare function hexDecode(payload: string): Uint8Array;
|
|
@@ -1,19 +0,0 @@
|
|
|
1
|
-
"use strict";
|
|
2
|
-
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
-
exports.hexDecode = exports.base64Decode = exports.base64EncodePrincipal = exports.base64Encode = void 0;
|
|
4
|
-
function base64Encode(payload) {
|
|
5
|
-
return Buffer.from(payload).toString('base64');
|
|
6
|
-
}
|
|
7
|
-
exports.base64Encode = base64Encode;
|
|
8
|
-
function base64EncodePrincipal(principal) {
|
|
9
|
-
return base64Encode(principal.toUint8Array());
|
|
10
|
-
}
|
|
11
|
-
exports.base64EncodePrincipal = base64EncodePrincipal;
|
|
12
|
-
function base64Decode(payload) {
|
|
13
|
-
return new Uint8Array(Buffer.from(payload, 'base64'));
|
|
14
|
-
}
|
|
15
|
-
exports.base64Decode = base64Decode;
|
|
16
|
-
function hexDecode(payload) {
|
|
17
|
-
return new Uint8Array(Buffer.from(payload, 'hex'));
|
|
18
|
-
}
|
|
19
|
-
exports.hexDecode = hexDecode;
|
|
@@ -1,4 +0,0 @@
|
|
|
1
|
-
export declare function exists(filePath: string): Promise<boolean>;
|
|
2
|
-
export declare function tmpFile(filePath: string): string;
|
|
3
|
-
export declare function readFileAsBytes(filePath: string): Promise<Uint8Array>;
|
|
4
|
-
export declare function readFileAsString(filePath: string): Promise<string>;
|
|
@@ -1,29 +0,0 @@
|
|
|
1
|
-
"use strict";
|
|
2
|
-
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
-
exports.readFileAsString = exports.readFileAsBytes = exports.tmpFile = exports.exists = void 0;
|
|
4
|
-
const promises_1 = require("node:fs/promises");
|
|
5
|
-
const node_path_1 = require("node:path");
|
|
6
|
-
const node_os_1 = require("node:os");
|
|
7
|
-
async function exists(filePath) {
|
|
8
|
-
try {
|
|
9
|
-
await (0, promises_1.access)(filePath, promises_1.constants.F_OK);
|
|
10
|
-
return true;
|
|
11
|
-
}
|
|
12
|
-
catch (e) {
|
|
13
|
-
return false;
|
|
14
|
-
}
|
|
15
|
-
}
|
|
16
|
-
exports.exists = exists;
|
|
17
|
-
function tmpFile(filePath) {
|
|
18
|
-
return (0, node_path_1.resolve)((0, node_os_1.tmpdir)(), filePath);
|
|
19
|
-
}
|
|
20
|
-
exports.tmpFile = tmpFile;
|
|
21
|
-
async function readFileAsBytes(filePath) {
|
|
22
|
-
const buffer = await (0, promises_1.readFile)(filePath);
|
|
23
|
-
return Uint8Array.from(buffer);
|
|
24
|
-
}
|
|
25
|
-
exports.readFileAsBytes = readFileAsBytes;
|
|
26
|
-
async function readFileAsString(filePath) {
|
|
27
|
-
return await (0, promises_1.readFile)(filePath, { encoding: 'utf-8' });
|
|
28
|
-
}
|
|
29
|
-
exports.readFileAsString = readFileAsString;
|
|
@@ -1,21 +0,0 @@
|
|
|
1
|
-
"use strict";
|
|
2
|
-
var __createBinding = (this && this.__createBinding) || (Object.create ? (function(o, m, k, k2) {
|
|
3
|
-
if (k2 === undefined) k2 = k;
|
|
4
|
-
var desc = Object.getOwnPropertyDescriptor(m, k);
|
|
5
|
-
if (!desc || ("get" in desc ? !m.__esModule : desc.writable || desc.configurable)) {
|
|
6
|
-
desc = { enumerable: true, get: function() { return m[k]; } };
|
|
7
|
-
}
|
|
8
|
-
Object.defineProperty(o, k2, desc);
|
|
9
|
-
}) : (function(o, m, k, k2) {
|
|
10
|
-
if (k2 === undefined) k2 = k;
|
|
11
|
-
o[k2] = m[k];
|
|
12
|
-
}));
|
|
13
|
-
var __exportStar = (this && this.__exportStar) || function(m, exports) {
|
|
14
|
-
for (var p in m) if (p !== "default" && !Object.prototype.hasOwnProperty.call(exports, p)) __createBinding(exports, m, p);
|
|
15
|
-
};
|
|
16
|
-
Object.defineProperty(exports, "__esModule", { value: true });
|
|
17
|
-
__exportStar(require("./candid"), exports);
|
|
18
|
-
__exportStar(require("./encoding"), exports);
|
|
19
|
-
__exportStar(require("./fs"), exports);
|
|
20
|
-
__exportStar(require("./os"), exports);
|
|
21
|
-
__exportStar(require("./poll"), exports);
|
|
@@ -1,19 +0,0 @@
|
|
|
1
|
-
"use strict";
|
|
2
|
-
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
-
exports.isArm = exports.isDarwin = exports.isLinux = exports.is64Bit = void 0;
|
|
4
|
-
function is64Bit() {
|
|
5
|
-
return process.arch === 'x64';
|
|
6
|
-
}
|
|
7
|
-
exports.is64Bit = is64Bit;
|
|
8
|
-
function isLinux() {
|
|
9
|
-
return process.platform === 'linux';
|
|
10
|
-
}
|
|
11
|
-
exports.isLinux = isLinux;
|
|
12
|
-
function isDarwin() {
|
|
13
|
-
return process.platform === 'darwin';
|
|
14
|
-
}
|
|
15
|
-
exports.isDarwin = isDarwin;
|
|
16
|
-
function isArm() {
|
|
17
|
-
return process.arch === 'arm64';
|
|
18
|
-
}
|
|
19
|
-
exports.isArm = isArm;
|