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