@portal-hq/web 3.3.4-beta.1 → 3.3.5-alpha
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/lib/commonjs/index.js +29 -1
- package/lib/commonjs/index.test.js +52 -0
- package/lib/commonjs/mpc/index.js +30 -1
- package/lib/commonjs/mpc/index.test.js +532 -244
- package/lib/esm/index.js +29 -1
- package/lib/esm/index.test.js +53 -1
- package/lib/esm/mpc/index.js +30 -1
- package/lib/esm/mpc/index.test.js +537 -249
- package/package.json +1 -1
- package/src/__mocks/constants.ts +10 -2
- package/src/__mocks/portal/mpc.ts +4 -0
- package/src/index.test.ts +124 -0
- package/src/index.ts +39 -2
- package/src/mpc/index.test.ts +883 -608
- package/src/mpc/index.ts +39 -2
- package/types.d.ts +13 -0
|
@@ -18,7 +18,7 @@ describe('Mpc', () => {
|
|
|
18
18
|
jest.clearAllMocks();
|
|
19
19
|
portal_1.default.host = constants_1.mockHost;
|
|
20
20
|
mpc = new _1.default({
|
|
21
|
-
portal: portal_1.default
|
|
21
|
+
portal: portal_1.default,
|
|
22
22
|
});
|
|
23
23
|
});
|
|
24
24
|
describe('backup', () => {
|
|
@@ -31,7 +31,8 @@ describe('Mpc', () => {
|
|
|
31
31
|
};
|
|
32
32
|
it('should successfully run backup', (done) => {
|
|
33
33
|
var _a;
|
|
34
|
-
jest
|
|
34
|
+
jest
|
|
35
|
+
.spyOn((_a = mpc.iframe) === null || _a === void 0 ? void 0 : _a.contentWindow, 'postMessage')
|
|
35
36
|
.mockImplementation((message, origin) => {
|
|
36
37
|
const { type, data } = message;
|
|
37
38
|
expect(type).toEqual('portal:wasm:backup');
|
|
@@ -43,8 +44,8 @@ describe('Mpc', () => {
|
|
|
43
44
|
type: 'portal:wasm:backupProgress',
|
|
44
45
|
data: {
|
|
45
46
|
status: index_1.MpcStatuses.EncryptingShare,
|
|
46
|
-
done: false
|
|
47
|
-
}
|
|
47
|
+
done: false,
|
|
48
|
+
},
|
|
48
49
|
},
|
|
49
50
|
}));
|
|
50
51
|
window.dispatchEvent(new MessageEvent('message', {
|
|
@@ -53,8 +54,8 @@ describe('Mpc', () => {
|
|
|
53
54
|
type: 'portal:wasm:backupProgress',
|
|
54
55
|
data: {
|
|
55
56
|
status: index_1.MpcStatuses.StoringShare,
|
|
56
|
-
done: false
|
|
57
|
-
}
|
|
57
|
+
done: false,
|
|
58
|
+
},
|
|
58
59
|
},
|
|
59
60
|
}));
|
|
60
61
|
window.dispatchEvent(new MessageEvent('message', {
|
|
@@ -63,8 +64,8 @@ describe('Mpc', () => {
|
|
|
63
64
|
type: 'portal:wasm:backupProgress',
|
|
64
65
|
data: {
|
|
65
66
|
status: index_1.MpcStatuses.Done,
|
|
66
|
-
done: true
|
|
67
|
-
}
|
|
67
|
+
done: true,
|
|
68
|
+
},
|
|
68
69
|
},
|
|
69
70
|
}));
|
|
70
71
|
window.dispatchEvent(new MessageEvent('message', {
|
|
@@ -73,19 +74,28 @@ describe('Mpc', () => {
|
|
|
73
74
|
type: 'portal:wasm:backupResult',
|
|
74
75
|
data: {
|
|
75
76
|
cipherText: 'test',
|
|
76
|
-
}
|
|
77
|
+
},
|
|
77
78
|
},
|
|
78
79
|
}));
|
|
79
80
|
});
|
|
80
81
|
const progressMock = jest.fn();
|
|
81
|
-
mpc
|
|
82
|
+
mpc
|
|
83
|
+
.backup(args, progressMock)
|
|
84
|
+
.then((res) => {
|
|
82
85
|
expect(res.cipherText).toEqual(constants_1.mockCipherText);
|
|
83
86
|
expect(progressMock).toHaveBeenCalledTimes(3);
|
|
84
|
-
expect(progressMock.mock.calls[0]).toEqual([
|
|
85
|
-
|
|
86
|
-
|
|
87
|
-
|
|
88
|
-
|
|
87
|
+
expect(progressMock.mock.calls[0]).toEqual([
|
|
88
|
+
{ status: index_1.MpcStatuses.EncryptingShare, done: false },
|
|
89
|
+
]);
|
|
90
|
+
expect(progressMock.mock.calls[1]).toEqual([
|
|
91
|
+
{ status: index_1.MpcStatuses.StoringShare, done: false },
|
|
92
|
+
]);
|
|
93
|
+
expect(progressMock.mock.calls[2]).toEqual([
|
|
94
|
+
{ status: index_1.MpcStatuses.Done, done: true },
|
|
95
|
+
]);
|
|
96
|
+
done();
|
|
97
|
+
})
|
|
98
|
+
.catch((e) => {
|
|
89
99
|
console.error(e);
|
|
90
100
|
expect(0).toEqual(1);
|
|
91
101
|
done();
|
|
@@ -93,7 +103,8 @@ describe('Mpc', () => {
|
|
|
93
103
|
});
|
|
94
104
|
it('should error out if the iframe sends an error message', (done) => {
|
|
95
105
|
var _a;
|
|
96
|
-
jest
|
|
106
|
+
jest
|
|
107
|
+
.spyOn((_a = mpc.iframe) === null || _a === void 0 ? void 0 : _a.contentWindow, 'postMessage')
|
|
97
108
|
.mockImplementationOnce((message, origin) => {
|
|
98
109
|
const { type, data } = message;
|
|
99
110
|
expect(type).toEqual('portal:wasm:backup');
|
|
@@ -105,15 +116,18 @@ describe('Mpc', () => {
|
|
|
105
116
|
type: 'portal:wasm:backupError',
|
|
106
117
|
data: {
|
|
107
118
|
code: 1,
|
|
108
|
-
message: 'test'
|
|
109
|
-
}
|
|
119
|
+
message: 'test',
|
|
120
|
+
},
|
|
110
121
|
},
|
|
111
122
|
}));
|
|
112
123
|
});
|
|
113
|
-
mpc
|
|
124
|
+
mpc
|
|
125
|
+
.backup(args)
|
|
126
|
+
.then(() => {
|
|
114
127
|
expect(0).toEqual(1);
|
|
115
128
|
done();
|
|
116
|
-
})
|
|
129
|
+
})
|
|
130
|
+
.catch((e) => {
|
|
117
131
|
expect(e).toBeInstanceOf(errors_1.PortalMpcError);
|
|
118
132
|
expect(e.message).toEqual('test');
|
|
119
133
|
expect(e.code).toEqual(1);
|
|
@@ -121,54 +135,63 @@ describe('Mpc', () => {
|
|
|
121
135
|
});
|
|
122
136
|
});
|
|
123
137
|
it('should error out if backupConfig is missing passswordStorage', (done) => {
|
|
124
|
-
mpc
|
|
138
|
+
mpc
|
|
139
|
+
.backup({
|
|
125
140
|
backupMethod: index_1.BackupMethods.password,
|
|
126
141
|
backupConfigs: {},
|
|
127
142
|
host: 'web.portalhq.io',
|
|
128
143
|
mpcVersion: 'v6',
|
|
129
144
|
featureFlags: {},
|
|
130
|
-
})
|
|
145
|
+
})
|
|
146
|
+
.then(() => {
|
|
131
147
|
expect(0).toEqual(1);
|
|
132
148
|
done();
|
|
133
|
-
})
|
|
149
|
+
})
|
|
150
|
+
.catch((e) => {
|
|
134
151
|
expect(e).toBeInstanceOf(Error);
|
|
135
152
|
expect(e.message).toEqual('Password storage config is required');
|
|
136
153
|
done();
|
|
137
154
|
});
|
|
138
155
|
});
|
|
139
156
|
it('should error out if passswordStorage is missing password', (done) => {
|
|
140
|
-
mpc
|
|
157
|
+
mpc
|
|
158
|
+
.backup({
|
|
141
159
|
backupMethod: index_1.BackupMethods.password,
|
|
142
160
|
backupConfigs: {
|
|
143
|
-
passwordStorage: {}
|
|
161
|
+
passwordStorage: {},
|
|
144
162
|
},
|
|
145
163
|
host: 'web.portalhq.io',
|
|
146
164
|
mpcVersion: 'v6',
|
|
147
165
|
featureFlags: {},
|
|
148
|
-
})
|
|
166
|
+
})
|
|
167
|
+
.then(() => {
|
|
149
168
|
expect(0).toEqual(1);
|
|
150
169
|
done();
|
|
151
|
-
})
|
|
170
|
+
})
|
|
171
|
+
.catch((e) => {
|
|
152
172
|
expect(e).toBeInstanceOf(Error);
|
|
153
173
|
expect(e.message).toEqual('Password is required');
|
|
154
174
|
done();
|
|
155
175
|
});
|
|
156
176
|
});
|
|
157
177
|
it('should error out if password is weak', (done) => {
|
|
158
|
-
mpc
|
|
178
|
+
mpc
|
|
179
|
+
.backup({
|
|
159
180
|
backupMethod: index_1.BackupMethods.password,
|
|
160
181
|
backupConfigs: {
|
|
161
182
|
passwordStorage: {
|
|
162
|
-
password: 'wea'
|
|
163
|
-
}
|
|
183
|
+
password: 'wea',
|
|
184
|
+
},
|
|
164
185
|
},
|
|
165
186
|
host: 'web.portalhq.io',
|
|
166
187
|
mpcVersion: 'v6',
|
|
167
188
|
featureFlags: {},
|
|
168
|
-
})
|
|
189
|
+
})
|
|
190
|
+
.then(() => {
|
|
169
191
|
expect(0).toEqual(1);
|
|
170
192
|
done();
|
|
171
|
-
})
|
|
193
|
+
})
|
|
194
|
+
.catch((e) => {
|
|
172
195
|
expect(e).toBeInstanceOf(Error);
|
|
173
196
|
expect(e.message).toEqual('Password must be at least 4 characters');
|
|
174
197
|
done();
|
|
@@ -178,7 +201,8 @@ describe('Mpc', () => {
|
|
|
178
201
|
describe('clearLocalWallet', () => {
|
|
179
202
|
it('should clear local wallet', (done) => {
|
|
180
203
|
var _a;
|
|
181
|
-
jest
|
|
204
|
+
jest
|
|
205
|
+
.spyOn((_a = mpc.iframe) === null || _a === void 0 ? void 0 : _a.contentWindow, 'postMessage')
|
|
182
206
|
.mockImplementation((message, origin) => {
|
|
183
207
|
const { type, data } = message;
|
|
184
208
|
expect(type).toEqual('portal:destroy');
|
|
@@ -191,10 +215,13 @@ describe('Mpc', () => {
|
|
|
191
215
|
},
|
|
192
216
|
}));
|
|
193
217
|
});
|
|
194
|
-
mpc
|
|
218
|
+
mpc
|
|
219
|
+
.clearLocalWallet()
|
|
220
|
+
.then((res) => {
|
|
195
221
|
expect(res).toEqual(true);
|
|
196
222
|
done();
|
|
197
|
-
})
|
|
223
|
+
})
|
|
224
|
+
.catch((_) => {
|
|
198
225
|
expect(0).toEqual(1);
|
|
199
226
|
done();
|
|
200
227
|
});
|
|
@@ -208,7 +235,8 @@ describe('Mpc', () => {
|
|
|
208
235
|
};
|
|
209
236
|
it('should successfully run generate', (done) => {
|
|
210
237
|
var _a;
|
|
211
|
-
jest
|
|
238
|
+
jest
|
|
239
|
+
.spyOn((_a = mpc.iframe) === null || _a === void 0 ? void 0 : _a.contentWindow, 'postMessage')
|
|
212
240
|
.mockImplementation((message, origin) => {
|
|
213
241
|
const { type, data } = message;
|
|
214
242
|
expect(type).toEqual('portal:wasm:generate');
|
|
@@ -220,8 +248,8 @@ describe('Mpc', () => {
|
|
|
220
248
|
type: 'portal:wasm:generateProgress',
|
|
221
249
|
data: {
|
|
222
250
|
status: index_1.MpcStatuses.StoringShare,
|
|
223
|
-
done: false
|
|
224
|
-
}
|
|
251
|
+
done: false,
|
|
252
|
+
},
|
|
225
253
|
},
|
|
226
254
|
}));
|
|
227
255
|
window.dispatchEvent(new MessageEvent('message', {
|
|
@@ -230,26 +258,33 @@ describe('Mpc', () => {
|
|
|
230
258
|
type: 'portal:wasm:generateProgress',
|
|
231
259
|
data: {
|
|
232
260
|
status: index_1.MpcStatuses.Done,
|
|
233
|
-
done: true
|
|
234
|
-
}
|
|
261
|
+
done: true,
|
|
262
|
+
},
|
|
235
263
|
},
|
|
236
264
|
}));
|
|
237
265
|
window.dispatchEvent(new MessageEvent('message', {
|
|
238
266
|
origin: mockHostOrigin,
|
|
239
267
|
data: {
|
|
240
268
|
type: 'portal:wasm:generateResult',
|
|
241
|
-
data: constants_1.mockAddress
|
|
269
|
+
data: constants_1.mockAddress,
|
|
242
270
|
},
|
|
243
271
|
}));
|
|
244
272
|
});
|
|
245
273
|
const progressMock = jest.fn();
|
|
246
|
-
mpc
|
|
274
|
+
mpc
|
|
275
|
+
.generate(args, progressMock)
|
|
276
|
+
.then((res) => {
|
|
247
277
|
expect(res).toEqual(constants_1.mockAddress);
|
|
248
278
|
expect(progressMock).toHaveBeenCalledTimes(2);
|
|
249
|
-
expect(progressMock.mock.calls[0]).toEqual([
|
|
250
|
-
|
|
251
|
-
|
|
252
|
-
|
|
279
|
+
expect(progressMock.mock.calls[0]).toEqual([
|
|
280
|
+
{ status: index_1.MpcStatuses.StoringShare, done: false },
|
|
281
|
+
]);
|
|
282
|
+
expect(progressMock.mock.calls[1]).toEqual([
|
|
283
|
+
{ status: index_1.MpcStatuses.Done, done: true },
|
|
284
|
+
]);
|
|
285
|
+
done();
|
|
286
|
+
})
|
|
287
|
+
.catch((e) => {
|
|
253
288
|
console.error(e);
|
|
254
289
|
expect(0).toEqual(1);
|
|
255
290
|
done();
|
|
@@ -257,7 +292,8 @@ describe('Mpc', () => {
|
|
|
257
292
|
});
|
|
258
293
|
it('should error out if the iframe sends an error message', (done) => {
|
|
259
294
|
var _a;
|
|
260
|
-
jest
|
|
295
|
+
jest
|
|
296
|
+
.spyOn((_a = mpc.iframe) === null || _a === void 0 ? void 0 : _a.contentWindow, 'postMessage')
|
|
261
297
|
.mockImplementationOnce((message, origin) => {
|
|
262
298
|
const { type, data } = message;
|
|
263
299
|
expect(type).toEqual('portal:wasm:generate');
|
|
@@ -269,15 +305,18 @@ describe('Mpc', () => {
|
|
|
269
305
|
type: 'portal:wasm:generateError',
|
|
270
306
|
data: {
|
|
271
307
|
code: 1,
|
|
272
|
-
message: 'test'
|
|
273
|
-
}
|
|
308
|
+
message: 'test',
|
|
309
|
+
},
|
|
274
310
|
},
|
|
275
311
|
}));
|
|
276
312
|
});
|
|
277
|
-
mpc
|
|
313
|
+
mpc
|
|
314
|
+
.generate(args)
|
|
315
|
+
.then(() => {
|
|
278
316
|
expect(0).toEqual(1);
|
|
279
317
|
done();
|
|
280
|
-
})
|
|
318
|
+
})
|
|
319
|
+
.catch((e) => {
|
|
281
320
|
expect(e).toBeInstanceOf(errors_1.PortalMpcError);
|
|
282
321
|
expect(e.message).toEqual('test');
|
|
283
322
|
expect(e.code).toEqual(1);
|
|
@@ -288,7 +327,8 @@ describe('Mpc', () => {
|
|
|
288
327
|
describe('getAddress', () => {
|
|
289
328
|
it('should successfully get address', (done) => {
|
|
290
329
|
var _a;
|
|
291
|
-
jest
|
|
330
|
+
jest
|
|
331
|
+
.spyOn((_a = mpc.iframe) === null || _a === void 0 ? void 0 : _a.contentWindow, 'postMessage')
|
|
292
332
|
.mockImplementation((message, origin) => {
|
|
293
333
|
const { type, data } = message;
|
|
294
334
|
expect(type).toEqual('portal:address');
|
|
@@ -298,14 +338,17 @@ describe('Mpc', () => {
|
|
|
298
338
|
origin: mockHostOrigin,
|
|
299
339
|
data: {
|
|
300
340
|
type: 'portal:addressResult',
|
|
301
|
-
data: constants_1.mockAddress
|
|
341
|
+
data: constants_1.mockAddress,
|
|
302
342
|
},
|
|
303
343
|
}));
|
|
304
344
|
});
|
|
305
|
-
mpc
|
|
345
|
+
mpc
|
|
346
|
+
.getAddress()
|
|
347
|
+
.then((res) => {
|
|
306
348
|
expect(res).toEqual(constants_1.mockAddress);
|
|
307
349
|
done();
|
|
308
|
-
})
|
|
350
|
+
})
|
|
351
|
+
.catch((_) => {
|
|
309
352
|
expect(0).toEqual(1);
|
|
310
353
|
done();
|
|
311
354
|
});
|
|
@@ -322,7 +365,8 @@ describe('Mpc', () => {
|
|
|
322
365
|
};
|
|
323
366
|
it('should successfully run recover', (done) => {
|
|
324
367
|
var _a;
|
|
325
|
-
jest
|
|
368
|
+
jest
|
|
369
|
+
.spyOn((_a = mpc.iframe) === null || _a === void 0 ? void 0 : _a.contentWindow, 'postMessage')
|
|
326
370
|
.mockImplementation((message, origin) => {
|
|
327
371
|
const { type, data } = message;
|
|
328
372
|
expect(type).toEqual('portal:wasm:recover');
|
|
@@ -334,8 +378,8 @@ describe('Mpc', () => {
|
|
|
334
378
|
type: 'portal:wasm:recoverProgress',
|
|
335
379
|
data: {
|
|
336
380
|
status: index_1.MpcStatuses.ReadingShare,
|
|
337
|
-
done: false
|
|
338
|
-
}
|
|
381
|
+
done: false,
|
|
382
|
+
},
|
|
339
383
|
},
|
|
340
384
|
}));
|
|
341
385
|
window.dispatchEvent(new MessageEvent('message', {
|
|
@@ -344,8 +388,8 @@ describe('Mpc', () => {
|
|
|
344
388
|
type: 'portal:wasm:recoverProgress',
|
|
345
389
|
data: {
|
|
346
390
|
status: index_1.MpcStatuses.StoringShare,
|
|
347
|
-
done: false
|
|
348
|
-
}
|
|
391
|
+
done: false,
|
|
392
|
+
},
|
|
349
393
|
},
|
|
350
394
|
}));
|
|
351
395
|
window.dispatchEvent(new MessageEvent('message', {
|
|
@@ -354,27 +398,36 @@ describe('Mpc', () => {
|
|
|
354
398
|
type: 'portal:wasm:recoverProgress',
|
|
355
399
|
data: {
|
|
356
400
|
status: index_1.MpcStatuses.Done,
|
|
357
|
-
done: true
|
|
358
|
-
}
|
|
401
|
+
done: true,
|
|
402
|
+
},
|
|
359
403
|
},
|
|
360
404
|
}));
|
|
361
405
|
window.dispatchEvent(new MessageEvent('message', {
|
|
362
406
|
origin: mockHostOrigin,
|
|
363
407
|
data: {
|
|
364
408
|
type: 'portal:wasm:recoverResult',
|
|
365
|
-
data: constants_1.mockAddress
|
|
409
|
+
data: constants_1.mockAddress,
|
|
366
410
|
},
|
|
367
411
|
}));
|
|
368
412
|
});
|
|
369
413
|
const progressMock = jest.fn();
|
|
370
|
-
mpc
|
|
414
|
+
mpc
|
|
415
|
+
.recover(args, progressMock)
|
|
416
|
+
.then((res) => {
|
|
371
417
|
expect(res).toEqual(constants_1.mockAddress);
|
|
372
418
|
expect(progressMock).toHaveBeenCalledTimes(3);
|
|
373
|
-
expect(progressMock.mock.calls[0]).toEqual([
|
|
374
|
-
|
|
375
|
-
|
|
376
|
-
|
|
377
|
-
|
|
419
|
+
expect(progressMock.mock.calls[0]).toEqual([
|
|
420
|
+
{ status: index_1.MpcStatuses.ReadingShare, done: false },
|
|
421
|
+
]);
|
|
422
|
+
expect(progressMock.mock.calls[1]).toEqual([
|
|
423
|
+
{ status: index_1.MpcStatuses.StoringShare, done: false },
|
|
424
|
+
]);
|
|
425
|
+
expect(progressMock.mock.calls[2]).toEqual([
|
|
426
|
+
{ status: index_1.MpcStatuses.Done, done: true },
|
|
427
|
+
]);
|
|
428
|
+
done();
|
|
429
|
+
})
|
|
430
|
+
.catch((e) => {
|
|
378
431
|
console.error(e);
|
|
379
432
|
expect(0).toEqual(1);
|
|
380
433
|
done();
|
|
@@ -382,7 +435,8 @@ describe('Mpc', () => {
|
|
|
382
435
|
});
|
|
383
436
|
it('should error out if the iframe sends an error message', (done) => {
|
|
384
437
|
var _a;
|
|
385
|
-
jest
|
|
438
|
+
jest
|
|
439
|
+
.spyOn((_a = mpc.iframe) === null || _a === void 0 ? void 0 : _a.contentWindow, 'postMessage')
|
|
386
440
|
.mockImplementationOnce((message, origin) => {
|
|
387
441
|
const { type, data } = message;
|
|
388
442
|
expect(type).toEqual('portal:wasm:recover');
|
|
@@ -394,15 +448,18 @@ describe('Mpc', () => {
|
|
|
394
448
|
type: 'portal:wasm:recoverError',
|
|
395
449
|
data: {
|
|
396
450
|
code: 1,
|
|
397
|
-
message: 'test'
|
|
398
|
-
}
|
|
451
|
+
message: 'test',
|
|
452
|
+
},
|
|
399
453
|
},
|
|
400
454
|
}));
|
|
401
455
|
});
|
|
402
|
-
mpc
|
|
456
|
+
mpc
|
|
457
|
+
.recover(args)
|
|
458
|
+
.then(() => {
|
|
403
459
|
expect(0).toEqual(1);
|
|
404
460
|
done();
|
|
405
|
-
})
|
|
461
|
+
})
|
|
462
|
+
.catch((e) => {
|
|
406
463
|
expect(e).toBeInstanceOf(errors_1.PortalMpcError);
|
|
407
464
|
expect(e.message).toEqual('test');
|
|
408
465
|
expect(e.code).toEqual(1);
|
|
@@ -418,11 +475,12 @@ describe('Mpc', () => {
|
|
|
418
475
|
host: 'web.portalhq.io',
|
|
419
476
|
mpcVersion: 'v6',
|
|
420
477
|
featureFlags: {},
|
|
421
|
-
organizationBackupShare: 'test'
|
|
478
|
+
organizationBackupShare: 'test',
|
|
422
479
|
};
|
|
423
480
|
it('should successfully eject the wallet', (done) => {
|
|
424
481
|
var _a;
|
|
425
|
-
jest
|
|
482
|
+
jest
|
|
483
|
+
.spyOn((_a = mpc.iframe) === null || _a === void 0 ? void 0 : _a.contentWindow, 'postMessage')
|
|
426
484
|
.mockImplementation((message, origin) => {
|
|
427
485
|
const { type, data } = message;
|
|
428
486
|
expect(type).toEqual('portal:wasm:eject');
|
|
@@ -432,21 +490,25 @@ describe('Mpc', () => {
|
|
|
432
490
|
origin: mockHostOrigin,
|
|
433
491
|
data: {
|
|
434
492
|
type: 'portal:wasm:ejectResult',
|
|
435
|
-
data: constants_1.mockEjectResult
|
|
493
|
+
data: constants_1.mockEjectResult,
|
|
436
494
|
},
|
|
437
495
|
}));
|
|
438
496
|
});
|
|
439
|
-
mpc
|
|
497
|
+
mpc
|
|
498
|
+
.eject(args)
|
|
499
|
+
.then((res) => {
|
|
440
500
|
expect(res).toEqual(constants_1.mockEjectResult);
|
|
441
501
|
done();
|
|
442
|
-
})
|
|
502
|
+
})
|
|
503
|
+
.catch((_) => {
|
|
443
504
|
expect(0).toEqual(1);
|
|
444
505
|
done();
|
|
445
506
|
});
|
|
446
507
|
});
|
|
447
508
|
it('should error out if the iframe sends an error message', (done) => {
|
|
448
509
|
var _a;
|
|
449
|
-
jest
|
|
510
|
+
jest
|
|
511
|
+
.spyOn((_a = mpc.iframe) === null || _a === void 0 ? void 0 : _a.contentWindow, 'postMessage')
|
|
450
512
|
.mockImplementationOnce((message, origin) => {
|
|
451
513
|
const { type, data } = message;
|
|
452
514
|
expect(type).toEqual('portal:wasm:eject');
|
|
@@ -458,15 +520,90 @@ describe('Mpc', () => {
|
|
|
458
520
|
type: 'portal:wasm:ejectError',
|
|
459
521
|
data: {
|
|
460
522
|
code: 1,
|
|
461
|
-
message: 'test'
|
|
462
|
-
}
|
|
523
|
+
message: 'test',
|
|
524
|
+
},
|
|
525
|
+
},
|
|
526
|
+
}));
|
|
527
|
+
});
|
|
528
|
+
mpc
|
|
529
|
+
.eject(args)
|
|
530
|
+
.then(() => {
|
|
531
|
+
expect(0).toEqual(1);
|
|
532
|
+
done();
|
|
533
|
+
})
|
|
534
|
+
.catch((e) => {
|
|
535
|
+
expect(e).toBeInstanceOf(errors_1.PortalMpcError);
|
|
536
|
+
expect(e.message).toEqual('test');
|
|
537
|
+
expect(e.code).toEqual(1);
|
|
538
|
+
done();
|
|
539
|
+
});
|
|
540
|
+
});
|
|
541
|
+
});
|
|
542
|
+
describe('ejectPrivateKeys', () => {
|
|
543
|
+
const args = {
|
|
544
|
+
backupMethod: index_1.BackupMethods.password,
|
|
545
|
+
backupConfigs: constants_1.mockBackupConfig,
|
|
546
|
+
cipherText: constants_1.mockCipherText,
|
|
547
|
+
host: 'web.portalhq.io',
|
|
548
|
+
mpcVersion: 'v6',
|
|
549
|
+
featureFlags: {},
|
|
550
|
+
organizationBackupShares: constants_1.mockOrgBackupShares,
|
|
551
|
+
};
|
|
552
|
+
it('should successfully eject the wallet', (done) => {
|
|
553
|
+
var _a;
|
|
554
|
+
jest
|
|
555
|
+
.spyOn((_a = mpc.iframe) === null || _a === void 0 ? void 0 : _a.contentWindow, 'postMessage')
|
|
556
|
+
.mockImplementation((message, origin) => {
|
|
557
|
+
const { type, data } = message;
|
|
558
|
+
expect(type).toEqual('portal:wasm:ejectPrivateKeys');
|
|
559
|
+
expect(data).toEqual(args);
|
|
560
|
+
expect(origin).toEqual(mockHostOrigin);
|
|
561
|
+
window.dispatchEvent(new MessageEvent('message', {
|
|
562
|
+
origin: mockHostOrigin,
|
|
563
|
+
data: {
|
|
564
|
+
type: 'portal:wasm:ejectPrivateKeysResult',
|
|
565
|
+
data: constants_1.mockEjectPrivateKeysResult,
|
|
566
|
+
},
|
|
567
|
+
}));
|
|
568
|
+
});
|
|
569
|
+
mpc
|
|
570
|
+
.ejectPrivateKeys(args)
|
|
571
|
+
.then((res) => {
|
|
572
|
+
expect(res).toEqual(constants_1.mockEjectPrivateKeysResult);
|
|
573
|
+
done();
|
|
574
|
+
})
|
|
575
|
+
.catch((_) => {
|
|
576
|
+
expect(0).toEqual(1);
|
|
577
|
+
done();
|
|
578
|
+
});
|
|
579
|
+
});
|
|
580
|
+
it('should error out if the iframe sends an error message', (done) => {
|
|
581
|
+
var _a;
|
|
582
|
+
jest
|
|
583
|
+
.spyOn((_a = mpc.iframe) === null || _a === void 0 ? void 0 : _a.contentWindow, 'postMessage')
|
|
584
|
+
.mockImplementationOnce((message, origin) => {
|
|
585
|
+
const { type, data } = message;
|
|
586
|
+
expect(type).toEqual('portal:wasm:ejectPrivateKeys');
|
|
587
|
+
expect(data).toEqual(args);
|
|
588
|
+
expect(origin).toEqual(mockHostOrigin);
|
|
589
|
+
window.dispatchEvent(new MessageEvent('message', {
|
|
590
|
+
origin: mockHostOrigin,
|
|
591
|
+
data: {
|
|
592
|
+
type: 'portal:wasm:ejectPrivateKeysError',
|
|
593
|
+
data: {
|
|
594
|
+
code: 1,
|
|
595
|
+
message: 'test',
|
|
596
|
+
},
|
|
463
597
|
},
|
|
464
598
|
}));
|
|
465
599
|
});
|
|
466
|
-
mpc
|
|
600
|
+
mpc
|
|
601
|
+
.ejectPrivateKeys(args)
|
|
602
|
+
.then(() => {
|
|
467
603
|
expect(0).toEqual(1);
|
|
468
604
|
done();
|
|
469
|
-
})
|
|
605
|
+
})
|
|
606
|
+
.catch((e) => {
|
|
470
607
|
expect(e).toBeInstanceOf(errors_1.PortalMpcError);
|
|
471
608
|
expect(e.message).toEqual('test');
|
|
472
609
|
expect(e.code).toEqual(1);
|
|
@@ -476,11 +613,13 @@ describe('Mpc', () => {
|
|
|
476
613
|
});
|
|
477
614
|
describe('rawSign', () => {
|
|
478
615
|
const args = {
|
|
479
|
-
curve: index_1.PortalCurve.SECP256K1,
|
|
616
|
+
curve: index_1.PortalCurve.SECP256K1,
|
|
617
|
+
param: 'test',
|
|
480
618
|
};
|
|
481
619
|
it('should successfully raW sign', (done) => {
|
|
482
620
|
var _a;
|
|
483
|
-
jest
|
|
621
|
+
jest
|
|
622
|
+
.spyOn((_a = mpc.iframe) === null || _a === void 0 ? void 0 : _a.contentWindow, 'postMessage')
|
|
484
623
|
.mockImplementation((message, origin) => {
|
|
485
624
|
const { type, data } = message;
|
|
486
625
|
expect(type).toEqual('portal:mpc:rawSign');
|
|
@@ -490,21 +629,25 @@ describe('Mpc', () => {
|
|
|
490
629
|
origin: mockHostOrigin,
|
|
491
630
|
data: {
|
|
492
631
|
type: 'portal:mpc:rawSignResult',
|
|
493
|
-
data: 'test'
|
|
632
|
+
data: 'test',
|
|
494
633
|
},
|
|
495
634
|
}));
|
|
496
635
|
});
|
|
497
|
-
mpc
|
|
636
|
+
mpc
|
|
637
|
+
.rawSign(args.curve, args.param)
|
|
638
|
+
.then((res) => {
|
|
498
639
|
expect(res).toEqual('test');
|
|
499
640
|
done();
|
|
500
|
-
})
|
|
641
|
+
})
|
|
642
|
+
.catch((_) => {
|
|
501
643
|
expect(0).toEqual(1);
|
|
502
644
|
done();
|
|
503
645
|
});
|
|
504
646
|
});
|
|
505
647
|
it('should error out if the iframe sends an error message', (done) => {
|
|
506
648
|
var _a;
|
|
507
|
-
jest
|
|
649
|
+
jest
|
|
650
|
+
.spyOn((_a = mpc.iframe) === null || _a === void 0 ? void 0 : _a.contentWindow, 'postMessage')
|
|
508
651
|
.mockImplementationOnce((message, origin) => {
|
|
509
652
|
const { type, data } = message;
|
|
510
653
|
expect(type).toEqual('portal:mpc:rawSign');
|
|
@@ -516,15 +659,18 @@ describe('Mpc', () => {
|
|
|
516
659
|
type: 'portal:mpc:rawSignError',
|
|
517
660
|
data: {
|
|
518
661
|
code: 1,
|
|
519
|
-
message: 'test'
|
|
520
|
-
}
|
|
662
|
+
message: 'test',
|
|
663
|
+
},
|
|
521
664
|
},
|
|
522
665
|
}));
|
|
523
666
|
});
|
|
524
|
-
mpc
|
|
667
|
+
mpc
|
|
668
|
+
.rawSign(args.curve, args.param)
|
|
669
|
+
.then(() => {
|
|
525
670
|
expect(0).toEqual(1);
|
|
526
671
|
done();
|
|
527
|
-
})
|
|
672
|
+
})
|
|
673
|
+
.catch((e) => {
|
|
528
674
|
expect(e).toBeInstanceOf(errors_1.PortalMpcError);
|
|
529
675
|
expect(e.message).toEqual('test');
|
|
530
676
|
expect(e.code).toEqual(1);
|
|
@@ -537,11 +683,12 @@ describe('Mpc', () => {
|
|
|
537
683
|
chainId: 'test',
|
|
538
684
|
method: 'test',
|
|
539
685
|
params: 'test',
|
|
540
|
-
rpcUrl: constants_1.mockRpcUrl
|
|
686
|
+
rpcUrl: constants_1.mockRpcUrl,
|
|
541
687
|
};
|
|
542
688
|
it('should successfully run sign', (done) => {
|
|
543
689
|
var _a;
|
|
544
|
-
jest
|
|
690
|
+
jest
|
|
691
|
+
.spyOn((_a = mpc.iframe) === null || _a === void 0 ? void 0 : _a.contentWindow, 'postMessage')
|
|
545
692
|
.mockImplementation((message, origin) => {
|
|
546
693
|
const { type, data } = message;
|
|
547
694
|
expect(type).toEqual('portal:wasm:sign');
|
|
@@ -551,14 +698,17 @@ describe('Mpc', () => {
|
|
|
551
698
|
origin: mockHostOrigin,
|
|
552
699
|
data: {
|
|
553
700
|
type: 'portal:wasm:signResult',
|
|
554
|
-
data: 'test'
|
|
701
|
+
data: 'test',
|
|
555
702
|
},
|
|
556
703
|
}));
|
|
557
704
|
});
|
|
558
|
-
mpc
|
|
705
|
+
mpc
|
|
706
|
+
.sign(args)
|
|
707
|
+
.then((res) => {
|
|
559
708
|
expect(res).toEqual('test');
|
|
560
709
|
done();
|
|
561
|
-
})
|
|
710
|
+
})
|
|
711
|
+
.catch((e) => {
|
|
562
712
|
console.error(e);
|
|
563
713
|
expect(0).toEqual(1);
|
|
564
714
|
done();
|
|
@@ -566,7 +716,8 @@ describe('Mpc', () => {
|
|
|
566
716
|
});
|
|
567
717
|
it('should error out if the iframe sends an error message', (done) => {
|
|
568
718
|
var _a;
|
|
569
|
-
jest
|
|
719
|
+
jest
|
|
720
|
+
.spyOn((_a = mpc.iframe) === null || _a === void 0 ? void 0 : _a.contentWindow, 'postMessage')
|
|
570
721
|
.mockImplementationOnce((message, origin) => {
|
|
571
722
|
const { type, data } = message;
|
|
572
723
|
expect(type).toEqual('portal:wasm:sign');
|
|
@@ -578,15 +729,18 @@ describe('Mpc', () => {
|
|
|
578
729
|
type: 'portal:wasm:signError',
|
|
579
730
|
data: {
|
|
580
731
|
code: 1,
|
|
581
|
-
message: 'test'
|
|
582
|
-
}
|
|
732
|
+
message: 'test',
|
|
733
|
+
},
|
|
583
734
|
},
|
|
584
735
|
}));
|
|
585
736
|
});
|
|
586
|
-
mpc
|
|
737
|
+
mpc
|
|
738
|
+
.sign(args)
|
|
739
|
+
.then(() => {
|
|
587
740
|
expect(0).toEqual(1);
|
|
588
741
|
done();
|
|
589
|
-
})
|
|
742
|
+
})
|
|
743
|
+
.catch((e) => {
|
|
590
744
|
expect(e).toBeInstanceOf(errors_1.PortalMpcError);
|
|
591
745
|
expect(e.message).toEqual('test');
|
|
592
746
|
expect(e.code).toEqual(1);
|
|
@@ -597,7 +751,8 @@ describe('Mpc', () => {
|
|
|
597
751
|
describe('checkSharesOnDevice', () => {
|
|
598
752
|
it('should successfully return the shares on device', (done) => {
|
|
599
753
|
var _a;
|
|
600
|
-
jest
|
|
754
|
+
jest
|
|
755
|
+
.spyOn((_a = mpc.iframe) === null || _a === void 0 ? void 0 : _a.contentWindow, 'postMessage')
|
|
601
756
|
.mockImplementation((message, origin) => {
|
|
602
757
|
const { type, data } = message;
|
|
603
758
|
expect(type).toEqual('portal:checkSharesOnDevice');
|
|
@@ -607,21 +762,25 @@ describe('Mpc', () => {
|
|
|
607
762
|
origin: mockHostOrigin,
|
|
608
763
|
data: {
|
|
609
764
|
type: 'portal:checkSharesOnDeviceResult',
|
|
610
|
-
data: constants_1.mockSharesOnDevice
|
|
765
|
+
data: constants_1.mockSharesOnDevice,
|
|
611
766
|
},
|
|
612
767
|
}));
|
|
613
768
|
});
|
|
614
|
-
mpc
|
|
769
|
+
mpc
|
|
770
|
+
.checkSharesOnDevice()
|
|
771
|
+
.then((res) => {
|
|
615
772
|
expect(res).toEqual(constants_1.mockSharesOnDevice);
|
|
616
773
|
done();
|
|
617
|
-
})
|
|
774
|
+
})
|
|
775
|
+
.catch((_) => {
|
|
618
776
|
expect(0).toEqual(1);
|
|
619
777
|
done();
|
|
620
778
|
});
|
|
621
779
|
});
|
|
622
780
|
it('should error out if the iframe sends an error message', (done) => {
|
|
623
781
|
var _a;
|
|
624
|
-
jest
|
|
782
|
+
jest
|
|
783
|
+
.spyOn((_a = mpc.iframe) === null || _a === void 0 ? void 0 : _a.contentWindow, 'postMessage')
|
|
625
784
|
.mockImplementationOnce((message, origin) => {
|
|
626
785
|
const { type, data } = message;
|
|
627
786
|
expect(type).toEqual('portal:checkSharesOnDevice');
|
|
@@ -633,15 +792,18 @@ describe('Mpc', () => {
|
|
|
633
792
|
type: 'portal:checkSharesOnDeviceError',
|
|
634
793
|
data: {
|
|
635
794
|
code: 1,
|
|
636
|
-
message: 'test'
|
|
637
|
-
}
|
|
795
|
+
message: 'test',
|
|
796
|
+
},
|
|
638
797
|
},
|
|
639
798
|
}));
|
|
640
799
|
});
|
|
641
|
-
mpc
|
|
800
|
+
mpc
|
|
801
|
+
.checkSharesOnDevice()
|
|
802
|
+
.then(() => {
|
|
642
803
|
expect(0).toEqual(1);
|
|
643
804
|
done();
|
|
644
|
-
})
|
|
805
|
+
})
|
|
806
|
+
.catch((e) => {
|
|
645
807
|
expect(e).toBeInstanceOf(errors_1.PortalMpcError);
|
|
646
808
|
expect(e.message).toEqual('test');
|
|
647
809
|
expect(e.code).toEqual(1);
|
|
@@ -654,7 +816,8 @@ describe('Mpc', () => {
|
|
|
654
816
|
const res = constants_1.mockBalances;
|
|
655
817
|
it('should successfully return the balances', (done) => {
|
|
656
818
|
var _a;
|
|
657
|
-
jest
|
|
819
|
+
jest
|
|
820
|
+
.spyOn((_a = mpc.iframe) === null || _a === void 0 ? void 0 : _a.contentWindow, 'postMessage')
|
|
658
821
|
.mockImplementation((message, origin) => {
|
|
659
822
|
const { type, data } = message;
|
|
660
823
|
expect(type).toEqual('portal:getBalances');
|
|
@@ -664,21 +827,25 @@ describe('Mpc', () => {
|
|
|
664
827
|
origin: mockHostOrigin,
|
|
665
828
|
data: {
|
|
666
829
|
type: 'portal:getBalancesResult',
|
|
667
|
-
data: res
|
|
830
|
+
data: res,
|
|
668
831
|
},
|
|
669
832
|
}));
|
|
670
833
|
});
|
|
671
|
-
mpc
|
|
834
|
+
mpc
|
|
835
|
+
.getBalances(...args)
|
|
836
|
+
.then((data) => {
|
|
672
837
|
expect(data).toEqual(res);
|
|
673
838
|
done();
|
|
674
|
-
})
|
|
839
|
+
})
|
|
840
|
+
.catch((_) => {
|
|
675
841
|
expect(0).toEqual(1);
|
|
676
842
|
done();
|
|
677
843
|
});
|
|
678
844
|
});
|
|
679
845
|
it('should error out if the iframe sends an error message', (done) => {
|
|
680
846
|
var _a;
|
|
681
|
-
jest
|
|
847
|
+
jest
|
|
848
|
+
.spyOn((_a = mpc.iframe) === null || _a === void 0 ? void 0 : _a.contentWindow, 'postMessage')
|
|
682
849
|
.mockImplementationOnce((message, origin) => {
|
|
683
850
|
const { type, data } = message;
|
|
684
851
|
expect(type).toEqual('portal:getBalances');
|
|
@@ -690,15 +857,18 @@ describe('Mpc', () => {
|
|
|
690
857
|
type: 'portal:getBalancesError',
|
|
691
858
|
data: {
|
|
692
859
|
code: 1,
|
|
693
|
-
message: 'test'
|
|
694
|
-
}
|
|
860
|
+
message: 'test',
|
|
861
|
+
},
|
|
695
862
|
},
|
|
696
863
|
}));
|
|
697
864
|
});
|
|
698
|
-
mpc
|
|
865
|
+
mpc
|
|
866
|
+
.getBalances(...args)
|
|
867
|
+
.then(() => {
|
|
699
868
|
expect(0).toEqual(1);
|
|
700
869
|
done();
|
|
701
|
-
})
|
|
870
|
+
})
|
|
871
|
+
.catch((e) => {
|
|
702
872
|
expect(e).toBeInstanceOf(errors_1.PortalMpcError);
|
|
703
873
|
expect(e.message).toEqual('test');
|
|
704
874
|
expect(e.code).toEqual(1);
|
|
@@ -710,7 +880,8 @@ describe('Mpc', () => {
|
|
|
710
880
|
const res = constants_1.mockClientResponse;
|
|
711
881
|
it('should successfully return the client', (done) => {
|
|
712
882
|
var _a;
|
|
713
|
-
jest
|
|
883
|
+
jest
|
|
884
|
+
.spyOn((_a = mpc.iframe) === null || _a === void 0 ? void 0 : _a.contentWindow, 'postMessage')
|
|
714
885
|
.mockImplementation((message, origin) => {
|
|
715
886
|
const { type, data } = message;
|
|
716
887
|
expect(type).toEqual('portal:getClient');
|
|
@@ -720,21 +891,25 @@ describe('Mpc', () => {
|
|
|
720
891
|
origin: mockHostOrigin,
|
|
721
892
|
data: {
|
|
722
893
|
type: 'portal:getClientResult',
|
|
723
|
-
data: res
|
|
894
|
+
data: res,
|
|
724
895
|
},
|
|
725
896
|
}));
|
|
726
897
|
});
|
|
727
|
-
mpc
|
|
898
|
+
mpc
|
|
899
|
+
.getClient()
|
|
900
|
+
.then((data) => {
|
|
728
901
|
expect(data).toEqual(res);
|
|
729
902
|
done();
|
|
730
|
-
})
|
|
903
|
+
})
|
|
904
|
+
.catch((_) => {
|
|
731
905
|
expect(0).toEqual(1);
|
|
732
906
|
done();
|
|
733
907
|
});
|
|
734
908
|
});
|
|
735
909
|
it('should error out if the iframe sends an error message', (done) => {
|
|
736
910
|
var _a;
|
|
737
|
-
jest
|
|
911
|
+
jest
|
|
912
|
+
.spyOn((_a = mpc.iframe) === null || _a === void 0 ? void 0 : _a.contentWindow, 'postMessage')
|
|
738
913
|
.mockImplementationOnce((message, origin) => {
|
|
739
914
|
const { type, data } = message;
|
|
740
915
|
expect(type).toEqual('portal:getClient');
|
|
@@ -746,15 +921,18 @@ describe('Mpc', () => {
|
|
|
746
921
|
type: 'portal:getClientError',
|
|
747
922
|
data: {
|
|
748
923
|
code: 1,
|
|
749
|
-
message: 'test'
|
|
750
|
-
}
|
|
924
|
+
message: 'test',
|
|
925
|
+
},
|
|
751
926
|
},
|
|
752
927
|
}));
|
|
753
928
|
});
|
|
754
|
-
mpc
|
|
929
|
+
mpc
|
|
930
|
+
.getClient()
|
|
931
|
+
.then(() => {
|
|
755
932
|
expect(0).toEqual(1);
|
|
756
933
|
done();
|
|
757
|
-
})
|
|
934
|
+
})
|
|
935
|
+
.catch((e) => {
|
|
758
936
|
expect(e).toBeInstanceOf(errors_1.PortalMpcError);
|
|
759
937
|
expect(e.message).toEqual('test');
|
|
760
938
|
expect(e.code).toEqual(1);
|
|
@@ -767,7 +945,8 @@ describe('Mpc', () => {
|
|
|
767
945
|
const res = constants_1.mockNFTs;
|
|
768
946
|
it('should successfully return the nfts', (done) => {
|
|
769
947
|
var _a;
|
|
770
|
-
jest
|
|
948
|
+
jest
|
|
949
|
+
.spyOn((_a = mpc.iframe) === null || _a === void 0 ? void 0 : _a.contentWindow, 'postMessage')
|
|
771
950
|
.mockImplementation((message, origin) => {
|
|
772
951
|
const { type, data } = message;
|
|
773
952
|
expect(type).toEqual('portal:getNFTs');
|
|
@@ -777,21 +956,25 @@ describe('Mpc', () => {
|
|
|
777
956
|
origin: mockHostOrigin,
|
|
778
957
|
data: {
|
|
779
958
|
type: 'portal:getNFTsResult',
|
|
780
|
-
data: res
|
|
959
|
+
data: res,
|
|
781
960
|
},
|
|
782
961
|
}));
|
|
783
962
|
});
|
|
784
|
-
mpc
|
|
963
|
+
mpc
|
|
964
|
+
.getNFTs(...args)
|
|
965
|
+
.then((data) => {
|
|
785
966
|
expect(data).toEqual(res);
|
|
786
967
|
done();
|
|
787
|
-
})
|
|
968
|
+
})
|
|
969
|
+
.catch((_) => {
|
|
788
970
|
expect(0).toEqual(1);
|
|
789
971
|
done();
|
|
790
972
|
});
|
|
791
973
|
});
|
|
792
974
|
it('should error out if the iframe sends an error message', (done) => {
|
|
793
975
|
var _a;
|
|
794
|
-
jest
|
|
976
|
+
jest
|
|
977
|
+
.spyOn((_a = mpc.iframe) === null || _a === void 0 ? void 0 : _a.contentWindow, 'postMessage')
|
|
795
978
|
.mockImplementationOnce((message, origin) => {
|
|
796
979
|
const { type, data } = message;
|
|
797
980
|
expect(type).toEqual('portal:getNFTs');
|
|
@@ -803,15 +986,18 @@ describe('Mpc', () => {
|
|
|
803
986
|
type: 'portal:getNFTsError',
|
|
804
987
|
data: {
|
|
805
988
|
code: 1,
|
|
806
|
-
message: 'test'
|
|
807
|
-
}
|
|
989
|
+
message: 'test',
|
|
990
|
+
},
|
|
808
991
|
},
|
|
809
992
|
}));
|
|
810
993
|
});
|
|
811
|
-
mpc
|
|
994
|
+
mpc
|
|
995
|
+
.getNFTs(...args)
|
|
996
|
+
.then(() => {
|
|
812
997
|
expect(0).toEqual(1);
|
|
813
998
|
done();
|
|
814
|
-
})
|
|
999
|
+
})
|
|
1000
|
+
.catch((e) => {
|
|
815
1001
|
expect(e).toBeInstanceOf(errors_1.PortalMpcError);
|
|
816
1002
|
expect(e.message).toEqual('test');
|
|
817
1003
|
expect(e.code).toEqual(1);
|
|
@@ -824,7 +1010,8 @@ describe('Mpc', () => {
|
|
|
824
1010
|
const res = constants_1.mockNFTs;
|
|
825
1011
|
it('should successfully return the nfts', (done) => {
|
|
826
1012
|
var _a;
|
|
827
|
-
jest
|
|
1013
|
+
jest
|
|
1014
|
+
.spyOn((_a = mpc.iframe) === null || _a === void 0 ? void 0 : _a.contentWindow, 'postMessage')
|
|
828
1015
|
.mockImplementation((message, origin) => {
|
|
829
1016
|
const { type, data } = message;
|
|
830
1017
|
expect(type).toEqual('portal:getNFTAssets');
|
|
@@ -834,21 +1021,25 @@ describe('Mpc', () => {
|
|
|
834
1021
|
origin: mockHostOrigin,
|
|
835
1022
|
data: {
|
|
836
1023
|
type: 'portal:getNFTAssetsResult',
|
|
837
|
-
data: res
|
|
1024
|
+
data: res,
|
|
838
1025
|
},
|
|
839
1026
|
}));
|
|
840
1027
|
});
|
|
841
|
-
mpc
|
|
1028
|
+
mpc
|
|
1029
|
+
.getNFTAssets(args[0])
|
|
1030
|
+
.then((data) => {
|
|
842
1031
|
expect(data).toEqual(res);
|
|
843
1032
|
done();
|
|
844
|
-
})
|
|
1033
|
+
})
|
|
1034
|
+
.catch((_) => {
|
|
845
1035
|
expect(0).toEqual(1);
|
|
846
1036
|
done();
|
|
847
1037
|
});
|
|
848
1038
|
});
|
|
849
1039
|
it('should error out if the iframe sends an error message', (done) => {
|
|
850
1040
|
var _a;
|
|
851
|
-
jest
|
|
1041
|
+
jest
|
|
1042
|
+
.spyOn((_a = mpc.iframe) === null || _a === void 0 ? void 0 : _a.contentWindow, 'postMessage')
|
|
852
1043
|
.mockImplementationOnce((message, origin) => {
|
|
853
1044
|
const { type, data } = message;
|
|
854
1045
|
expect(type).toEqual('portal:getNFTAssets');
|
|
@@ -860,15 +1051,18 @@ describe('Mpc', () => {
|
|
|
860
1051
|
type: 'portal:getNFTAssetsError',
|
|
861
1052
|
data: {
|
|
862
1053
|
code: 1,
|
|
863
|
-
message: 'test'
|
|
864
|
-
}
|
|
1054
|
+
message: 'test',
|
|
1055
|
+
},
|
|
865
1056
|
},
|
|
866
1057
|
}));
|
|
867
1058
|
});
|
|
868
|
-
mpc
|
|
1059
|
+
mpc
|
|
1060
|
+
.getNFTAssets(args[0])
|
|
1061
|
+
.then(() => {
|
|
869
1062
|
expect(0).toEqual(1);
|
|
870
1063
|
done();
|
|
871
|
-
})
|
|
1064
|
+
})
|
|
1065
|
+
.catch((e) => {
|
|
872
1066
|
expect(e).toBeInstanceOf(errors_1.PortalMpcError);
|
|
873
1067
|
expect(e.message).toEqual('test');
|
|
874
1068
|
expect(e.code).toEqual(1);
|
|
@@ -880,7 +1074,8 @@ describe('Mpc', () => {
|
|
|
880
1074
|
const res = constants_1.mockAssets;
|
|
881
1075
|
it('should successfully return the assets', (done) => {
|
|
882
1076
|
var _a;
|
|
883
|
-
jest
|
|
1077
|
+
jest
|
|
1078
|
+
.spyOn((_a = mpc.iframe) === null || _a === void 0 ? void 0 : _a.contentWindow, 'postMessage')
|
|
884
1079
|
.mockImplementation((message, origin) => {
|
|
885
1080
|
const { type, data } = message;
|
|
886
1081
|
expect(type).toEqual('portal:getAssets');
|
|
@@ -890,21 +1085,25 @@ describe('Mpc', () => {
|
|
|
890
1085
|
origin: mockHostOrigin,
|
|
891
1086
|
data: {
|
|
892
1087
|
type: 'portal:getAssetsResult',
|
|
893
|
-
data: res
|
|
1088
|
+
data: res,
|
|
894
1089
|
},
|
|
895
1090
|
}));
|
|
896
1091
|
});
|
|
897
|
-
mpc
|
|
1092
|
+
mpc
|
|
1093
|
+
.getAssets('eip155:1', true)
|
|
1094
|
+
.then((data) => {
|
|
898
1095
|
expect(data).toEqual(res);
|
|
899
1096
|
done();
|
|
900
|
-
})
|
|
1097
|
+
})
|
|
1098
|
+
.catch((_) => {
|
|
901
1099
|
expect(0).toEqual(1);
|
|
902
1100
|
done();
|
|
903
1101
|
});
|
|
904
1102
|
});
|
|
905
1103
|
it('should error out if the iframe sends an error message', (done) => {
|
|
906
1104
|
var _a;
|
|
907
|
-
jest
|
|
1105
|
+
jest
|
|
1106
|
+
.spyOn((_a = mpc.iframe) === null || _a === void 0 ? void 0 : _a.contentWindow, 'postMessage')
|
|
908
1107
|
.mockImplementationOnce((message, origin) => {
|
|
909
1108
|
const { type, data } = message;
|
|
910
1109
|
expect(type).toEqual('portal:getAssets');
|
|
@@ -916,15 +1115,18 @@ describe('Mpc', () => {
|
|
|
916
1115
|
type: 'portal:getAssetsError',
|
|
917
1116
|
data: {
|
|
918
1117
|
code: 1,
|
|
919
|
-
message: 'test'
|
|
920
|
-
}
|
|
1118
|
+
message: 'test',
|
|
1119
|
+
},
|
|
921
1120
|
},
|
|
922
1121
|
}));
|
|
923
1122
|
});
|
|
924
|
-
mpc
|
|
1123
|
+
mpc
|
|
1124
|
+
.getAssets('eip155:1', true)
|
|
1125
|
+
.then(() => {
|
|
925
1126
|
expect(0).toEqual(1);
|
|
926
1127
|
done();
|
|
927
|
-
})
|
|
1128
|
+
})
|
|
1129
|
+
.catch((e) => {
|
|
928
1130
|
expect(e).toBeInstanceOf(errors_1.PortalMpcError);
|
|
929
1131
|
expect(e.message).toEqual('test');
|
|
930
1132
|
expect(e.code).toEqual(1);
|
|
@@ -936,35 +1138,50 @@ describe('Mpc', () => {
|
|
|
936
1138
|
const res = constants_1.mockBuiltTransaction;
|
|
937
1139
|
it('should successfully return the built transaction', (done) => {
|
|
938
1140
|
var _a;
|
|
939
|
-
jest
|
|
1141
|
+
jest
|
|
1142
|
+
.spyOn((_a = mpc.iframe) === null || _a === void 0 ? void 0 : _a.contentWindow, 'postMessage')
|
|
940
1143
|
.mockImplementation((message, origin) => {
|
|
941
1144
|
const { type, data } = message;
|
|
942
1145
|
expect(type).toEqual('portal:buildTransaction');
|
|
943
|
-
expect(data).toEqual({
|
|
1146
|
+
expect(data).toEqual({
|
|
1147
|
+
chainId: 'eip155:1',
|
|
1148
|
+
to: constants_1.mockAddress,
|
|
1149
|
+
token: 'USDT',
|
|
1150
|
+
amount: '42',
|
|
1151
|
+
});
|
|
944
1152
|
expect(origin).toEqual(mockHostOrigin);
|
|
945
1153
|
window.dispatchEvent(new MessageEvent('message', {
|
|
946
1154
|
origin: mockHostOrigin,
|
|
947
1155
|
data: {
|
|
948
1156
|
type: 'portal:buildTransactionResult',
|
|
949
|
-
data: res
|
|
1157
|
+
data: res,
|
|
950
1158
|
},
|
|
951
1159
|
}));
|
|
952
1160
|
});
|
|
953
|
-
mpc
|
|
1161
|
+
mpc
|
|
1162
|
+
.buildTransaction('eip155:1', constants_1.mockAddress, 'USDT', '42')
|
|
1163
|
+
.then((data) => {
|
|
954
1164
|
expect(data).toEqual(res);
|
|
955
1165
|
done();
|
|
956
|
-
})
|
|
1166
|
+
})
|
|
1167
|
+
.catch((_) => {
|
|
957
1168
|
expect(0).toEqual(1);
|
|
958
1169
|
done();
|
|
959
1170
|
});
|
|
960
1171
|
});
|
|
961
1172
|
it('should error out if the iframe sends an error message', (done) => {
|
|
962
1173
|
var _a;
|
|
963
|
-
jest
|
|
1174
|
+
jest
|
|
1175
|
+
.spyOn((_a = mpc.iframe) === null || _a === void 0 ? void 0 : _a.contentWindow, 'postMessage')
|
|
964
1176
|
.mockImplementationOnce((message, origin) => {
|
|
965
1177
|
const { type, data } = message;
|
|
966
1178
|
expect(type).toEqual('portal:buildTransaction');
|
|
967
|
-
expect(data).toEqual({
|
|
1179
|
+
expect(data).toEqual({
|
|
1180
|
+
chainId: 'eip155:1',
|
|
1181
|
+
to: constants_1.mockAddress,
|
|
1182
|
+
token: 'USDT',
|
|
1183
|
+
amount: '42',
|
|
1184
|
+
});
|
|
968
1185
|
expect(origin).toEqual(mockHostOrigin);
|
|
969
1186
|
window.dispatchEvent(new MessageEvent('message', {
|
|
970
1187
|
origin: mockHostOrigin,
|
|
@@ -972,15 +1189,18 @@ describe('Mpc', () => {
|
|
|
972
1189
|
type: 'portal:buildTransactionError',
|
|
973
1190
|
data: {
|
|
974
1191
|
code: 1,
|
|
975
|
-
message: 'test'
|
|
976
|
-
}
|
|
1192
|
+
message: 'test',
|
|
1193
|
+
},
|
|
977
1194
|
},
|
|
978
1195
|
}));
|
|
979
1196
|
});
|
|
980
|
-
mpc
|
|
1197
|
+
mpc
|
|
1198
|
+
.buildTransaction('eip155:1', constants_1.mockAddress, 'USDT', '42')
|
|
1199
|
+
.then(() => {
|
|
981
1200
|
expect(0).toEqual(1);
|
|
982
1201
|
done();
|
|
983
|
-
})
|
|
1202
|
+
})
|
|
1203
|
+
.catch((e) => {
|
|
984
1204
|
expect(e).toBeInstanceOf(errors_1.PortalMpcError);
|
|
985
1205
|
expect(e.message).toEqual('test');
|
|
986
1206
|
expect(e.code).toEqual(1);
|
|
@@ -992,35 +1212,48 @@ describe('Mpc', () => {
|
|
|
992
1212
|
const res = constants_1.mockBuiltTransaction;
|
|
993
1213
|
it('should successfully return the quote', (done) => {
|
|
994
1214
|
var _a;
|
|
995
|
-
jest
|
|
1215
|
+
jest
|
|
1216
|
+
.spyOn((_a = mpc.iframe) === null || _a === void 0 ? void 0 : _a.contentWindow, 'postMessage')
|
|
996
1217
|
.mockImplementation((message, origin) => {
|
|
997
1218
|
const { type, data } = message;
|
|
998
1219
|
expect(type).toEqual('portal:swaps:getQuote');
|
|
999
|
-
expect(data).toEqual({
|
|
1220
|
+
expect(data).toEqual({
|
|
1221
|
+
apiKey: constants_1.mockApikey,
|
|
1222
|
+
args: constants_1.mockQuoteArgs,
|
|
1223
|
+
chainId: 'eip155:1',
|
|
1224
|
+
});
|
|
1000
1225
|
expect(origin).toEqual(mockHostOrigin);
|
|
1001
1226
|
window.dispatchEvent(new MessageEvent('message', {
|
|
1002
1227
|
origin: mockHostOrigin,
|
|
1003
1228
|
data: {
|
|
1004
1229
|
type: 'portal:swaps:getQuoteResult',
|
|
1005
|
-
data: res
|
|
1230
|
+
data: res,
|
|
1006
1231
|
},
|
|
1007
1232
|
}));
|
|
1008
1233
|
});
|
|
1009
|
-
mpc
|
|
1234
|
+
mpc
|
|
1235
|
+
.getQuote(constants_1.mockApikey, constants_1.mockQuoteArgs, 'eip155:1')
|
|
1236
|
+
.then((data) => {
|
|
1010
1237
|
expect(data).toEqual(res);
|
|
1011
1238
|
done();
|
|
1012
|
-
})
|
|
1239
|
+
})
|
|
1240
|
+
.catch((_) => {
|
|
1013
1241
|
expect(0).toEqual(1);
|
|
1014
1242
|
done();
|
|
1015
1243
|
});
|
|
1016
1244
|
});
|
|
1017
1245
|
it('should error out if the iframe sends an error message', (done) => {
|
|
1018
1246
|
var _a;
|
|
1019
|
-
jest
|
|
1247
|
+
jest
|
|
1248
|
+
.spyOn((_a = mpc.iframe) === null || _a === void 0 ? void 0 : _a.contentWindow, 'postMessage')
|
|
1020
1249
|
.mockImplementationOnce((message, origin) => {
|
|
1021
1250
|
const { type, data } = message;
|
|
1022
1251
|
expect(type).toEqual('portal:swaps:getQuote');
|
|
1023
|
-
expect(data).toEqual({
|
|
1252
|
+
expect(data).toEqual({
|
|
1253
|
+
apiKey: constants_1.mockApikey,
|
|
1254
|
+
args: constants_1.mockQuoteArgs,
|
|
1255
|
+
chainId: 'eip155:1',
|
|
1256
|
+
});
|
|
1024
1257
|
expect(origin).toEqual(mockHostOrigin);
|
|
1025
1258
|
window.dispatchEvent(new MessageEvent('message', {
|
|
1026
1259
|
origin: mockHostOrigin,
|
|
@@ -1028,15 +1261,18 @@ describe('Mpc', () => {
|
|
|
1028
1261
|
type: 'portal:swaps:getQuoteError',
|
|
1029
1262
|
data: {
|
|
1030
1263
|
code: 1,
|
|
1031
|
-
message: 'test'
|
|
1032
|
-
}
|
|
1264
|
+
message: 'test',
|
|
1265
|
+
},
|
|
1033
1266
|
},
|
|
1034
1267
|
}));
|
|
1035
1268
|
});
|
|
1036
|
-
mpc
|
|
1269
|
+
mpc
|
|
1270
|
+
.getQuote(constants_1.mockApikey, constants_1.mockQuoteArgs, 'eip155:1')
|
|
1271
|
+
.then(() => {
|
|
1037
1272
|
expect(0).toEqual(1);
|
|
1038
1273
|
done();
|
|
1039
|
-
})
|
|
1274
|
+
})
|
|
1275
|
+
.catch((e) => {
|
|
1040
1276
|
expect(e).toBeInstanceOf(errors_1.PortalMpcError);
|
|
1041
1277
|
expect(e.message).toEqual('test');
|
|
1042
1278
|
expect(e.code).toEqual(1);
|
|
@@ -1048,7 +1284,8 @@ describe('Mpc', () => {
|
|
|
1048
1284
|
const res = constants_1.mockBuiltTransaction;
|
|
1049
1285
|
it('should successfully return the sources', (done) => {
|
|
1050
1286
|
var _a;
|
|
1051
|
-
jest
|
|
1287
|
+
jest
|
|
1288
|
+
.spyOn((_a = mpc.iframe) === null || _a === void 0 ? void 0 : _a.contentWindow, 'postMessage')
|
|
1052
1289
|
.mockImplementation((message, origin) => {
|
|
1053
1290
|
const { type, data } = message;
|
|
1054
1291
|
expect(type).toEqual('portal:swaps:getSources');
|
|
@@ -1058,21 +1295,25 @@ describe('Mpc', () => {
|
|
|
1058
1295
|
origin: mockHostOrigin,
|
|
1059
1296
|
data: {
|
|
1060
1297
|
type: 'portal:swaps:getSourcesResult',
|
|
1061
|
-
data: res
|
|
1298
|
+
data: res,
|
|
1062
1299
|
},
|
|
1063
1300
|
}));
|
|
1064
1301
|
});
|
|
1065
|
-
mpc
|
|
1302
|
+
mpc
|
|
1303
|
+
.getSources(constants_1.mockApikey, 'eip155:1')
|
|
1304
|
+
.then((data) => {
|
|
1066
1305
|
expect(data).toEqual(res);
|
|
1067
1306
|
done();
|
|
1068
|
-
})
|
|
1307
|
+
})
|
|
1308
|
+
.catch((_) => {
|
|
1069
1309
|
expect(0).toEqual(1);
|
|
1070
1310
|
done();
|
|
1071
1311
|
});
|
|
1072
1312
|
});
|
|
1073
1313
|
it('should error out if the iframe sends an error message', (done) => {
|
|
1074
1314
|
var _a;
|
|
1075
|
-
jest
|
|
1315
|
+
jest
|
|
1316
|
+
.spyOn((_a = mpc.iframe) === null || _a === void 0 ? void 0 : _a.contentWindow, 'postMessage')
|
|
1076
1317
|
.mockImplementationOnce((message, origin) => {
|
|
1077
1318
|
const { type, data } = message;
|
|
1078
1319
|
expect(type).toEqual('portal:swaps:getSources');
|
|
@@ -1084,15 +1325,18 @@ describe('Mpc', () => {
|
|
|
1084
1325
|
type: 'portal:swaps:getSourcesError',
|
|
1085
1326
|
data: {
|
|
1086
1327
|
code: 1,
|
|
1087
|
-
message: 'test'
|
|
1088
|
-
}
|
|
1328
|
+
message: 'test',
|
|
1329
|
+
},
|
|
1089
1330
|
},
|
|
1090
1331
|
}));
|
|
1091
1332
|
});
|
|
1092
|
-
mpc
|
|
1333
|
+
mpc
|
|
1334
|
+
.getSources(constants_1.mockApikey, 'eip155:1')
|
|
1335
|
+
.then(() => {
|
|
1093
1336
|
expect(0).toEqual(1);
|
|
1094
1337
|
done();
|
|
1095
|
-
})
|
|
1338
|
+
})
|
|
1339
|
+
.catch((e) => {
|
|
1096
1340
|
expect(e).toBeInstanceOf(errors_1.PortalMpcError);
|
|
1097
1341
|
expect(e.message).toEqual('test');
|
|
1098
1342
|
expect(e.code).toEqual(1);
|
|
@@ -1104,12 +1348,14 @@ describe('Mpc', () => {
|
|
|
1104
1348
|
const res = constants_1.mockBuiltTransaction;
|
|
1105
1349
|
it('should successfully return the transactions', (done) => {
|
|
1106
1350
|
var _a;
|
|
1107
|
-
jest
|
|
1351
|
+
jest
|
|
1352
|
+
.spyOn((_a = mpc.iframe) === null || _a === void 0 ? void 0 : _a.contentWindow, 'postMessage')
|
|
1108
1353
|
.mockImplementation((message, origin) => {
|
|
1109
1354
|
const { type, data } = message;
|
|
1110
1355
|
expect(type).toEqual('portal:getTransactions');
|
|
1111
1356
|
expect(data).toEqual({
|
|
1112
|
-
chainId: 'eip155:1',
|
|
1357
|
+
chainId: 'eip155:1',
|
|
1358
|
+
limit: undefined,
|
|
1113
1359
|
offset: undefined,
|
|
1114
1360
|
order: undefined,
|
|
1115
1361
|
});
|
|
@@ -1118,26 +1364,31 @@ describe('Mpc', () => {
|
|
|
1118
1364
|
origin: mockHostOrigin,
|
|
1119
1365
|
data: {
|
|
1120
1366
|
type: 'portal:getTransactionsResult',
|
|
1121
|
-
data: res
|
|
1367
|
+
data: res,
|
|
1122
1368
|
},
|
|
1123
1369
|
}));
|
|
1124
1370
|
});
|
|
1125
|
-
mpc
|
|
1371
|
+
mpc
|
|
1372
|
+
.getTransactions('eip155:1')
|
|
1373
|
+
.then((data) => {
|
|
1126
1374
|
expect(data).toEqual(res);
|
|
1127
1375
|
done();
|
|
1128
|
-
})
|
|
1376
|
+
})
|
|
1377
|
+
.catch((_) => {
|
|
1129
1378
|
expect(0).toEqual(1);
|
|
1130
1379
|
done();
|
|
1131
1380
|
});
|
|
1132
1381
|
});
|
|
1133
1382
|
it('should error out if the iframe sends an error message', (done) => {
|
|
1134
1383
|
var _a;
|
|
1135
|
-
jest
|
|
1384
|
+
jest
|
|
1385
|
+
.spyOn((_a = mpc.iframe) === null || _a === void 0 ? void 0 : _a.contentWindow, 'postMessage')
|
|
1136
1386
|
.mockImplementationOnce((message, origin) => {
|
|
1137
1387
|
const { type, data } = message;
|
|
1138
1388
|
expect(type).toEqual('portal:getTransactions');
|
|
1139
1389
|
expect(data).toEqual({
|
|
1140
|
-
chainId: 'eip155:1',
|
|
1390
|
+
chainId: 'eip155:1',
|
|
1391
|
+
limit: undefined,
|
|
1141
1392
|
offset: undefined,
|
|
1142
1393
|
order: undefined,
|
|
1143
1394
|
});
|
|
@@ -1148,15 +1399,18 @@ describe('Mpc', () => {
|
|
|
1148
1399
|
type: 'portal:getTransactionsError',
|
|
1149
1400
|
data: {
|
|
1150
1401
|
code: 1,
|
|
1151
|
-
message: 'test'
|
|
1152
|
-
}
|
|
1402
|
+
message: 'test',
|
|
1403
|
+
},
|
|
1153
1404
|
},
|
|
1154
1405
|
}));
|
|
1155
1406
|
});
|
|
1156
|
-
mpc
|
|
1407
|
+
mpc
|
|
1408
|
+
.getTransactions('eip155:1')
|
|
1409
|
+
.then(() => {
|
|
1157
1410
|
expect(0).toEqual(1);
|
|
1158
1411
|
done();
|
|
1159
|
-
})
|
|
1412
|
+
})
|
|
1413
|
+
.catch((e) => {
|
|
1160
1414
|
expect(e).toBeInstanceOf(errors_1.PortalMpcError);
|
|
1161
1415
|
expect(e.message).toEqual('test');
|
|
1162
1416
|
expect(e.code).toEqual(1);
|
|
@@ -1168,40 +1422,45 @@ describe('Mpc', () => {
|
|
|
1168
1422
|
const res = true;
|
|
1169
1423
|
it('should successfully set the backup status', (done) => {
|
|
1170
1424
|
var _a;
|
|
1171
|
-
jest
|
|
1425
|
+
jest
|
|
1426
|
+
.spyOn((_a = mpc.iframe) === null || _a === void 0 ? void 0 : _a.contentWindow, 'postMessage')
|
|
1172
1427
|
.mockImplementation((message, origin) => {
|
|
1173
1428
|
const { type, data } = message;
|
|
1174
1429
|
expect(type).toEqual('portal:api:setBackupStatus');
|
|
1175
1430
|
expect(data).toEqual({
|
|
1176
1431
|
backupIds: constants_1.mockBackupIds,
|
|
1177
|
-
status: 'STORED_CLIENT_BACKUP_SHARE'
|
|
1432
|
+
status: 'STORED_CLIENT_BACKUP_SHARE',
|
|
1178
1433
|
});
|
|
1179
1434
|
expect(origin).toEqual(mockHostOrigin);
|
|
1180
1435
|
window.dispatchEvent(new MessageEvent('message', {
|
|
1181
1436
|
origin: mockHostOrigin,
|
|
1182
1437
|
data: {
|
|
1183
1438
|
type: 'portal:api:setBackupStatusResult',
|
|
1184
|
-
data: res
|
|
1439
|
+
data: res,
|
|
1185
1440
|
},
|
|
1186
1441
|
}));
|
|
1187
1442
|
});
|
|
1188
|
-
mpc
|
|
1443
|
+
mpc
|
|
1444
|
+
.setBackupStatus('STORED_CLIENT_BACKUP_SHARE', constants_1.mockBackupIds)
|
|
1445
|
+
.then((data) => {
|
|
1189
1446
|
expect(data).toEqual(res);
|
|
1190
1447
|
done();
|
|
1191
|
-
})
|
|
1448
|
+
})
|
|
1449
|
+
.catch((_) => {
|
|
1192
1450
|
expect(0).toEqual(1);
|
|
1193
1451
|
done();
|
|
1194
1452
|
});
|
|
1195
1453
|
});
|
|
1196
1454
|
it('should error out if the iframe sends an error message', (done) => {
|
|
1197
1455
|
var _a;
|
|
1198
|
-
jest
|
|
1456
|
+
jest
|
|
1457
|
+
.spyOn((_a = mpc.iframe) === null || _a === void 0 ? void 0 : _a.contentWindow, 'postMessage')
|
|
1199
1458
|
.mockImplementationOnce((message, origin) => {
|
|
1200
1459
|
const { type, data } = message;
|
|
1201
1460
|
expect(type).toEqual('portal:api:setBackupStatus');
|
|
1202
1461
|
expect(data).toEqual({
|
|
1203
1462
|
backupIds: constants_1.mockBackupIds,
|
|
1204
|
-
status: 'STORED_CLIENT_BACKUP_SHARE'
|
|
1463
|
+
status: 'STORED_CLIENT_BACKUP_SHARE',
|
|
1205
1464
|
});
|
|
1206
1465
|
expect(origin).toEqual(mockHostOrigin);
|
|
1207
1466
|
window.dispatchEvent(new MessageEvent('message', {
|
|
@@ -1210,15 +1469,18 @@ describe('Mpc', () => {
|
|
|
1210
1469
|
type: 'portal:api:setBackupStatusError',
|
|
1211
1470
|
data: {
|
|
1212
1471
|
code: 1,
|
|
1213
|
-
message: 'test'
|
|
1214
|
-
}
|
|
1472
|
+
message: 'test',
|
|
1473
|
+
},
|
|
1215
1474
|
},
|
|
1216
1475
|
}));
|
|
1217
1476
|
});
|
|
1218
|
-
mpc
|
|
1477
|
+
mpc
|
|
1478
|
+
.setBackupStatus('STORED_CLIENT_BACKUP_SHARE', constants_1.mockBackupIds)
|
|
1479
|
+
.then(() => {
|
|
1219
1480
|
expect(0).toEqual(1);
|
|
1220
1481
|
done();
|
|
1221
|
-
})
|
|
1482
|
+
})
|
|
1483
|
+
.catch((e) => {
|
|
1222
1484
|
expect(e).toBeInstanceOf(errors_1.PortalMpcError);
|
|
1223
1485
|
expect(e.message).toEqual('test');
|
|
1224
1486
|
expect(e.code).toEqual(1);
|
|
@@ -1230,40 +1492,45 @@ describe('Mpc', () => {
|
|
|
1230
1492
|
const res = constants_1.mockSimulationResult;
|
|
1231
1493
|
it('should successfully return the simulated transaction', (done) => {
|
|
1232
1494
|
var _a;
|
|
1233
|
-
jest
|
|
1495
|
+
jest
|
|
1496
|
+
.spyOn((_a = mpc.iframe) === null || _a === void 0 ? void 0 : _a.contentWindow, 'postMessage')
|
|
1234
1497
|
.mockImplementation((message, origin) => {
|
|
1235
1498
|
const { type, data } = message;
|
|
1236
1499
|
expect(type).toEqual('portal:simulateTransaction');
|
|
1237
1500
|
expect(data).toEqual({
|
|
1238
1501
|
chainId: 'eip155:1',
|
|
1239
|
-
transaction: constants_1.mockTransactionToSimulate
|
|
1502
|
+
transaction: constants_1.mockTransactionToSimulate,
|
|
1240
1503
|
});
|
|
1241
1504
|
expect(origin).toEqual(mockHostOrigin);
|
|
1242
1505
|
window.dispatchEvent(new MessageEvent('message', {
|
|
1243
1506
|
origin: mockHostOrigin,
|
|
1244
1507
|
data: {
|
|
1245
1508
|
type: 'portal:simulateTransactionResult',
|
|
1246
|
-
data: res
|
|
1509
|
+
data: res,
|
|
1247
1510
|
},
|
|
1248
1511
|
}));
|
|
1249
1512
|
});
|
|
1250
|
-
mpc
|
|
1513
|
+
mpc
|
|
1514
|
+
.simulateTransaction(constants_1.mockTransactionToSimulate, 'eip155:1')
|
|
1515
|
+
.then((data) => {
|
|
1251
1516
|
expect(data).toEqual(res);
|
|
1252
1517
|
done();
|
|
1253
|
-
})
|
|
1518
|
+
})
|
|
1519
|
+
.catch((_) => {
|
|
1254
1520
|
expect(0).toEqual(1);
|
|
1255
1521
|
done();
|
|
1256
1522
|
});
|
|
1257
1523
|
});
|
|
1258
1524
|
it('should error out if the iframe sends an error message', (done) => {
|
|
1259
1525
|
var _a;
|
|
1260
|
-
jest
|
|
1526
|
+
jest
|
|
1527
|
+
.spyOn((_a = mpc.iframe) === null || _a === void 0 ? void 0 : _a.contentWindow, 'postMessage')
|
|
1261
1528
|
.mockImplementationOnce((message, origin) => {
|
|
1262
1529
|
const { type, data } = message;
|
|
1263
1530
|
expect(type).toEqual('portal:simulateTransaction');
|
|
1264
1531
|
expect(data).toEqual({
|
|
1265
1532
|
chainId: 'eip155:1',
|
|
1266
|
-
transaction: constants_1.mockTransactionToSimulate
|
|
1533
|
+
transaction: constants_1.mockTransactionToSimulate,
|
|
1267
1534
|
});
|
|
1268
1535
|
expect(origin).toEqual(mockHostOrigin);
|
|
1269
1536
|
window.dispatchEvent(new MessageEvent('message', {
|
|
@@ -1272,15 +1539,18 @@ describe('Mpc', () => {
|
|
|
1272
1539
|
type: 'portal:simulateTransactionError',
|
|
1273
1540
|
data: {
|
|
1274
1541
|
code: 1,
|
|
1275
|
-
message: 'test'
|
|
1276
|
-
}
|
|
1542
|
+
message: 'test',
|
|
1543
|
+
},
|
|
1277
1544
|
},
|
|
1278
1545
|
}));
|
|
1279
1546
|
});
|
|
1280
|
-
mpc
|
|
1547
|
+
mpc
|
|
1548
|
+
.simulateTransaction(constants_1.mockTransactionToSimulate, 'eip155:1')
|
|
1549
|
+
.then(() => {
|
|
1281
1550
|
expect(0).toEqual(1);
|
|
1282
1551
|
done();
|
|
1283
|
-
})
|
|
1552
|
+
})
|
|
1553
|
+
.catch((e) => {
|
|
1284
1554
|
expect(e).toBeInstanceOf(errors_1.PortalMpcError);
|
|
1285
1555
|
expect(e.message).toEqual('test');
|
|
1286
1556
|
expect(e.code).toEqual(1);
|
|
@@ -1292,42 +1562,47 @@ describe('Mpc', () => {
|
|
|
1292
1562
|
const res = constants_1.mockEvaluationResult;
|
|
1293
1563
|
it('should successfully return the evaluated transaction', (done) => {
|
|
1294
1564
|
var _a;
|
|
1295
|
-
jest
|
|
1565
|
+
jest
|
|
1566
|
+
.spyOn((_a = mpc.iframe) === null || _a === void 0 ? void 0 : _a.contentWindow, 'postMessage')
|
|
1296
1567
|
.mockImplementation((message, origin) => {
|
|
1297
1568
|
const { type, data } = message;
|
|
1298
1569
|
expect(type).toEqual('portal:evaluateTransaction');
|
|
1299
1570
|
expect(data).toEqual({
|
|
1300
1571
|
chainId: 'eip155:1',
|
|
1301
1572
|
transaction: constants_1.mockTransactionToEvaluate,
|
|
1302
|
-
operationType: 'all'
|
|
1573
|
+
operationType: 'all',
|
|
1303
1574
|
});
|
|
1304
1575
|
expect(origin).toEqual(mockHostOrigin);
|
|
1305
1576
|
window.dispatchEvent(new MessageEvent('message', {
|
|
1306
1577
|
origin: mockHostOrigin,
|
|
1307
1578
|
data: {
|
|
1308
1579
|
type: 'portal:evaluateTransactionResult',
|
|
1309
|
-
data: res
|
|
1580
|
+
data: res,
|
|
1310
1581
|
},
|
|
1311
1582
|
}));
|
|
1312
1583
|
});
|
|
1313
|
-
mpc
|
|
1584
|
+
mpc
|
|
1585
|
+
.evaluateTransaction('eip155:1', constants_1.mockTransactionToEvaluate, 'all')
|
|
1586
|
+
.then((data) => {
|
|
1314
1587
|
expect(data).toEqual(res);
|
|
1315
1588
|
done();
|
|
1316
|
-
})
|
|
1589
|
+
})
|
|
1590
|
+
.catch((_) => {
|
|
1317
1591
|
expect(0).toEqual(1);
|
|
1318
1592
|
done();
|
|
1319
1593
|
});
|
|
1320
1594
|
});
|
|
1321
1595
|
it('should error out if the iframe sends an error message', (done) => {
|
|
1322
1596
|
var _a;
|
|
1323
|
-
jest
|
|
1597
|
+
jest
|
|
1598
|
+
.spyOn((_a = mpc.iframe) === null || _a === void 0 ? void 0 : _a.contentWindow, 'postMessage')
|
|
1324
1599
|
.mockImplementationOnce((message, origin) => {
|
|
1325
1600
|
const { type, data } = message;
|
|
1326
1601
|
expect(type).toEqual('portal:evaluateTransaction');
|
|
1327
1602
|
expect(data).toEqual({
|
|
1328
1603
|
chainId: 'eip155:1',
|
|
1329
1604
|
transaction: constants_1.mockTransactionToEvaluate,
|
|
1330
|
-
operationType: 'all'
|
|
1605
|
+
operationType: 'all',
|
|
1331
1606
|
});
|
|
1332
1607
|
expect(origin).toEqual(mockHostOrigin);
|
|
1333
1608
|
window.dispatchEvent(new MessageEvent('message', {
|
|
@@ -1336,15 +1611,18 @@ describe('Mpc', () => {
|
|
|
1336
1611
|
type: 'portal:evaluateTransactionError',
|
|
1337
1612
|
data: {
|
|
1338
1613
|
code: 1,
|
|
1339
|
-
message: 'test'
|
|
1340
|
-
}
|
|
1614
|
+
message: 'test',
|
|
1615
|
+
},
|
|
1341
1616
|
},
|
|
1342
1617
|
}));
|
|
1343
1618
|
});
|
|
1344
|
-
mpc
|
|
1619
|
+
mpc
|
|
1620
|
+
.evaluateTransaction('eip155:1', constants_1.mockTransactionToEvaluate, 'all')
|
|
1621
|
+
.then(() => {
|
|
1345
1622
|
expect(0).toEqual(1);
|
|
1346
1623
|
done();
|
|
1347
|
-
})
|
|
1624
|
+
})
|
|
1625
|
+
.catch((e) => {
|
|
1348
1626
|
expect(e).toBeInstanceOf(errors_1.PortalMpcError);
|
|
1349
1627
|
expect(e.message).toEqual('test');
|
|
1350
1628
|
expect(e.code).toEqual(1);
|
|
@@ -1355,38 +1633,45 @@ describe('Mpc', () => {
|
|
|
1355
1633
|
describe('storedClientBackupShare', () => {
|
|
1356
1634
|
it('should successfully return the stored client backup share', (done) => {
|
|
1357
1635
|
var _a;
|
|
1358
|
-
jest
|
|
1636
|
+
jest
|
|
1637
|
+
.spyOn((_a = mpc.iframe) === null || _a === void 0 ? void 0 : _a.contentWindow, 'postMessage')
|
|
1359
1638
|
.mockImplementation((message, origin) => {
|
|
1360
1639
|
const { type, data } = message;
|
|
1361
1640
|
expect(type).toEqual('portal:storedClientBackupShare');
|
|
1362
1641
|
expect(data).toEqual({
|
|
1363
|
-
success: true,
|
|
1642
|
+
success: true,
|
|
1643
|
+
backupMethod: index_1.BackupMethods.password,
|
|
1364
1644
|
});
|
|
1365
1645
|
expect(origin).toEqual(mockHostOrigin);
|
|
1366
1646
|
window.dispatchEvent(new MessageEvent('message', {
|
|
1367
1647
|
origin: mockHostOrigin,
|
|
1368
1648
|
data: {
|
|
1369
1649
|
type: 'portal:storedClientBackupShareResult',
|
|
1370
|
-
data: true
|
|
1650
|
+
data: true,
|
|
1371
1651
|
},
|
|
1372
1652
|
}));
|
|
1373
1653
|
});
|
|
1374
|
-
mpc
|
|
1654
|
+
mpc
|
|
1655
|
+
.storedClientBackupShare(true, index_1.BackupMethods.password)
|
|
1656
|
+
.then((data) => {
|
|
1375
1657
|
expect(data).toEqual(undefined);
|
|
1376
1658
|
done();
|
|
1377
|
-
})
|
|
1659
|
+
})
|
|
1660
|
+
.catch((_) => {
|
|
1378
1661
|
expect(0).toEqual(1);
|
|
1379
1662
|
done();
|
|
1380
1663
|
});
|
|
1381
1664
|
});
|
|
1382
1665
|
it('should error out if the iframe sends an error message', (done) => {
|
|
1383
1666
|
var _a;
|
|
1384
|
-
jest
|
|
1667
|
+
jest
|
|
1668
|
+
.spyOn((_a = mpc.iframe) === null || _a === void 0 ? void 0 : _a.contentWindow, 'postMessage')
|
|
1385
1669
|
.mockImplementationOnce((message, origin) => {
|
|
1386
1670
|
const { type, data } = message;
|
|
1387
1671
|
expect(type).toEqual('portal:storedClientBackupShare');
|
|
1388
1672
|
expect(data).toEqual({
|
|
1389
|
-
success: true,
|
|
1673
|
+
success: true,
|
|
1674
|
+
backupMethod: index_1.BackupMethods.password,
|
|
1390
1675
|
});
|
|
1391
1676
|
expect(origin).toEqual(mockHostOrigin);
|
|
1392
1677
|
window.dispatchEvent(new MessageEvent('message', {
|
|
@@ -1395,15 +1680,18 @@ describe('Mpc', () => {
|
|
|
1395
1680
|
type: 'portal:storedClientBackupShareError',
|
|
1396
1681
|
data: {
|
|
1397
1682
|
code: 1,
|
|
1398
|
-
message: 'test'
|
|
1399
|
-
}
|
|
1683
|
+
message: 'test',
|
|
1684
|
+
},
|
|
1400
1685
|
},
|
|
1401
1686
|
}));
|
|
1402
1687
|
});
|
|
1403
|
-
mpc
|
|
1688
|
+
mpc
|
|
1689
|
+
.storedClientBackupShare(true, index_1.BackupMethods.password)
|
|
1690
|
+
.then(() => {
|
|
1404
1691
|
expect(0).toEqual(1);
|
|
1405
1692
|
done();
|
|
1406
|
-
})
|
|
1693
|
+
})
|
|
1694
|
+
.catch((e) => {
|
|
1407
1695
|
expect(e).toBeInstanceOf(errors_1.PortalMpcError);
|
|
1408
1696
|
expect(e.message).toEqual('test');
|
|
1409
1697
|
expect(e.code).toEqual(1);
|