@portal-hq/web 3.6.2-alpha → 3.7.0
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/hypernative.d.ts +346 -0
- package/lib/commonjs/index.js +144 -2
- package/lib/commonjs/index.test.js +119 -2
- package/lib/commonjs/integrations/security/hypernative/index.js +101 -0
- package/lib/commonjs/integrations/security/hypernative/index.test.js +151 -0
- package/lib/commonjs/integrations/security/index.js +16 -0
- package/lib/commonjs/integrations/trading/zero-x/index.js +17 -4
- package/lib/commonjs/integrations/trading/zero-x/index.test.js +61 -15
- package/lib/commonjs/mpc/index.js +156 -5
- package/lib/commonjs/mpc/index.test.js +794 -5
- package/lib/commonjs/passkeys/index.js +394 -0
- package/lib/commonjs/passkeys/types.js +2 -0
- package/lib/commonjs/provider/index.js +5 -2
- package/lib/esm/index.js +144 -2
- package/lib/esm/index.test.js +119 -2
- package/lib/esm/integrations/security/hypernative/index.js +98 -0
- package/lib/esm/integrations/security/hypernative/index.test.js +146 -0
- package/lib/esm/integrations/security/index.js +10 -0
- package/lib/esm/integrations/trading/zero-x/index.js +17 -4
- package/lib/esm/integrations/trading/zero-x/index.test.js +62 -16
- package/lib/esm/mpc/index.js +156 -5
- package/lib/esm/mpc/index.test.js +795 -6
- package/lib/esm/passkeys/index.js +390 -0
- package/lib/esm/passkeys/types.js +1 -0
- package/lib/esm/provider/index.js +5 -2
- package/lifi-types.d.ts +1236 -0
- package/package.json +6 -3
- package/src/__mocks/constants.ts +422 -5
- package/src/__mocks/portal/mpc.ts +1 -0
- package/src/index.test.ts +179 -3
- package/src/index.ts +212 -4
- package/src/integrations/security/hypernative/index.test.ts +196 -0
- package/src/integrations/security/hypernative/index.ts +106 -0
- package/src/integrations/security/index.ts +14 -0
- package/src/integrations/trading/zero-x/index.test.ts +98 -19
- package/src/integrations/trading/zero-x/index.ts +29 -9
- package/src/mpc/index.test.ts +944 -7
- package/src/mpc/index.ts +200 -10
- package/src/passkeys/index.ts +536 -0
- package/src/passkeys/types.ts +78 -0
- package/src/provider/index.ts +5 -0
- package/tsconfig.json +7 -1
- package/types.d.ts +45 -12
- package/yieldxyz-types.d.ts +778 -0
- package/zero-x.d.ts +204 -0
package/src/mpc/index.test.ts
CHANGED
|
@@ -49,6 +49,27 @@ import {
|
|
|
49
49
|
mockLifiGetStatusResponse,
|
|
50
50
|
mockLifiGetRouteStepRequest,
|
|
51
51
|
mockLifiGetRouteStepResponse,
|
|
52
|
+
mockZeroExQuoteV2Request,
|
|
53
|
+
mockZeroExQuoteV2Response,
|
|
54
|
+
mockZeroExSourcesV2Request,
|
|
55
|
+
mockZeroExSourcesV2Response,
|
|
56
|
+
mockZeroExPriceRequest,
|
|
57
|
+
mockZeroExPriceResponse,
|
|
58
|
+
mockZeroExOptions,
|
|
59
|
+
mockScanAddressesRequest,
|
|
60
|
+
mockScanAddressesResponse,
|
|
61
|
+
mockScanEVMTxRequest,
|
|
62
|
+
mockScanEVMTxResponse,
|
|
63
|
+
mockScanEip712TxRequest,
|
|
64
|
+
mockScanEip712TxResponse,
|
|
65
|
+
mockScanSolanaTxRequest,
|
|
66
|
+
mockScanSolanaTxResponse,
|
|
67
|
+
mockScanNftRequest,
|
|
68
|
+
mockScanNftResponse,
|
|
69
|
+
mockScanTokenRequest,
|
|
70
|
+
mockScanTokenResponse,
|
|
71
|
+
mockScanUrlRequest,
|
|
72
|
+
mockScanUrlResponse,
|
|
52
73
|
} from '../__mocks/constants'
|
|
53
74
|
import portalMock from '../__mocks/portal/portal'
|
|
54
75
|
import { PortalMpcError } from './errors'
|
|
@@ -163,6 +184,60 @@ describe('Mpc', () => {
|
|
|
163
184
|
})
|
|
164
185
|
})
|
|
165
186
|
|
|
187
|
+
it('should include encryption key when iframe returns custom backup response', (done) => {
|
|
188
|
+
const setBackupStatusSpy = jest
|
|
189
|
+
.spyOn(mpc, 'setBackupStatus')
|
|
190
|
+
.mockResolvedValue(true as any)
|
|
191
|
+
|
|
192
|
+
jest
|
|
193
|
+
.spyOn(mpc.iframe?.contentWindow!, 'postMessage')
|
|
194
|
+
.mockImplementation((message: any, origin?) => {
|
|
195
|
+
const { type, data } = message
|
|
196
|
+
|
|
197
|
+
expect(type).toEqual('portal:wasm:backup')
|
|
198
|
+
expect(data).toEqual(args)
|
|
199
|
+
expect(origin).toEqual(mockHostOrigin)
|
|
200
|
+
|
|
201
|
+
window.dispatchEvent(
|
|
202
|
+
new MessageEvent('message', {
|
|
203
|
+
origin: mockHostOrigin,
|
|
204
|
+
data: {
|
|
205
|
+
type: 'portal:wasm:backupResult',
|
|
206
|
+
data: {
|
|
207
|
+
cipherText: mockCipherText,
|
|
208
|
+
encryptionKey: 'custom-backup-key',
|
|
209
|
+
backupIds: mockBackupIds,
|
|
210
|
+
},
|
|
211
|
+
},
|
|
212
|
+
}),
|
|
213
|
+
)
|
|
214
|
+
})
|
|
215
|
+
|
|
216
|
+
mpc
|
|
217
|
+
.backup(args)
|
|
218
|
+
.then(async (res) => {
|
|
219
|
+
expect(res.cipherText).toEqual(mockCipherText)
|
|
220
|
+
expect(res.encryptionKey).toEqual('custom-backup-key')
|
|
221
|
+
|
|
222
|
+
await res.storageCallback()
|
|
223
|
+
|
|
224
|
+
expect(setBackupStatusSpy).toHaveBeenCalledTimes(1)
|
|
225
|
+
expect(setBackupStatusSpy).toHaveBeenCalledWith(
|
|
226
|
+
'STORED_CLIENT_BACKUP_SHARE',
|
|
227
|
+
mockBackupIds,
|
|
228
|
+
)
|
|
229
|
+
done()
|
|
230
|
+
})
|
|
231
|
+
.catch((e) => {
|
|
232
|
+
console.error(e)
|
|
233
|
+
expect(0).toEqual(1)
|
|
234
|
+
done()
|
|
235
|
+
})
|
|
236
|
+
.finally(() => {
|
|
237
|
+
setBackupStatusSpy.mockRestore()
|
|
238
|
+
})
|
|
239
|
+
})
|
|
240
|
+
|
|
166
241
|
it('should error out if the iframe sends an error message', (done) => {
|
|
167
242
|
jest
|
|
168
243
|
.spyOn(mpc.iframe?.contentWindow!, 'postMessage')
|
|
@@ -283,7 +358,7 @@ describe('Mpc', () => {
|
|
|
283
358
|
.catch((e) => {
|
|
284
359
|
expect(e).toBeInstanceOf(Error)
|
|
285
360
|
expect(e.message).toEqual(
|
|
286
|
-
'Invalid backup method: INVALID_METHOD. Valid methods are: GDRIVE, PASSWORD, PASSKEY, UNKNOWN',
|
|
361
|
+
'Invalid backup method: INVALID_METHOD. Valid methods are: GDRIVE, PASSWORD, PASSKEY, CUSTOM, UNKNOWN',
|
|
287
362
|
)
|
|
288
363
|
done()
|
|
289
364
|
})
|
|
@@ -1496,7 +1571,7 @@ describe('Mpc', () => {
|
|
|
1496
1571
|
})
|
|
1497
1572
|
|
|
1498
1573
|
mpc
|
|
1499
|
-
.getQuote(
|
|
1574
|
+
.getQuote('eip155:1', mockQuoteArgs, mockApikey)
|
|
1500
1575
|
.then((data) => {
|
|
1501
1576
|
expect(data).toEqual(res)
|
|
1502
1577
|
done()
|
|
@@ -1536,7 +1611,7 @@ describe('Mpc', () => {
|
|
|
1536
1611
|
})
|
|
1537
1612
|
|
|
1538
1613
|
mpc
|
|
1539
|
-
.getQuote(
|
|
1614
|
+
.getQuote('eip155:1', mockQuoteArgs, mockApikey)
|
|
1540
1615
|
.then(() => {
|
|
1541
1616
|
expect(0).toEqual(1)
|
|
1542
1617
|
done()
|
|
@@ -1575,7 +1650,7 @@ describe('Mpc', () => {
|
|
|
1575
1650
|
})
|
|
1576
1651
|
|
|
1577
1652
|
mpc
|
|
1578
|
-
.getSources(
|
|
1653
|
+
.getSources('eip155:1', mockApikey)
|
|
1579
1654
|
.then((data) => {
|
|
1580
1655
|
expect(data).toEqual(res)
|
|
1581
1656
|
done()
|
|
@@ -1611,7 +1686,7 @@ describe('Mpc', () => {
|
|
|
1611
1686
|
})
|
|
1612
1687
|
|
|
1613
1688
|
mpc
|
|
1614
|
-
.getSources(
|
|
1689
|
+
.getSources('eip155:1', mockApikey)
|
|
1615
1690
|
.then(() => {
|
|
1616
1691
|
expect(0).toEqual(1)
|
|
1617
1692
|
done()
|
|
@@ -1746,8 +1821,8 @@ describe('Mpc', () => {
|
|
|
1746
1821
|
.catch((_) => {
|
|
1747
1822
|
expect(0).toEqual(1)
|
|
1748
1823
|
done()
|
|
1749
|
-
|
|
1750
|
-
|
|
1824
|
+
})
|
|
1825
|
+
})
|
|
1751
1826
|
|
|
1752
1827
|
it('should error out if the iframe sends an error message', (done) => {
|
|
1753
1828
|
jest
|
|
@@ -2945,4 +3020,866 @@ describe('Mpc', () => {
|
|
|
2945
3020
|
})
|
|
2946
3021
|
})
|
|
2947
3022
|
})
|
|
3023
|
+
|
|
3024
|
+
describe('getSwapsQuoteV2', () => {
|
|
3025
|
+
const args = mockZeroExQuoteV2Request
|
|
3026
|
+
const options = mockZeroExOptions
|
|
3027
|
+
const res = mockZeroExQuoteV2Response
|
|
3028
|
+
|
|
3029
|
+
it('should successfully return the quote', (done) => {
|
|
3030
|
+
jest
|
|
3031
|
+
.spyOn(mpc.iframe?.contentWindow!, 'postMessage')
|
|
3032
|
+
.mockImplementation((message: any, origin?) => {
|
|
3033
|
+
const { type, data } = message
|
|
3034
|
+
|
|
3035
|
+
expect(type).toEqual('portal:swaps:getQuoteV2')
|
|
3036
|
+
expect(data).toEqual({ ...args, options })
|
|
3037
|
+
expect(origin).toEqual(mockHostOrigin)
|
|
3038
|
+
|
|
3039
|
+
window.dispatchEvent(
|
|
3040
|
+
new MessageEvent('message', {
|
|
3041
|
+
origin: mockHostOrigin,
|
|
3042
|
+
data: {
|
|
3043
|
+
type: 'portal:swaps:getQuoteV2Result',
|
|
3044
|
+
data: res,
|
|
3045
|
+
},
|
|
3046
|
+
}),
|
|
3047
|
+
)
|
|
3048
|
+
})
|
|
3049
|
+
|
|
3050
|
+
mpc
|
|
3051
|
+
.getSwapsQuoteV2(args, options)
|
|
3052
|
+
.then((data) => {
|
|
3053
|
+
expect(data).toEqual(res)
|
|
3054
|
+
done()
|
|
3055
|
+
})
|
|
3056
|
+
.catch((_) => {
|
|
3057
|
+
expect(0).toEqual(1)
|
|
3058
|
+
done()
|
|
3059
|
+
})
|
|
3060
|
+
})
|
|
3061
|
+
|
|
3062
|
+
it('should successfully return the quote without options', (done) => {
|
|
3063
|
+
jest
|
|
3064
|
+
.spyOn(mpc.iframe?.contentWindow!, 'postMessage')
|
|
3065
|
+
.mockImplementation((message: any, origin?) => {
|
|
3066
|
+
const { type, data } = message
|
|
3067
|
+
|
|
3068
|
+
expect(type).toEqual('portal:swaps:getQuoteV2')
|
|
3069
|
+
expect(data).toEqual({ ...args, options: undefined })
|
|
3070
|
+
expect(origin).toEqual(mockHostOrigin)
|
|
3071
|
+
|
|
3072
|
+
window.dispatchEvent(
|
|
3073
|
+
new MessageEvent('message', {
|
|
3074
|
+
origin: mockHostOrigin,
|
|
3075
|
+
data: {
|
|
3076
|
+
type: 'portal:swaps:getQuoteV2Result',
|
|
3077
|
+
data: res,
|
|
3078
|
+
},
|
|
3079
|
+
}),
|
|
3080
|
+
)
|
|
3081
|
+
})
|
|
3082
|
+
|
|
3083
|
+
mpc
|
|
3084
|
+
.getSwapsQuoteV2(args)
|
|
3085
|
+
.then((data) => {
|
|
3086
|
+
expect(data).toEqual(res)
|
|
3087
|
+
done()
|
|
3088
|
+
})
|
|
3089
|
+
.catch((_) => {
|
|
3090
|
+
expect(0).toEqual(1)
|
|
3091
|
+
done()
|
|
3092
|
+
})
|
|
3093
|
+
})
|
|
3094
|
+
|
|
3095
|
+
it('should error out if the iframe sends an error message', (done) => {
|
|
3096
|
+
jest
|
|
3097
|
+
.spyOn(mpc.iframe?.contentWindow!, 'postMessage')
|
|
3098
|
+
.mockImplementationOnce((message: any, origin?) => {
|
|
3099
|
+
const { type, data } = message
|
|
3100
|
+
|
|
3101
|
+
expect(type).toEqual('portal:swaps:getQuoteV2')
|
|
3102
|
+
expect(data).toEqual({ ...args, options })
|
|
3103
|
+
expect(origin).toEqual(mockHostOrigin)
|
|
3104
|
+
|
|
3105
|
+
window.dispatchEvent(
|
|
3106
|
+
new MessageEvent('message', {
|
|
3107
|
+
origin: mockHostOrigin,
|
|
3108
|
+
data: {
|
|
3109
|
+
type: 'portal:swaps:getQuoteV2Error',
|
|
3110
|
+
data: {
|
|
3111
|
+
code: 1,
|
|
3112
|
+
message: 'test',
|
|
3113
|
+
},
|
|
3114
|
+
},
|
|
3115
|
+
}),
|
|
3116
|
+
)
|
|
3117
|
+
})
|
|
3118
|
+
|
|
3119
|
+
mpc
|
|
3120
|
+
.getSwapsQuoteV2(args, options)
|
|
3121
|
+
.then(() => {
|
|
3122
|
+
expect(0).toEqual(1)
|
|
3123
|
+
done()
|
|
3124
|
+
})
|
|
3125
|
+
.catch((e) => {
|
|
3126
|
+
expect(e).toBeInstanceOf(PortalMpcError)
|
|
3127
|
+
expect(e.message).toEqual('test')
|
|
3128
|
+
expect(e.code).toEqual(1)
|
|
3129
|
+
done()
|
|
3130
|
+
})
|
|
3131
|
+
})
|
|
3132
|
+
})
|
|
3133
|
+
|
|
3134
|
+
describe('getSwapsSourcesV2', () => {
|
|
3135
|
+
const args = mockZeroExSourcesV2Request
|
|
3136
|
+
const options = mockZeroExOptions
|
|
3137
|
+
const res = mockZeroExSourcesV2Response
|
|
3138
|
+
|
|
3139
|
+
it('should successfully return the sources', (done) => {
|
|
3140
|
+
jest
|
|
3141
|
+
.spyOn(mpc.iframe?.contentWindow!, 'postMessage')
|
|
3142
|
+
.mockImplementation((message: any, origin?) => {
|
|
3143
|
+
const { type, data } = message
|
|
3144
|
+
|
|
3145
|
+
expect(type).toEqual('portal:swaps:getSourcesV2')
|
|
3146
|
+
expect(data).toEqual({ ...args, options })
|
|
3147
|
+
expect(origin).toEqual(mockHostOrigin)
|
|
3148
|
+
|
|
3149
|
+
window.dispatchEvent(
|
|
3150
|
+
new MessageEvent('message', {
|
|
3151
|
+
origin: mockHostOrigin,
|
|
3152
|
+
data: {
|
|
3153
|
+
type: 'portal:swaps:getSourcesV2Result',
|
|
3154
|
+
data: res,
|
|
3155
|
+
},
|
|
3156
|
+
}),
|
|
3157
|
+
)
|
|
3158
|
+
})
|
|
3159
|
+
|
|
3160
|
+
mpc
|
|
3161
|
+
.getSwapsSourcesV2(args, options)
|
|
3162
|
+
.then((data) => {
|
|
3163
|
+
expect(data).toEqual(res)
|
|
3164
|
+
done()
|
|
3165
|
+
})
|
|
3166
|
+
.catch((_) => {
|
|
3167
|
+
expect(0).toEqual(1)
|
|
3168
|
+
done()
|
|
3169
|
+
})
|
|
3170
|
+
})
|
|
3171
|
+
|
|
3172
|
+
it('should successfully return the sources without options', (done) => {
|
|
3173
|
+
jest
|
|
3174
|
+
.spyOn(mpc.iframe?.contentWindow!, 'postMessage')
|
|
3175
|
+
.mockImplementation((message: any, origin?) => {
|
|
3176
|
+
const { type, data } = message
|
|
3177
|
+
|
|
3178
|
+
expect(type).toEqual('portal:swaps:getSourcesV2')
|
|
3179
|
+
expect(data).toEqual({ ...args, options: undefined })
|
|
3180
|
+
expect(origin).toEqual(mockHostOrigin)
|
|
3181
|
+
|
|
3182
|
+
window.dispatchEvent(
|
|
3183
|
+
new MessageEvent('message', {
|
|
3184
|
+
origin: mockHostOrigin,
|
|
3185
|
+
data: {
|
|
3186
|
+
type: 'portal:swaps:getSourcesV2Result',
|
|
3187
|
+
data: res,
|
|
3188
|
+
},
|
|
3189
|
+
}),
|
|
3190
|
+
)
|
|
3191
|
+
})
|
|
3192
|
+
|
|
3193
|
+
mpc
|
|
3194
|
+
.getSwapsSourcesV2(args)
|
|
3195
|
+
.then((data) => {
|
|
3196
|
+
expect(data).toEqual(res)
|
|
3197
|
+
done()
|
|
3198
|
+
})
|
|
3199
|
+
.catch((_) => {
|
|
3200
|
+
expect(0).toEqual(1)
|
|
3201
|
+
done()
|
|
3202
|
+
})
|
|
3203
|
+
})
|
|
3204
|
+
|
|
3205
|
+
it('should error out if the iframe sends an error message', (done) => {
|
|
3206
|
+
jest
|
|
3207
|
+
.spyOn(mpc.iframe?.contentWindow!, 'postMessage')
|
|
3208
|
+
.mockImplementationOnce((message: any, origin?) => {
|
|
3209
|
+
const { type, data } = message
|
|
3210
|
+
|
|
3211
|
+
expect(type).toEqual('portal:swaps:getSourcesV2')
|
|
3212
|
+
expect(data).toEqual({ ...args, options })
|
|
3213
|
+
expect(origin).toEqual(mockHostOrigin)
|
|
3214
|
+
|
|
3215
|
+
window.dispatchEvent(
|
|
3216
|
+
new MessageEvent('message', {
|
|
3217
|
+
origin: mockHostOrigin,
|
|
3218
|
+
data: {
|
|
3219
|
+
type: 'portal:swaps:getSourcesV2Error',
|
|
3220
|
+
data: {
|
|
3221
|
+
code: 1,
|
|
3222
|
+
message: 'test',
|
|
3223
|
+
},
|
|
3224
|
+
},
|
|
3225
|
+
}),
|
|
3226
|
+
)
|
|
3227
|
+
})
|
|
3228
|
+
|
|
3229
|
+
mpc
|
|
3230
|
+
.getSwapsSourcesV2(args, options)
|
|
3231
|
+
.then(() => {
|
|
3232
|
+
expect(0).toEqual(1)
|
|
3233
|
+
done()
|
|
3234
|
+
})
|
|
3235
|
+
.catch((e) => {
|
|
3236
|
+
expect(e).toBeInstanceOf(PortalMpcError)
|
|
3237
|
+
expect(e.message).toEqual('test')
|
|
3238
|
+
expect(e.code).toEqual(1)
|
|
3239
|
+
done()
|
|
3240
|
+
})
|
|
3241
|
+
})
|
|
3242
|
+
})
|
|
3243
|
+
|
|
3244
|
+
describe('getSwapsPrice', () => {
|
|
3245
|
+
const args = mockZeroExPriceRequest
|
|
3246
|
+
const options = mockZeroExOptions
|
|
3247
|
+
const res = mockZeroExPriceResponse
|
|
3248
|
+
|
|
3249
|
+
it('should successfully return the price', (done) => {
|
|
3250
|
+
jest
|
|
3251
|
+
.spyOn(mpc.iframe?.contentWindow!, 'postMessage')
|
|
3252
|
+
.mockImplementation((message: any, origin?) => {
|
|
3253
|
+
const { type, data } = message
|
|
3254
|
+
|
|
3255
|
+
expect(type).toEqual('portal:swaps:getPrice')
|
|
3256
|
+
expect(data).toEqual({ ...args, options })
|
|
3257
|
+
expect(origin).toEqual(mockHostOrigin)
|
|
3258
|
+
|
|
3259
|
+
window.dispatchEvent(
|
|
3260
|
+
new MessageEvent('message', {
|
|
3261
|
+
origin: mockHostOrigin,
|
|
3262
|
+
data: {
|
|
3263
|
+
type: 'portal:swaps:getPriceResult',
|
|
3264
|
+
data: res,
|
|
3265
|
+
},
|
|
3266
|
+
}),
|
|
3267
|
+
)
|
|
3268
|
+
})
|
|
3269
|
+
|
|
3270
|
+
mpc
|
|
3271
|
+
.getSwapsPrice(args, options)
|
|
3272
|
+
.then((data) => {
|
|
3273
|
+
expect(data).toEqual(res)
|
|
3274
|
+
done()
|
|
3275
|
+
})
|
|
3276
|
+
.catch((_) => {
|
|
3277
|
+
expect(0).toEqual(1)
|
|
3278
|
+
done()
|
|
3279
|
+
})
|
|
3280
|
+
})
|
|
3281
|
+
|
|
3282
|
+
it('should successfully return the price without options', (done) => {
|
|
3283
|
+
jest
|
|
3284
|
+
.spyOn(mpc.iframe?.contentWindow!, 'postMessage')
|
|
3285
|
+
.mockImplementation((message: any, origin?) => {
|
|
3286
|
+
const { type, data } = message
|
|
3287
|
+
|
|
3288
|
+
expect(type).toEqual('portal:swaps:getPrice')
|
|
3289
|
+
expect(data).toEqual({ ...args, options: undefined })
|
|
3290
|
+
expect(origin).toEqual(mockHostOrigin)
|
|
3291
|
+
|
|
3292
|
+
window.dispatchEvent(
|
|
3293
|
+
new MessageEvent('message', {
|
|
3294
|
+
origin: mockHostOrigin,
|
|
3295
|
+
data: {
|
|
3296
|
+
type: 'portal:swaps:getPriceResult',
|
|
3297
|
+
data: res,
|
|
3298
|
+
},
|
|
3299
|
+
}),
|
|
3300
|
+
)
|
|
3301
|
+
})
|
|
3302
|
+
|
|
3303
|
+
mpc
|
|
3304
|
+
.getSwapsPrice(args)
|
|
3305
|
+
.then((data) => {
|
|
3306
|
+
expect(data).toEqual(res)
|
|
3307
|
+
done()
|
|
3308
|
+
})
|
|
3309
|
+
.catch((_) => {
|
|
3310
|
+
expect(0).toEqual(1)
|
|
3311
|
+
done()
|
|
3312
|
+
})
|
|
3313
|
+
})
|
|
3314
|
+
|
|
3315
|
+
it('should error out if the iframe sends an error message', (done) => {
|
|
3316
|
+
jest
|
|
3317
|
+
.spyOn(mpc.iframe?.contentWindow!, 'postMessage')
|
|
3318
|
+
.mockImplementationOnce((message: any, origin?) => {
|
|
3319
|
+
const { type, data } = message
|
|
3320
|
+
|
|
3321
|
+
expect(type).toEqual('portal:swaps:getPrice')
|
|
3322
|
+
expect(data).toEqual({ ...args, options })
|
|
3323
|
+
expect(origin).toEqual(mockHostOrigin)
|
|
3324
|
+
|
|
3325
|
+
window.dispatchEvent(
|
|
3326
|
+
new MessageEvent('message', {
|
|
3327
|
+
origin: mockHostOrigin,
|
|
3328
|
+
data: {
|
|
3329
|
+
type: 'portal:swaps:getPriceError',
|
|
3330
|
+
data: {
|
|
3331
|
+
code: 1,
|
|
3332
|
+
message: 'test',
|
|
3333
|
+
},
|
|
3334
|
+
},
|
|
3335
|
+
}),
|
|
3336
|
+
)
|
|
3337
|
+
})
|
|
3338
|
+
|
|
3339
|
+
mpc
|
|
3340
|
+
.getSwapsPrice(args, options)
|
|
3341
|
+
.then(() => {
|
|
3342
|
+
expect(0).toEqual(1)
|
|
3343
|
+
done()
|
|
3344
|
+
})
|
|
3345
|
+
.catch((e) => {
|
|
3346
|
+
expect(e).toBeInstanceOf(PortalMpcError)
|
|
3347
|
+
expect(e.message).toEqual('test')
|
|
3348
|
+
expect(e.code).toEqual(1)
|
|
3349
|
+
done()
|
|
3350
|
+
})
|
|
3351
|
+
})
|
|
3352
|
+
})
|
|
3353
|
+
|
|
3354
|
+
describe('scanAddresses', () => {
|
|
3355
|
+
const args = mockScanAddressesRequest
|
|
3356
|
+
const res = mockScanAddressesResponse
|
|
3357
|
+
|
|
3358
|
+
it('should successfully scan addresses', (done) => {
|
|
3359
|
+
jest
|
|
3360
|
+
.spyOn(mpc.iframe?.contentWindow!, 'postMessage')
|
|
3361
|
+
.mockImplementation((message: any, origin?) => {
|
|
3362
|
+
const { type, data } = message
|
|
3363
|
+
|
|
3364
|
+
expect(type).toEqual('portal:security:scanAddresses')
|
|
3365
|
+
expect(data).toEqual(args)
|
|
3366
|
+
expect(origin).toEqual(mockHostOrigin)
|
|
3367
|
+
|
|
3368
|
+
window.dispatchEvent(
|
|
3369
|
+
new MessageEvent('message', {
|
|
3370
|
+
origin: mockHostOrigin,
|
|
3371
|
+
data: {
|
|
3372
|
+
type: 'portal:security:scanAddressesResult',
|
|
3373
|
+
data: res,
|
|
3374
|
+
},
|
|
3375
|
+
}),
|
|
3376
|
+
)
|
|
3377
|
+
})
|
|
3378
|
+
|
|
3379
|
+
mpc
|
|
3380
|
+
.scanAddresses(args)
|
|
3381
|
+
.then((data) => {
|
|
3382
|
+
expect(data).toEqual(res)
|
|
3383
|
+
done()
|
|
3384
|
+
})
|
|
3385
|
+
.catch((_) => {
|
|
3386
|
+
expect(0).toEqual(1)
|
|
3387
|
+
done()
|
|
3388
|
+
})
|
|
3389
|
+
})
|
|
3390
|
+
|
|
3391
|
+
it('should error out if the iframe sends an error message', (done) => {
|
|
3392
|
+
jest
|
|
3393
|
+
.spyOn(mpc.iframe?.contentWindow!, 'postMessage')
|
|
3394
|
+
.mockImplementationOnce((message: any, origin?) => {
|
|
3395
|
+
const { type, data } = message
|
|
3396
|
+
|
|
3397
|
+
expect(type).toEqual('portal:security:scanAddresses')
|
|
3398
|
+
expect(data).toEqual(args)
|
|
3399
|
+
expect(origin).toEqual(mockHostOrigin)
|
|
3400
|
+
|
|
3401
|
+
window.dispatchEvent(
|
|
3402
|
+
new MessageEvent('message', {
|
|
3403
|
+
origin: mockHostOrigin,
|
|
3404
|
+
data: {
|
|
3405
|
+
type: 'portal:security:scanAddressesError',
|
|
3406
|
+
data: {
|
|
3407
|
+
code: 1,
|
|
3408
|
+
message: 'test',
|
|
3409
|
+
},
|
|
3410
|
+
},
|
|
3411
|
+
}),
|
|
3412
|
+
)
|
|
3413
|
+
})
|
|
3414
|
+
|
|
3415
|
+
mpc
|
|
3416
|
+
.scanAddresses(args)
|
|
3417
|
+
.then(() => {
|
|
3418
|
+
expect(0).toEqual(1)
|
|
3419
|
+
done()
|
|
3420
|
+
})
|
|
3421
|
+
.catch((e) => {
|
|
3422
|
+
expect(e).toBeInstanceOf(PortalMpcError)
|
|
3423
|
+
expect(e.message).toEqual('test')
|
|
3424
|
+
expect(e.code).toEqual(1)
|
|
3425
|
+
done()
|
|
3426
|
+
})
|
|
3427
|
+
})
|
|
3428
|
+
})
|
|
3429
|
+
|
|
3430
|
+
describe('scanEVMTx', () => {
|
|
3431
|
+
const args = mockScanEVMTxRequest
|
|
3432
|
+
const res = mockScanEVMTxResponse
|
|
3433
|
+
|
|
3434
|
+
it('should successfully scan EIP-155 transaction', (done) => {
|
|
3435
|
+
jest
|
|
3436
|
+
.spyOn(mpc.iframe?.contentWindow!, 'postMessage')
|
|
3437
|
+
.mockImplementation((message: any, origin?) => {
|
|
3438
|
+
const { type, data } = message
|
|
3439
|
+
|
|
3440
|
+
expect(type).toEqual('portal:security:scanEVMTx')
|
|
3441
|
+
expect(data).toEqual(args)
|
|
3442
|
+
expect(origin).toEqual(mockHostOrigin)
|
|
3443
|
+
|
|
3444
|
+
window.dispatchEvent(
|
|
3445
|
+
new MessageEvent('message', {
|
|
3446
|
+
origin: mockHostOrigin,
|
|
3447
|
+
data: {
|
|
3448
|
+
type: 'portal:security:scanEVMTxResult',
|
|
3449
|
+
data: res,
|
|
3450
|
+
},
|
|
3451
|
+
}),
|
|
3452
|
+
)
|
|
3453
|
+
})
|
|
3454
|
+
|
|
3455
|
+
mpc
|
|
3456
|
+
.scanEVMTx(args)
|
|
3457
|
+
.then((data) => {
|
|
3458
|
+
expect(data).toEqual(res)
|
|
3459
|
+
done()
|
|
3460
|
+
})
|
|
3461
|
+
.catch((_) => {
|
|
3462
|
+
expect(0).toEqual(1)
|
|
3463
|
+
done()
|
|
3464
|
+
})
|
|
3465
|
+
})
|
|
3466
|
+
|
|
3467
|
+
it('should error out if the iframe sends an error message', (done) => {
|
|
3468
|
+
jest
|
|
3469
|
+
.spyOn(mpc.iframe?.contentWindow!, 'postMessage')
|
|
3470
|
+
.mockImplementationOnce((message: any, origin?) => {
|
|
3471
|
+
const { type, data } = message
|
|
3472
|
+
|
|
3473
|
+
expect(type).toEqual('portal:security:scanEVMTx')
|
|
3474
|
+
expect(data).toEqual(args)
|
|
3475
|
+
expect(origin).toEqual(mockHostOrigin)
|
|
3476
|
+
|
|
3477
|
+
window.dispatchEvent(
|
|
3478
|
+
new MessageEvent('message', {
|
|
3479
|
+
origin: mockHostOrigin,
|
|
3480
|
+
data: {
|
|
3481
|
+
type: 'portal:security:scanEVMTxError',
|
|
3482
|
+
data: {
|
|
3483
|
+
code: 1,
|
|
3484
|
+
message: 'test',
|
|
3485
|
+
},
|
|
3486
|
+
},
|
|
3487
|
+
}),
|
|
3488
|
+
)
|
|
3489
|
+
})
|
|
3490
|
+
|
|
3491
|
+
mpc
|
|
3492
|
+
.scanEVMTx(args)
|
|
3493
|
+
.then(() => {
|
|
3494
|
+
expect(0).toEqual(1)
|
|
3495
|
+
done()
|
|
3496
|
+
})
|
|
3497
|
+
.catch((e) => {
|
|
3498
|
+
expect(e).toBeInstanceOf(PortalMpcError)
|
|
3499
|
+
expect(e.message).toEqual('test')
|
|
3500
|
+
expect(e.code).toEqual(1)
|
|
3501
|
+
done()
|
|
3502
|
+
})
|
|
3503
|
+
})
|
|
3504
|
+
})
|
|
3505
|
+
|
|
3506
|
+
describe('scanEip712Tx', () => {
|
|
3507
|
+
const args = mockScanEip712TxRequest
|
|
3508
|
+
const res = mockScanEip712TxResponse
|
|
3509
|
+
|
|
3510
|
+
it('should successfully scan EIP-712 transaction', (done) => {
|
|
3511
|
+
jest
|
|
3512
|
+
.spyOn(mpc.iframe?.contentWindow!, 'postMessage')
|
|
3513
|
+
.mockImplementation((message: any, origin?) => {
|
|
3514
|
+
const { type, data } = message
|
|
3515
|
+
|
|
3516
|
+
expect(type).toEqual('portal:security:scanEip712Tx')
|
|
3517
|
+
expect(data).toEqual(args)
|
|
3518
|
+
expect(origin).toEqual(mockHostOrigin)
|
|
3519
|
+
|
|
3520
|
+
window.dispatchEvent(
|
|
3521
|
+
new MessageEvent('message', {
|
|
3522
|
+
origin: mockHostOrigin,
|
|
3523
|
+
data: {
|
|
3524
|
+
type: 'portal:security:scanEip712TxResult',
|
|
3525
|
+
data: res,
|
|
3526
|
+
},
|
|
3527
|
+
}),
|
|
3528
|
+
)
|
|
3529
|
+
})
|
|
3530
|
+
|
|
3531
|
+
mpc
|
|
3532
|
+
.scanEip712Tx(args)
|
|
3533
|
+
.then((data) => {
|
|
3534
|
+
expect(data).toEqual(res)
|
|
3535
|
+
done()
|
|
3536
|
+
})
|
|
3537
|
+
.catch((_) => {
|
|
3538
|
+
expect(0).toEqual(1)
|
|
3539
|
+
done()
|
|
3540
|
+
})
|
|
3541
|
+
})
|
|
3542
|
+
|
|
3543
|
+
it('should error out if the iframe sends an error message', (done) => {
|
|
3544
|
+
jest
|
|
3545
|
+
.spyOn(mpc.iframe?.contentWindow!, 'postMessage')
|
|
3546
|
+
.mockImplementationOnce((message: any, origin?) => {
|
|
3547
|
+
const { type, data } = message
|
|
3548
|
+
|
|
3549
|
+
expect(type).toEqual('portal:security:scanEip712Tx')
|
|
3550
|
+
expect(data).toEqual(args)
|
|
3551
|
+
expect(origin).toEqual(mockHostOrigin)
|
|
3552
|
+
|
|
3553
|
+
window.dispatchEvent(
|
|
3554
|
+
new MessageEvent('message', {
|
|
3555
|
+
origin: mockHostOrigin,
|
|
3556
|
+
data: {
|
|
3557
|
+
type: 'portal:security:scanEip712TxError',
|
|
3558
|
+
data: {
|
|
3559
|
+
code: 1,
|
|
3560
|
+
message: 'test',
|
|
3561
|
+
},
|
|
3562
|
+
},
|
|
3563
|
+
}),
|
|
3564
|
+
)
|
|
3565
|
+
})
|
|
3566
|
+
|
|
3567
|
+
mpc
|
|
3568
|
+
.scanEip712Tx(args)
|
|
3569
|
+
.then(() => {
|
|
3570
|
+
expect(0).toEqual(1)
|
|
3571
|
+
done()
|
|
3572
|
+
})
|
|
3573
|
+
.catch((e) => {
|
|
3574
|
+
expect(e).toBeInstanceOf(PortalMpcError)
|
|
3575
|
+
expect(e.message).toEqual('test')
|
|
3576
|
+
expect(e.code).toEqual(1)
|
|
3577
|
+
done()
|
|
3578
|
+
})
|
|
3579
|
+
})
|
|
3580
|
+
})
|
|
3581
|
+
|
|
3582
|
+
describe('scanSolanaTx', () => {
|
|
3583
|
+
const args = mockScanSolanaTxRequest
|
|
3584
|
+
const res = mockScanSolanaTxResponse
|
|
3585
|
+
|
|
3586
|
+
it('should successfully scan Solana transaction', (done) => {
|
|
3587
|
+
jest
|
|
3588
|
+
.spyOn(mpc.iframe?.contentWindow!, 'postMessage')
|
|
3589
|
+
.mockImplementation((message: any, origin?) => {
|
|
3590
|
+
const { type, data } = message
|
|
3591
|
+
|
|
3592
|
+
expect(type).toEqual('portal:security:scanSolanaTx')
|
|
3593
|
+
expect(data).toEqual(args)
|
|
3594
|
+
expect(origin).toEqual(mockHostOrigin)
|
|
3595
|
+
|
|
3596
|
+
window.dispatchEvent(
|
|
3597
|
+
new MessageEvent('message', {
|
|
3598
|
+
origin: mockHostOrigin,
|
|
3599
|
+
data: {
|
|
3600
|
+
type: 'portal:security:scanSolanaTxResult',
|
|
3601
|
+
data: res,
|
|
3602
|
+
},
|
|
3603
|
+
}),
|
|
3604
|
+
)
|
|
3605
|
+
})
|
|
3606
|
+
|
|
3607
|
+
mpc
|
|
3608
|
+
.scanSolanaTx(args)
|
|
3609
|
+
.then((data) => {
|
|
3610
|
+
expect(data).toEqual(res)
|
|
3611
|
+
done()
|
|
3612
|
+
})
|
|
3613
|
+
.catch((_) => {
|
|
3614
|
+
expect(0).toEqual(1)
|
|
3615
|
+
done()
|
|
3616
|
+
})
|
|
3617
|
+
})
|
|
3618
|
+
|
|
3619
|
+
it('should error out if the iframe sends an error message', (done) => {
|
|
3620
|
+
jest
|
|
3621
|
+
.spyOn(mpc.iframe?.contentWindow!, 'postMessage')
|
|
3622
|
+
.mockImplementationOnce((message: any, origin?) => {
|
|
3623
|
+
const { type, data } = message
|
|
3624
|
+
|
|
3625
|
+
expect(type).toEqual('portal:security:scanSolanaTx')
|
|
3626
|
+
expect(data).toEqual(args)
|
|
3627
|
+
expect(origin).toEqual(mockHostOrigin)
|
|
3628
|
+
|
|
3629
|
+
window.dispatchEvent(
|
|
3630
|
+
new MessageEvent('message', {
|
|
3631
|
+
origin: mockHostOrigin,
|
|
3632
|
+
data: {
|
|
3633
|
+
type: 'portal:security:scanSolanaTxError',
|
|
3634
|
+
data: {
|
|
3635
|
+
code: 1,
|
|
3636
|
+
message: 'test',
|
|
3637
|
+
},
|
|
3638
|
+
},
|
|
3639
|
+
}),
|
|
3640
|
+
)
|
|
3641
|
+
})
|
|
3642
|
+
|
|
3643
|
+
mpc
|
|
3644
|
+
.scanSolanaTx(args)
|
|
3645
|
+
.then(() => {
|
|
3646
|
+
expect(0).toEqual(1)
|
|
3647
|
+
done()
|
|
3648
|
+
})
|
|
3649
|
+
.catch((e) => {
|
|
3650
|
+
expect(e).toBeInstanceOf(PortalMpcError)
|
|
3651
|
+
expect(e.message).toEqual('test')
|
|
3652
|
+
expect(e.code).toEqual(1)
|
|
3653
|
+
done()
|
|
3654
|
+
})
|
|
3655
|
+
})
|
|
3656
|
+
})
|
|
3657
|
+
|
|
3658
|
+
describe('scanNft', () => {
|
|
3659
|
+
const args = mockScanNftRequest
|
|
3660
|
+
const res = mockScanNftResponse
|
|
3661
|
+
|
|
3662
|
+
it('should successfully scan NFT', (done) => {
|
|
3663
|
+
jest
|
|
3664
|
+
.spyOn(mpc.iframe?.contentWindow!, 'postMessage')
|
|
3665
|
+
.mockImplementation((message: any, origin?) => {
|
|
3666
|
+
const { type, data } = message
|
|
3667
|
+
|
|
3668
|
+
expect(type).toEqual('portal:security:scanNfts')
|
|
3669
|
+
expect(data).toEqual(args)
|
|
3670
|
+
expect(origin).toEqual(mockHostOrigin)
|
|
3671
|
+
|
|
3672
|
+
window.dispatchEvent(
|
|
3673
|
+
new MessageEvent('message', {
|
|
3674
|
+
origin: mockHostOrigin,
|
|
3675
|
+
data: {
|
|
3676
|
+
type: 'portal:security:scanNftsResult',
|
|
3677
|
+
data: res,
|
|
3678
|
+
},
|
|
3679
|
+
}),
|
|
3680
|
+
)
|
|
3681
|
+
})
|
|
3682
|
+
|
|
3683
|
+
mpc
|
|
3684
|
+
.scanNFTs(args)
|
|
3685
|
+
.then((data) => {
|
|
3686
|
+
expect(data).toEqual(res)
|
|
3687
|
+
done()
|
|
3688
|
+
})
|
|
3689
|
+
.catch((_) => {
|
|
3690
|
+
expect(0).toEqual(1)
|
|
3691
|
+
done()
|
|
3692
|
+
})
|
|
3693
|
+
})
|
|
3694
|
+
|
|
3695
|
+
it('should error out if the iframe sends an error message', (done) => {
|
|
3696
|
+
jest
|
|
3697
|
+
.spyOn(mpc.iframe?.contentWindow!, 'postMessage')
|
|
3698
|
+
.mockImplementationOnce((message: any, origin?) => {
|
|
3699
|
+
const { type, data } = message
|
|
3700
|
+
|
|
3701
|
+
expect(type).toEqual('portal:security:scanNfts')
|
|
3702
|
+
expect(data).toEqual(args)
|
|
3703
|
+
expect(origin).toEqual(mockHostOrigin)
|
|
3704
|
+
|
|
3705
|
+
window.dispatchEvent(
|
|
3706
|
+
new MessageEvent('message', {
|
|
3707
|
+
origin: mockHostOrigin,
|
|
3708
|
+
data: {
|
|
3709
|
+
type: 'portal:security:scanNftsError',
|
|
3710
|
+
data: {
|
|
3711
|
+
code: 1,
|
|
3712
|
+
message: 'test',
|
|
3713
|
+
},
|
|
3714
|
+
},
|
|
3715
|
+
}),
|
|
3716
|
+
)
|
|
3717
|
+
})
|
|
3718
|
+
|
|
3719
|
+
mpc
|
|
3720
|
+
.scanNFTs(args)
|
|
3721
|
+
.then(() => {
|
|
3722
|
+
expect(0).toEqual(1)
|
|
3723
|
+
done()
|
|
3724
|
+
})
|
|
3725
|
+
.catch((e) => {
|
|
3726
|
+
expect(e).toBeInstanceOf(PortalMpcError)
|
|
3727
|
+
expect(e.message).toEqual('test')
|
|
3728
|
+
expect(e.code).toEqual(1)
|
|
3729
|
+
done()
|
|
3730
|
+
})
|
|
3731
|
+
})
|
|
3732
|
+
})
|
|
3733
|
+
|
|
3734
|
+
describe('scanToken', () => {
|
|
3735
|
+
const args = mockScanTokenRequest
|
|
3736
|
+
const res = mockScanTokenResponse
|
|
3737
|
+
|
|
3738
|
+
it('should successfully scan token', (done) => {
|
|
3739
|
+
jest
|
|
3740
|
+
.spyOn(mpc.iframe?.contentWindow!, 'postMessage')
|
|
3741
|
+
.mockImplementation((message: any, origin?) => {
|
|
3742
|
+
const { type, data } = message
|
|
3743
|
+
|
|
3744
|
+
expect(type).toEqual('portal:security:scanTokens')
|
|
3745
|
+
expect(data).toEqual(args)
|
|
3746
|
+
expect(origin).toEqual(mockHostOrigin)
|
|
3747
|
+
|
|
3748
|
+
window.dispatchEvent(
|
|
3749
|
+
new MessageEvent('message', {
|
|
3750
|
+
origin: mockHostOrigin,
|
|
3751
|
+
data: {
|
|
3752
|
+
type: 'portal:security:scanTokensResult',
|
|
3753
|
+
data: res,
|
|
3754
|
+
},
|
|
3755
|
+
}),
|
|
3756
|
+
)
|
|
3757
|
+
})
|
|
3758
|
+
|
|
3759
|
+
mpc
|
|
3760
|
+
.scanTokens(args)
|
|
3761
|
+
.then((data) => {
|
|
3762
|
+
expect(data).toEqual(res)
|
|
3763
|
+
done()
|
|
3764
|
+
})
|
|
3765
|
+
.catch((_) => {
|
|
3766
|
+
expect(0).toEqual(1)
|
|
3767
|
+
done()
|
|
3768
|
+
})
|
|
3769
|
+
})
|
|
3770
|
+
|
|
3771
|
+
it('should error out if the iframe sends an error message', (done) => {
|
|
3772
|
+
jest
|
|
3773
|
+
.spyOn(mpc.iframe?.contentWindow!, 'postMessage')
|
|
3774
|
+
.mockImplementationOnce((message: any, origin?) => {
|
|
3775
|
+
const { type, data } = message
|
|
3776
|
+
|
|
3777
|
+
expect(type).toEqual('portal:security:scanTokens')
|
|
3778
|
+
expect(data).toEqual(args)
|
|
3779
|
+
expect(origin).toEqual(mockHostOrigin)
|
|
3780
|
+
|
|
3781
|
+
window.dispatchEvent(
|
|
3782
|
+
new MessageEvent('message', {
|
|
3783
|
+
origin: mockHostOrigin,
|
|
3784
|
+
data: {
|
|
3785
|
+
type: 'portal:security:scanTokensError',
|
|
3786
|
+
data: {
|
|
3787
|
+
code: 1,
|
|
3788
|
+
message: 'test',
|
|
3789
|
+
},
|
|
3790
|
+
},
|
|
3791
|
+
}),
|
|
3792
|
+
)
|
|
3793
|
+
})
|
|
3794
|
+
|
|
3795
|
+
mpc
|
|
3796
|
+
.scanTokens(args)
|
|
3797
|
+
.then(() => {
|
|
3798
|
+
expect(0).toEqual(1)
|
|
3799
|
+
done()
|
|
3800
|
+
})
|
|
3801
|
+
.catch((e) => {
|
|
3802
|
+
expect(e).toBeInstanceOf(PortalMpcError)
|
|
3803
|
+
expect(e.message).toEqual('test')
|
|
3804
|
+
expect(e.code).toEqual(1)
|
|
3805
|
+
done()
|
|
3806
|
+
})
|
|
3807
|
+
})
|
|
3808
|
+
})
|
|
3809
|
+
|
|
3810
|
+
describe('scanUrl', () => {
|
|
3811
|
+
const args = mockScanUrlRequest
|
|
3812
|
+
const res = mockScanUrlResponse
|
|
3813
|
+
|
|
3814
|
+
it('should successfully scan URL', (done) => {
|
|
3815
|
+
jest
|
|
3816
|
+
.spyOn(mpc.iframe?.contentWindow!, 'postMessage')
|
|
3817
|
+
.mockImplementation((message: any, origin?) => {
|
|
3818
|
+
const { type, data } = message
|
|
3819
|
+
|
|
3820
|
+
expect(type).toEqual('portal:security:scanUrl')
|
|
3821
|
+
expect(data).toEqual({ url: args })
|
|
3822
|
+
expect(origin).toEqual(mockHostOrigin)
|
|
3823
|
+
|
|
3824
|
+
window.dispatchEvent(
|
|
3825
|
+
new MessageEvent('message', {
|
|
3826
|
+
origin: mockHostOrigin,
|
|
3827
|
+
data: {
|
|
3828
|
+
type: 'portal:security:scanUrlResult',
|
|
3829
|
+
data: res,
|
|
3830
|
+
},
|
|
3831
|
+
}),
|
|
3832
|
+
)
|
|
3833
|
+
})
|
|
3834
|
+
|
|
3835
|
+
mpc
|
|
3836
|
+
.scanUrl(args)
|
|
3837
|
+
.then((data) => {
|
|
3838
|
+
expect(data).toEqual(res)
|
|
3839
|
+
done()
|
|
3840
|
+
})
|
|
3841
|
+
.catch((_) => {
|
|
3842
|
+
expect(0).toEqual(1)
|
|
3843
|
+
done()
|
|
3844
|
+
})
|
|
3845
|
+
})
|
|
3846
|
+
|
|
3847
|
+
it('should error out if the iframe sends an error message', (done) => {
|
|
3848
|
+
jest
|
|
3849
|
+
.spyOn(mpc.iframe?.contentWindow!, 'postMessage')
|
|
3850
|
+
.mockImplementationOnce((message: any, origin?) => {
|
|
3851
|
+
const { type, data } = message
|
|
3852
|
+
|
|
3853
|
+
expect(type).toEqual('portal:security:scanUrl')
|
|
3854
|
+
expect(data).toEqual({ url: args })
|
|
3855
|
+
expect(origin).toEqual(mockHostOrigin)
|
|
3856
|
+
|
|
3857
|
+
window.dispatchEvent(
|
|
3858
|
+
new MessageEvent('message', {
|
|
3859
|
+
origin: mockHostOrigin,
|
|
3860
|
+
data: {
|
|
3861
|
+
type: 'portal:security:scanUrlError',
|
|
3862
|
+
data: {
|
|
3863
|
+
code: 1,
|
|
3864
|
+
message: 'test',
|
|
3865
|
+
},
|
|
3866
|
+
},
|
|
3867
|
+
}),
|
|
3868
|
+
)
|
|
3869
|
+
})
|
|
3870
|
+
|
|
3871
|
+
mpc
|
|
3872
|
+
.scanUrl(args)
|
|
3873
|
+
.then(() => {
|
|
3874
|
+
expect(0).toEqual(1)
|
|
3875
|
+
done()
|
|
3876
|
+
})
|
|
3877
|
+
.catch((e) => {
|
|
3878
|
+
expect(e).toBeInstanceOf(PortalMpcError)
|
|
3879
|
+
expect(e.message).toEqual('test')
|
|
3880
|
+
expect(e.code).toEqual(1)
|
|
3881
|
+
done()
|
|
3882
|
+
})
|
|
3883
|
+
})
|
|
3884
|
+
})
|
|
2948
3885
|
})
|