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