ic-mops 0.37.1 → 0.37.3
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/commands/docs.ts +1 -1
- package/commands/test/test.ts +1 -1
- package/dist/bin/mops.js +0 -0
- package/dist/commands/docs.js +1 -1
- package/dist/commands/test/test.js +1 -1
- package/dist/package.json +1 -1
- package/package.json +1 -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 +0,0 @@
|
|
|
1
|
-
export {};
|
|
@@ -1,5 +0,0 @@
|
|
|
1
|
-
"use strict";
|
|
2
|
-
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
-
exports.idlFactory = void 0;
|
|
4
|
-
var clock_did_1 = require("../../declarations/clock.did");
|
|
5
|
-
Object.defineProperty(exports, "idlFactory", { enumerable: true, get: function () { return clock_did_1.idlFactory; } });
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
export {};
|
|
@@ -1,48 +0,0 @@
|
|
|
1
|
-
"use strict";
|
|
2
|
-
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
-
const node_path_1 = require("node:path");
|
|
4
|
-
const principal_1 = require("@dfinity/principal");
|
|
5
|
-
const pic_1 = require("@hadronous/pic");
|
|
6
|
-
const clock_1 = require("../clock");
|
|
7
|
-
const WASM_PATH = (0, node_path_1.resolve)(__dirname, '..', '..', '..', '..', '.dfx', 'local', 'canisters', 'clock', 'clock.wasm');
|
|
8
|
-
describe('Clock', () => {
|
|
9
|
-
let actor;
|
|
10
|
-
let pic;
|
|
11
|
-
let canisterId;
|
|
12
|
-
beforeEach(async () => {
|
|
13
|
-
pic = await pic_1.PocketIc.create();
|
|
14
|
-
const fixture = await pic.setupCanister(clock_1.idlFactory, WASM_PATH);
|
|
15
|
-
actor = fixture.actor;
|
|
16
|
-
canisterId = fixture.canisterId;
|
|
17
|
-
});
|
|
18
|
-
afterEach(async () => {
|
|
19
|
-
await pic.tearDown();
|
|
20
|
-
});
|
|
21
|
-
it('should create the correct canister', async () => {
|
|
22
|
-
const canisterExists = await pic.checkCanisterExists(canisterId);
|
|
23
|
-
expect(canisterExists).toBe(true);
|
|
24
|
-
});
|
|
25
|
-
it('should not create any other canister', async () => {
|
|
26
|
-
const otherCanisterId = principal_1.Principal.fromUint8Array(new Uint8Array([0]));
|
|
27
|
-
const canisterExists = await pic.checkCanisterExists(otherCanisterId);
|
|
28
|
-
expect(canisterExists).toBe(false);
|
|
29
|
-
});
|
|
30
|
-
it('should set and get canister cycles', async () => {
|
|
31
|
-
const cycles = await pic.getCyclesBalance(canisterId);
|
|
32
|
-
const cyclesToAdd = 1000000;
|
|
33
|
-
const updatedCyclesBalance = await pic.addCycles(canisterId, cyclesToAdd);
|
|
34
|
-
const fetchUpdatedCyclesBalance = await pic.getCyclesBalance(canisterId);
|
|
35
|
-
expect(updatedCyclesBalance).toEqual(cycles + cyclesToAdd);
|
|
36
|
-
expect(fetchUpdatedCyclesBalance).toEqual(updatedCyclesBalance);
|
|
37
|
-
});
|
|
38
|
-
it.each([1, 10, 1000, 100000])('should return the correct time after %d second(s)', async (timeToAdvanceS) => {
|
|
39
|
-
await pic.resetTime();
|
|
40
|
-
await pic.tick();
|
|
41
|
-
const timeToAdvanceMs = timeToAdvanceS * 1000;
|
|
42
|
-
const initialTime = await actor.get();
|
|
43
|
-
await pic.advanceTime(timeToAdvanceMs);
|
|
44
|
-
await pic.tick();
|
|
45
|
-
const finalTime = await actor.get();
|
|
46
|
-
expect(finalTime).toEqual(initialTime + BigInt(timeToAdvanceMs));
|
|
47
|
-
});
|
|
48
|
-
});
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
export {};
|
|
@@ -1,5 +0,0 @@
|
|
|
1
|
-
"use strict";
|
|
2
|
-
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
-
exports.idlFactory = void 0;
|
|
4
|
-
var counter_did_1 = require("../../declarations/counter.did");
|
|
5
|
-
Object.defineProperty(exports, "idlFactory", { enumerable: true, get: function () { return counter_did_1.idlFactory; } });
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
export {};
|
|
@@ -1,80 +0,0 @@
|
|
|
1
|
-
"use strict";
|
|
2
|
-
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
-
const node_path_1 = require("node:path");
|
|
4
|
-
const pic_1 = require("@hadronous/pic");
|
|
5
|
-
const counter_1 = require("../counter");
|
|
6
|
-
const WASM_PATH = (0, node_path_1.resolve)(__dirname, '..', '..', '..', '..', '.dfx', 'local', 'canisters', 'counter', 'counter.wasm');
|
|
7
|
-
describe('Counter', () => {
|
|
8
|
-
let pic;
|
|
9
|
-
let actor;
|
|
10
|
-
let canisterId;
|
|
11
|
-
beforeEach(async () => {
|
|
12
|
-
pic = await pic_1.PocketIc.create();
|
|
13
|
-
const fixture = await pic.setupCanister(counter_1.idlFactory, WASM_PATH);
|
|
14
|
-
actor = fixture.actor;
|
|
15
|
-
canisterId = fixture.canisterId;
|
|
16
|
-
});
|
|
17
|
-
afterEach(async () => {
|
|
18
|
-
await pic.tearDown();
|
|
19
|
-
});
|
|
20
|
-
it('should start at 0', async () => {
|
|
21
|
-
const result = await actor.get();
|
|
22
|
-
expect(result).toEqual(0n);
|
|
23
|
-
});
|
|
24
|
-
it.each([42n, 306n, 7n])('should set the counter to %d', async (input) => {
|
|
25
|
-
await actor.set(input);
|
|
26
|
-
const result = await actor.get();
|
|
27
|
-
expect(result).toEqual(input);
|
|
28
|
-
});
|
|
29
|
-
it('should increment from 0', async () => {
|
|
30
|
-
const initialCount = await actor.get();
|
|
31
|
-
await actor.inc();
|
|
32
|
-
const countAfterFirstInc = await actor.get();
|
|
33
|
-
await actor.inc();
|
|
34
|
-
const finalCount = await actor.get();
|
|
35
|
-
expect(initialCount).toEqual(0n);
|
|
36
|
-
expect(countAfterFirstInc).toEqual(1n);
|
|
37
|
-
expect(finalCount).toEqual(2n);
|
|
38
|
-
});
|
|
39
|
-
it.each([42n, 306n, 7n])('should increment from %d', async (input) => {
|
|
40
|
-
await actor.set(input);
|
|
41
|
-
const initialCount = await actor.get();
|
|
42
|
-
await actor.inc();
|
|
43
|
-
const countAfterFirstInc = await actor.get();
|
|
44
|
-
await actor.inc();
|
|
45
|
-
const finalCount = await actor.get();
|
|
46
|
-
expect(initialCount).toEqual(input);
|
|
47
|
-
expect(countAfterFirstInc).toEqual(input + 1n);
|
|
48
|
-
expect(finalCount).toEqual(input + 2n);
|
|
49
|
-
});
|
|
50
|
-
it.each([42n, 306n, 7n])('should decrement from %d', async (input) => {
|
|
51
|
-
await actor.set(input);
|
|
52
|
-
const initialCount = await actor.get();
|
|
53
|
-
await actor.dec();
|
|
54
|
-
const countAfterFirstDec = await actor.get();
|
|
55
|
-
await actor.dec();
|
|
56
|
-
const finalCount = await actor.get();
|
|
57
|
-
expect(initialCount).toEqual(input);
|
|
58
|
-
expect(countAfterFirstDec).toEqual(input - 1n);
|
|
59
|
-
expect(finalCount).toEqual(input - 2n);
|
|
60
|
-
});
|
|
61
|
-
it('should fail to decrement from 0', async () => {
|
|
62
|
-
const initialCount = await actor.get();
|
|
63
|
-
expect(initialCount).toEqual(0n);
|
|
64
|
-
await expect(actor.dec()).rejects.toThrow('Natural subtraction underflow');
|
|
65
|
-
});
|
|
66
|
-
it('should upgrade the canister', async () => {
|
|
67
|
-
await actor.inc();
|
|
68
|
-
const preUpgradeCount = await actor.get();
|
|
69
|
-
await pic.upgradeCanister(canisterId, WASM_PATH);
|
|
70
|
-
const postUpgradeCount = await actor.get();
|
|
71
|
-
expect(preUpgradeCount).toEqual(postUpgradeCount);
|
|
72
|
-
});
|
|
73
|
-
it('should reinstall the canister', async () => {
|
|
74
|
-
await actor.inc();
|
|
75
|
-
const preReinstallCount = await actor.get();
|
|
76
|
-
await pic.reinstallCode(canisterId, WASM_PATH);
|
|
77
|
-
const postReinstallCount = await actor.get();
|
|
78
|
-
expect(postReinstallCount).not.toEqual(preReinstallCount);
|
|
79
|
-
});
|
|
80
|
-
});
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
export {};
|
|
@@ -1,211 +0,0 @@
|
|
|
1
|
-
"use strict";
|
|
2
|
-
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
-
const node_path_1 = require("node:path");
|
|
4
|
-
const agent_1 = require("@dfinity/agent");
|
|
5
|
-
const pic_1 = require("@hadronous/pic");
|
|
6
|
-
const todo_1 = require("../todo");
|
|
7
|
-
const WASM_PATH = (0, node_path_1.resolve)(__dirname, '..', '..', '..', '..', '.dfx', 'local', 'canisters', 'todo', 'todo.wasm');
|
|
8
|
-
describe('Todo', () => {
|
|
9
|
-
let pic;
|
|
10
|
-
let actor;
|
|
11
|
-
let canisterId;
|
|
12
|
-
const alice = (0, pic_1.createIdentity)('superSecretAlicePassword');
|
|
13
|
-
const bob = (0, pic_1.createIdentity)('superSecretBobPassword');
|
|
14
|
-
beforeEach(async () => {
|
|
15
|
-
pic = await pic_1.PocketIc.create();
|
|
16
|
-
const fixture = await pic.setupCanister(todo_1.idlFactory, WASM_PATH);
|
|
17
|
-
actor = fixture.actor;
|
|
18
|
-
canisterId = fixture.canisterId;
|
|
19
|
-
});
|
|
20
|
-
afterEach(async () => {
|
|
21
|
-
await pic.tearDown();
|
|
22
|
-
});
|
|
23
|
-
describe('with an anonymous user', () => {
|
|
24
|
-
const identity = new agent_1.AnonymousIdentity();
|
|
25
|
-
const expectedError = 'Anonymous principals are not allowed to call this method';
|
|
26
|
-
beforeEach(() => {
|
|
27
|
-
actor.setIdentity(identity);
|
|
28
|
-
});
|
|
29
|
-
it('should prevent creating a todo', async () => {
|
|
30
|
-
await expect(actor.create_todo({
|
|
31
|
-
text: 'Learn Rust',
|
|
32
|
-
})).rejects.toThrow(expectedError);
|
|
33
|
-
});
|
|
34
|
-
it('should prevent getting todos', async () => {
|
|
35
|
-
await expect(actor.get_todos()).rejects.toThrow(expectedError);
|
|
36
|
-
});
|
|
37
|
-
it('should prevent updating a todo', async () => {
|
|
38
|
-
await expect(actor.update_todo(1n, {
|
|
39
|
-
text: ['Learn Rust'],
|
|
40
|
-
done: [],
|
|
41
|
-
})).rejects.toThrow(expectedError);
|
|
42
|
-
});
|
|
43
|
-
it('should prevent deleting a todo', async () => {
|
|
44
|
-
await expect(actor.delete_todo(1n)).rejects.toThrow(expectedError);
|
|
45
|
-
});
|
|
46
|
-
});
|
|
47
|
-
describe('with alice', () => {
|
|
48
|
-
beforeEach(() => {
|
|
49
|
-
actor.setIdentity(alice);
|
|
50
|
-
});
|
|
51
|
-
it('should allow creating a todo', async () => {
|
|
52
|
-
const initialGetResponse = await actor.get_todos();
|
|
53
|
-
const createResponse = await actor.create_todo({ text: 'Learn Rust' });
|
|
54
|
-
const getResponse = await actor.get_todos();
|
|
55
|
-
expect(initialGetResponse.todos).toHaveLength(0);
|
|
56
|
-
expect(getResponse.todos).toHaveLength(1);
|
|
57
|
-
expect(getResponse.todos).toContainEqual({
|
|
58
|
-
id: createResponse.id,
|
|
59
|
-
text: 'Learn Rust',
|
|
60
|
-
done: false,
|
|
61
|
-
});
|
|
62
|
-
});
|
|
63
|
-
it('should allow updating a todo', async () => {
|
|
64
|
-
const initialGetResponse = await actor.get_todos();
|
|
65
|
-
const createResponse = await actor.create_todo({
|
|
66
|
-
text: 'Learn Rust',
|
|
67
|
-
});
|
|
68
|
-
const afterCreateGetResponse = await actor.get_todos();
|
|
69
|
-
await actor.update_todo(createResponse.id, {
|
|
70
|
-
text: ['Learn Rust and WebAssembly'],
|
|
71
|
-
done: [],
|
|
72
|
-
});
|
|
73
|
-
const afterUpdateGetResponse = await actor.get_todos();
|
|
74
|
-
expect(initialGetResponse.todos).toHaveLength(0);
|
|
75
|
-
expect(afterCreateGetResponse.todos).toHaveLength(1);
|
|
76
|
-
expect(afterCreateGetResponse.todos).toContainEqual({
|
|
77
|
-
id: createResponse.id,
|
|
78
|
-
text: 'Learn Rust',
|
|
79
|
-
done: false,
|
|
80
|
-
});
|
|
81
|
-
expect(afterUpdateGetResponse.todos).toHaveLength(1);
|
|
82
|
-
expect(afterUpdateGetResponse.todos).toContainEqual({
|
|
83
|
-
id: createResponse.id,
|
|
84
|
-
text: 'Learn Rust and WebAssembly',
|
|
85
|
-
done: false,
|
|
86
|
-
});
|
|
87
|
-
});
|
|
88
|
-
it('should allow deleting a todo', async () => {
|
|
89
|
-
const initialGetResponse = await actor.get_todos();
|
|
90
|
-
const createResponse = await actor.create_todo({
|
|
91
|
-
text: 'Learn Rust',
|
|
92
|
-
});
|
|
93
|
-
const afterCreateGetResponse = await actor.get_todos();
|
|
94
|
-
await actor.delete_todo(createResponse.id);
|
|
95
|
-
const afterDeleteGetResponse = await actor.get_todos();
|
|
96
|
-
expect(initialGetResponse.todos).toHaveLength(0);
|
|
97
|
-
expect(afterCreateGetResponse.todos).toHaveLength(1);
|
|
98
|
-
expect(afterCreateGetResponse.todos).toContainEqual({
|
|
99
|
-
id: createResponse.id,
|
|
100
|
-
text: 'Learn Rust',
|
|
101
|
-
done: false,
|
|
102
|
-
});
|
|
103
|
-
expect(afterDeleteGetResponse.todos).toHaveLength(0);
|
|
104
|
-
});
|
|
105
|
-
});
|
|
106
|
-
describe('with alice and bob', () => {
|
|
107
|
-
it("should return alice's todos to alice and bob's todos to bob", async () => {
|
|
108
|
-
actor.setIdentity(alice);
|
|
109
|
-
const aliceCreateResponse = await actor.create_todo({
|
|
110
|
-
text: 'Learn Rust',
|
|
111
|
-
});
|
|
112
|
-
const aliceAfterCreateGetResponse = await actor.get_todos();
|
|
113
|
-
actor.setIdentity(bob);
|
|
114
|
-
const bobCreateResponse = await actor.create_todo({
|
|
115
|
-
text: 'Learn WebAssembly',
|
|
116
|
-
});
|
|
117
|
-
const bobAfterCreateGetResponse = await actor.get_todos();
|
|
118
|
-
expect(aliceAfterCreateGetResponse.todos).toHaveLength(1);
|
|
119
|
-
expect(aliceAfterCreateGetResponse.todos).toContainEqual({
|
|
120
|
-
id: aliceCreateResponse.id,
|
|
121
|
-
text: 'Learn Rust',
|
|
122
|
-
done: false,
|
|
123
|
-
});
|
|
124
|
-
expect(bobAfterCreateGetResponse.todos).toHaveLength(1);
|
|
125
|
-
expect(bobAfterCreateGetResponse.todos).toContainEqual({
|
|
126
|
-
id: bobCreateResponse.id,
|
|
127
|
-
text: 'Learn WebAssembly',
|
|
128
|
-
done: false,
|
|
129
|
-
});
|
|
130
|
-
});
|
|
131
|
-
it("should prevent bob from updating alice's todo", async () => {
|
|
132
|
-
actor.setIdentity(alice);
|
|
133
|
-
const aliceCreateResponse = await actor.create_todo({
|
|
134
|
-
text: 'Learn Rust',
|
|
135
|
-
});
|
|
136
|
-
actor.setIdentity(bob);
|
|
137
|
-
await expect(actor.update_todo(aliceCreateResponse.id, {
|
|
138
|
-
text: ['Learn Rust and WebAssembly'],
|
|
139
|
-
done: [],
|
|
140
|
-
})).rejects.toThrow(`Caller with principal ${bob
|
|
141
|
-
.getPrincipal()
|
|
142
|
-
.toText()} does not own todo with id ${aliceCreateResponse.id}`);
|
|
143
|
-
});
|
|
144
|
-
it('should prevent bob from deleting alices todo', async () => {
|
|
145
|
-
actor.setIdentity(alice);
|
|
146
|
-
const aliceCreateResponse = await actor.create_todo({
|
|
147
|
-
text: 'Learn Rust',
|
|
148
|
-
});
|
|
149
|
-
actor.setIdentity(bob);
|
|
150
|
-
await expect(actor.delete_todo(aliceCreateResponse.id)).rejects.toThrow(`Caller with principal ${bob
|
|
151
|
-
.getPrincipal()
|
|
152
|
-
.toText()} does not own todo with id ${aliceCreateResponse.id}`);
|
|
153
|
-
});
|
|
154
|
-
it('should survive an upgrade', async () => {
|
|
155
|
-
actor.setIdentity(alice);
|
|
156
|
-
const aliceCreateResponse = await actor.create_todo({
|
|
157
|
-
text: 'Learn Rust',
|
|
158
|
-
});
|
|
159
|
-
actor.setIdentity(bob);
|
|
160
|
-
const bobCreateResponse = await actor.create_todo({
|
|
161
|
-
text: 'Learn WebAssembly',
|
|
162
|
-
});
|
|
163
|
-
await pic.upgradeCanister(canisterId, WASM_PATH);
|
|
164
|
-
actor.setIdentity(alice);
|
|
165
|
-
const aliceAfterUpgradeGetResponse = await actor.get_todos();
|
|
166
|
-
actor.setIdentity(bob);
|
|
167
|
-
const bobAfterUpgradeGetResponse = await actor.get_todos();
|
|
168
|
-
expect(aliceAfterUpgradeGetResponse.todos).toHaveLength(1);
|
|
169
|
-
expect(aliceAfterUpgradeGetResponse.todos).toContainEqual({
|
|
170
|
-
id: aliceCreateResponse.id,
|
|
171
|
-
text: 'Learn Rust',
|
|
172
|
-
done: false,
|
|
173
|
-
});
|
|
174
|
-
expect(bobAfterUpgradeGetResponse.todos).toHaveLength(1);
|
|
175
|
-
expect(bobAfterUpgradeGetResponse.todos).toContainEqual({
|
|
176
|
-
id: bobCreateResponse.id,
|
|
177
|
-
text: 'Learn WebAssembly',
|
|
178
|
-
done: false,
|
|
179
|
-
});
|
|
180
|
-
});
|
|
181
|
-
it('should survive a reset and stable memory restore', async () => {
|
|
182
|
-
actor.setIdentity(alice);
|
|
183
|
-
const aliceCreateResponse = await actor.create_todo({
|
|
184
|
-
text: 'Learn Rust',
|
|
185
|
-
});
|
|
186
|
-
actor.setIdentity(bob);
|
|
187
|
-
const bobCreateResponse = await actor.create_todo({
|
|
188
|
-
text: 'Learn WebAssembly',
|
|
189
|
-
});
|
|
190
|
-
const stableMemory = await pic.getStableMemory(canisterId);
|
|
191
|
-
await pic.reinstallCode(canisterId, WASM_PATH);
|
|
192
|
-
await pic.setStableMemory(canisterId, stableMemory);
|
|
193
|
-
actor.setIdentity(alice);
|
|
194
|
-
const aliceAfterUpgradeGetResponse = await actor.get_todos();
|
|
195
|
-
actor.setIdentity(bob);
|
|
196
|
-
const bobAfterUpgradeGetResponse = await actor.get_todos();
|
|
197
|
-
expect(aliceAfterUpgradeGetResponse.todos).toHaveLength(1);
|
|
198
|
-
expect(aliceAfterUpgradeGetResponse.todos).toContainEqual({
|
|
199
|
-
id: aliceCreateResponse.id,
|
|
200
|
-
text: 'Learn Rust',
|
|
201
|
-
done: false,
|
|
202
|
-
});
|
|
203
|
-
expect(bobAfterUpgradeGetResponse.todos).toHaveLength(1);
|
|
204
|
-
expect(bobAfterUpgradeGetResponse.todos).toContainEqual({
|
|
205
|
-
id: bobCreateResponse.id,
|
|
206
|
-
text: 'Learn WebAssembly',
|
|
207
|
-
done: false,
|
|
208
|
-
});
|
|
209
|
-
});
|
|
210
|
-
});
|
|
211
|
-
});
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
export {};
|
|
@@ -1,5 +0,0 @@
|
|
|
1
|
-
"use strict";
|
|
2
|
-
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
-
exports.idlFactory = void 0;
|
|
4
|
-
var todo_did_1 = require("../../declarations/todo.did");
|
|
5
|
-
Object.defineProperty(exports, "idlFactory", { enumerable: true, get: function () { return todo_did_1.idlFactory; } });
|
|
@@ -1,12 +0,0 @@
|
|
|
1
|
-
export declare class BinStartError extends Error {
|
|
2
|
-
constructor(cause: Error);
|
|
3
|
-
}
|
|
4
|
-
export declare class BinStartMacOSArmError extends Error {
|
|
5
|
-
constructor(cause: Error);
|
|
6
|
-
}
|
|
7
|
-
export declare class BinNotFoundError extends Error {
|
|
8
|
-
constructor(picBinPath: string);
|
|
9
|
-
}
|
|
10
|
-
export declare class BinTimeoutError extends Error {
|
|
11
|
-
constructor();
|
|
12
|
-
}
|
|
@@ -1,36 +0,0 @@
|
|
|
1
|
-
"use strict";
|
|
2
|
-
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
-
exports.BinTimeoutError = exports.BinNotFoundError = exports.BinStartMacOSArmError = exports.BinStartError = void 0;
|
|
4
|
-
class BinStartError extends Error {
|
|
5
|
-
constructor(cause) {
|
|
6
|
-
super(`There was an error starting the PocketIC Binary.
|
|
7
|
-
|
|
8
|
-
Original error: ${cause.name} ${cause.message}.
|
|
9
|
-
${cause.stack}`, { cause });
|
|
10
|
-
}
|
|
11
|
-
}
|
|
12
|
-
exports.BinStartError = BinStartError;
|
|
13
|
-
class BinStartMacOSArmError extends Error {
|
|
14
|
-
constructor(cause) {
|
|
15
|
-
super(`There was an error starting the PocketIC Binary.
|
|
16
|
-
|
|
17
|
-
It seems you are running on an Apple Silicon Mac. The PocketIC binary can not run with the ARM architecture on Apple Silicon Macs.
|
|
18
|
-
Please install and enable Rosetta if it is not enabled and try again.
|
|
19
|
-
|
|
20
|
-
Original error: ${cause.name} ${cause.message}.
|
|
21
|
-
${cause.stack}`, { cause });
|
|
22
|
-
}
|
|
23
|
-
}
|
|
24
|
-
exports.BinStartMacOSArmError = BinStartMacOSArmError;
|
|
25
|
-
class BinNotFoundError extends Error {
|
|
26
|
-
constructor(picBinPath) {
|
|
27
|
-
super(`Could not find the PocketIC binary. The PocketIC binary could not be found at ${picBinPath}. Please try installing @hadronous/pic again.`);
|
|
28
|
-
}
|
|
29
|
-
}
|
|
30
|
-
exports.BinNotFoundError = BinNotFoundError;
|
|
31
|
-
class BinTimeoutError extends Error {
|
|
32
|
-
constructor() {
|
|
33
|
-
super('The PocketIC binary took too long to start. Please try again.');
|
|
34
|
-
}
|
|
35
|
-
}
|
|
36
|
-
exports.BinTimeoutError = BinTimeoutError;
|
|
@@ -1,15 +0,0 @@
|
|
|
1
|
-
export type HeadersInit = Record<string, string>;
|
|
2
|
-
export interface GetOptions {
|
|
3
|
-
headers?: HeadersInit;
|
|
4
|
-
}
|
|
5
|
-
export interface PostOptions<P> {
|
|
6
|
-
body?: P;
|
|
7
|
-
headers?: HeadersInit;
|
|
8
|
-
}
|
|
9
|
-
export declare const JSON_HEADER: HeadersInit;
|
|
10
|
-
export declare class HttpClient {
|
|
11
|
-
private constructor();
|
|
12
|
-
static get<R>(url: string, options?: GetOptions): Promise<R>;
|
|
13
|
-
static post<P, R>(url: string, options?: PostOptions<P>): Promise<R>;
|
|
14
|
-
}
|
|
15
|
-
export declare function handleFetchError(response: Response): void;
|
|
@@ -1,37 +0,0 @@
|
|
|
1
|
-
"use strict";
|
|
2
|
-
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
-
exports.handleFetchError = exports.HttpClient = exports.JSON_HEADER = void 0;
|
|
4
|
-
exports.JSON_HEADER = {
|
|
5
|
-
'Content-Type': 'application/json',
|
|
6
|
-
};
|
|
7
|
-
class HttpClient {
|
|
8
|
-
constructor() { }
|
|
9
|
-
static async get(url, options) {
|
|
10
|
-
const headers = options?.headers ?? {};
|
|
11
|
-
const response = await fetch(url, {
|
|
12
|
-
method: 'GET',
|
|
13
|
-
headers: { ...headers, ...exports.JSON_HEADER },
|
|
14
|
-
});
|
|
15
|
-
handleFetchError(response);
|
|
16
|
-
return (await response.json());
|
|
17
|
-
}
|
|
18
|
-
static async post(url, options) {
|
|
19
|
-
const body = options?.body ? JSON.stringify(options.body) : null;
|
|
20
|
-
const headers = options?.headers ?? {};
|
|
21
|
-
const response = await fetch(url, {
|
|
22
|
-
method: 'POST',
|
|
23
|
-
body,
|
|
24
|
-
headers: { ...headers, ...exports.JSON_HEADER },
|
|
25
|
-
});
|
|
26
|
-
handleFetchError(response);
|
|
27
|
-
return (await response.json());
|
|
28
|
-
}
|
|
29
|
-
}
|
|
30
|
-
exports.HttpClient = HttpClient;
|
|
31
|
-
function handleFetchError(response) {
|
|
32
|
-
if (!response.ok) {
|
|
33
|
-
console.error('Error response', response.url, response.statusText);
|
|
34
|
-
throw new Error(`${response.url} ${response.statusText}`);
|
|
35
|
-
}
|
|
36
|
-
}
|
|
37
|
-
exports.handleFetchError = handleFetchError;
|
|
@@ -1,66 +0,0 @@
|
|
|
1
|
-
import { Identity } from '@dfinity/agent';
|
|
2
|
-
/**
|
|
3
|
-
* Create an Identity from a seed phrase.
|
|
4
|
-
* The seed phrase can be any arbitrary string.
|
|
5
|
-
*
|
|
6
|
-
* The Identity is generated deterministically from the seed phrase,
|
|
7
|
-
* so subsequent calls to this function with the same seed phrase will
|
|
8
|
-
* produce the same Identity.
|
|
9
|
-
*
|
|
10
|
-
* This is useful for tests where a persistent Identity is necessary
|
|
11
|
-
* but it's easier to store the seed phrase than the Identity itself.
|
|
12
|
-
*
|
|
13
|
-
* @category API
|
|
14
|
-
* @param seedPhrase The seed phrase to create the identity from. Can be any arbitrary string.
|
|
15
|
-
* @returns An identity created from the seed phrase.
|
|
16
|
-
*
|
|
17
|
-
* @see [Identity](https://agent-js.icp.xyz/agent/interfaces/Identity.html)
|
|
18
|
-
*
|
|
19
|
-
* @example
|
|
20
|
-
* ```ts
|
|
21
|
-
* import { PocketIc, createIdentity } from '@hadronous/pic';
|
|
22
|
-
* import { AnonymousIdentity } from '@dfinity/agent';
|
|
23
|
-
* import { _SERVICE, idlFactory } from '../declarations';
|
|
24
|
-
*
|
|
25
|
-
* const wasmPath = resolve('..', '..', 'canister.wasm');
|
|
26
|
-
*
|
|
27
|
-
* const pic = await PocketIc.create();
|
|
28
|
-
* const fixture = await pic.setupCanister<_SERVICE>(idlFactory, wasmPath);
|
|
29
|
-
* const { actor } = fixture;
|
|
30
|
-
*
|
|
31
|
-
* const bob = createIdentity('SuperSecretSeedPhraseForBob');
|
|
32
|
-
* actor.setIdentity(bob);
|
|
33
|
-
* ```
|
|
34
|
-
*/
|
|
35
|
-
export declare function createIdentity(seedPhrase: string): Identity;
|
|
36
|
-
/**
|
|
37
|
-
* Create an Identity from a randomly generated bip39 seed phrase.
|
|
38
|
-
* Subsequent calls to this function will produce different Identities
|
|
39
|
-
* with an extremely low probability of collision.
|
|
40
|
-
*
|
|
41
|
-
* This is useful for tests where it is important to avoid conflicts arising
|
|
42
|
-
* from multiple identities accessing the same canister and maintaining
|
|
43
|
-
* the necessary seed phrases would become cumbersome.
|
|
44
|
-
*
|
|
45
|
-
* @category API
|
|
46
|
-
* @returns An identity created from a random seed phrase.
|
|
47
|
-
*
|
|
48
|
-
* @see [Identity](https://agent-js.icp.xyz/agent/interfaces/Identity.html)
|
|
49
|
-
*
|
|
50
|
-
* @example
|
|
51
|
-
* ```ts
|
|
52
|
-
* import { PocketIc, generateRandomIdentity } from '@hadronous/pic';
|
|
53
|
-
* import { AnonymousIdentity } from '@dfinity/agent';
|
|
54
|
-
* import { _SERVICE, idlFactory } from '../declarations';
|
|
55
|
-
*
|
|
56
|
-
* const wasmPath = resolve('..', '..', 'canister.wasm');
|
|
57
|
-
*
|
|
58
|
-
* const pic = await PocketIc.create();
|
|
59
|
-
* const fixture = await pic.setupCanister<_SERVICE>(idlFactory, wasmPath);
|
|
60
|
-
* const { actor } = fixture;
|
|
61
|
-
*
|
|
62
|
-
* const bob = generateRandomIdentity();
|
|
63
|
-
* actor.setIdentity(bob);
|
|
64
|
-
* ```
|
|
65
|
-
*/
|
|
66
|
-
export declare function generateRandomIdentity(): Identity;
|