@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
|
@@ -1,9 +1,18 @@
|
|
|
1
1
|
/**
|
|
2
2
|
* @jest-environment jsdom
|
|
3
3
|
*/
|
|
4
|
+
var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, generator) {
|
|
5
|
+
function adopt(value) { return value instanceof P ? value : new P(function (resolve) { resolve(value); }); }
|
|
6
|
+
return new (P || (P = Promise))(function (resolve, reject) {
|
|
7
|
+
function fulfilled(value) { try { step(generator.next(value)); } catch (e) { reject(e); } }
|
|
8
|
+
function rejected(value) { try { step(generator["throw"](value)); } catch (e) { reject(e); } }
|
|
9
|
+
function step(result) { result.done ? resolve(result.value) : adopt(result.value).then(fulfilled, rejected); }
|
|
10
|
+
step((generator = generator.apply(thisArg, _arguments || [])).next());
|
|
11
|
+
});
|
|
12
|
+
};
|
|
4
13
|
import { BackupMethods, MpcStatuses, PortalCurve } from '../index';
|
|
5
14
|
import Mpc from '.';
|
|
6
|
-
import { mockAddress, mockApikey, mockAssets, mockBackupConfig, mockBackupIds, mockBalances, mockBuiltTransaction, mockCipherText, mockClientResponse, mockEjectResult, mockEjectPrivateKeysResult, mockEvaluationResult, mockHost, mockNFTs, mockOrgBackupShares, mockQuoteArgs, mockRpcUrl, mockSharesOnDevice, mockSimulationResult, mockTransactionToEvaluate, mockTransactionToSimulate, mockYieldXyzGetYieldsRequest, mockYieldXyzGetYieldsResponse, mockYieldXyzEnterRequest, mockYieldXyzEnterResponse, mockYieldXyzExitRequest, mockYieldXyzExitResponse, mockYieldXyzGetBalancesRequest, mockYieldXyzGetBalancesResponse, mockYieldXyzGetHistoricalActionsRequest, mockYieldXyzGetHistoricalActionsResponse, mockYieldXyzManageYieldRequest, mockYieldXyzManageYieldResponse, mockYieldXyzTrackTransactionRequest, mockYieldXyzTrackTransactionResponse, mockYieldXyzGetTransactionResponse, mockLifiGetRoutesRequest, mockLifiGetRoutesResponse, mockLifiGetQuoteRequest, mockLifiGetQuoteResponse, mockLifiGetStatusRequest, mockLifiGetStatusResponse, mockLifiGetRouteStepRequest, mockLifiGetRouteStepResponse, } from '../__mocks/constants';
|
|
15
|
+
import { mockAddress, mockApikey, mockAssets, mockBackupConfig, mockBackupIds, mockBalances, mockBuiltTransaction, mockCipherText, mockClientResponse, mockEjectResult, mockEjectPrivateKeysResult, mockEvaluationResult, mockHost, mockNFTs, mockOrgBackupShares, mockQuoteArgs, mockRpcUrl, mockSharesOnDevice, mockSimulationResult, mockTransactionToEvaluate, mockTransactionToSimulate, mockYieldXyzGetYieldsRequest, mockYieldXyzGetYieldsResponse, mockYieldXyzEnterRequest, mockYieldXyzEnterResponse, mockYieldXyzExitRequest, mockYieldXyzExitResponse, mockYieldXyzGetBalancesRequest, mockYieldXyzGetBalancesResponse, mockYieldXyzGetHistoricalActionsRequest, mockYieldXyzGetHistoricalActionsResponse, mockYieldXyzManageYieldRequest, mockYieldXyzManageYieldResponse, mockYieldXyzTrackTransactionRequest, mockYieldXyzTrackTransactionResponse, mockYieldXyzGetTransactionResponse, mockLifiGetRoutesRequest, mockLifiGetRoutesResponse, mockLifiGetQuoteRequest, mockLifiGetQuoteResponse, mockLifiGetStatusRequest, mockLifiGetStatusResponse, mockLifiGetRouteStepRequest, mockLifiGetRouteStepResponse, mockZeroExQuoteV2Request, mockZeroExQuoteV2Response, mockZeroExSourcesV2Request, mockZeroExSourcesV2Response, mockZeroExPriceRequest, mockZeroExPriceResponse, mockZeroExOptions, mockScanAddressesRequest, mockScanAddressesResponse, mockScanEVMTxRequest, mockScanEVMTxResponse, mockScanEip712TxRequest, mockScanEip712TxResponse, mockScanSolanaTxRequest, mockScanSolanaTxResponse, mockScanNftRequest, mockScanNftResponse, mockScanTokenRequest, mockScanTokenResponse, mockScanUrlRequest, mockScanUrlResponse, } from '../__mocks/constants';
|
|
7
16
|
import portalMock from '../__mocks/portal/portal';
|
|
8
17
|
import { PortalMpcError } from './errors';
|
|
9
18
|
describe('Mpc', () => {
|
|
@@ -96,6 +105,49 @@ describe('Mpc', () => {
|
|
|
96
105
|
done();
|
|
97
106
|
});
|
|
98
107
|
});
|
|
108
|
+
it('should include encryption key when iframe returns custom backup response', (done) => {
|
|
109
|
+
var _a;
|
|
110
|
+
const setBackupStatusSpy = jest
|
|
111
|
+
.spyOn(mpc, 'setBackupStatus')
|
|
112
|
+
.mockResolvedValue(true);
|
|
113
|
+
jest
|
|
114
|
+
.spyOn((_a = mpc.iframe) === null || _a === void 0 ? void 0 : _a.contentWindow, 'postMessage')
|
|
115
|
+
.mockImplementation((message, origin) => {
|
|
116
|
+
const { type, data } = message;
|
|
117
|
+
expect(type).toEqual('portal:wasm:backup');
|
|
118
|
+
expect(data).toEqual(args);
|
|
119
|
+
expect(origin).toEqual(mockHostOrigin);
|
|
120
|
+
window.dispatchEvent(new MessageEvent('message', {
|
|
121
|
+
origin: mockHostOrigin,
|
|
122
|
+
data: {
|
|
123
|
+
type: 'portal:wasm:backupResult',
|
|
124
|
+
data: {
|
|
125
|
+
cipherText: mockCipherText,
|
|
126
|
+
encryptionKey: 'custom-backup-key',
|
|
127
|
+
backupIds: mockBackupIds,
|
|
128
|
+
},
|
|
129
|
+
},
|
|
130
|
+
}));
|
|
131
|
+
});
|
|
132
|
+
mpc
|
|
133
|
+
.backup(args)
|
|
134
|
+
.then((res) => __awaiter(void 0, void 0, void 0, function* () {
|
|
135
|
+
expect(res.cipherText).toEqual(mockCipherText);
|
|
136
|
+
expect(res.encryptionKey).toEqual('custom-backup-key');
|
|
137
|
+
yield res.storageCallback();
|
|
138
|
+
expect(setBackupStatusSpy).toHaveBeenCalledTimes(1);
|
|
139
|
+
expect(setBackupStatusSpy).toHaveBeenCalledWith('STORED_CLIENT_BACKUP_SHARE', mockBackupIds);
|
|
140
|
+
done();
|
|
141
|
+
}))
|
|
142
|
+
.catch((e) => {
|
|
143
|
+
console.error(e);
|
|
144
|
+
expect(0).toEqual(1);
|
|
145
|
+
done();
|
|
146
|
+
})
|
|
147
|
+
.finally(() => {
|
|
148
|
+
setBackupStatusSpy.mockRestore();
|
|
149
|
+
});
|
|
150
|
+
});
|
|
99
151
|
it('should error out if the iframe sends an error message', (done) => {
|
|
100
152
|
var _a;
|
|
101
153
|
jest
|
|
@@ -207,7 +259,7 @@ describe('Mpc', () => {
|
|
|
207
259
|
})
|
|
208
260
|
.catch((e) => {
|
|
209
261
|
expect(e).toBeInstanceOf(Error);
|
|
210
|
-
expect(e.message).toEqual('Invalid backup method: INVALID_METHOD. Valid methods are: GDRIVE, PASSWORD, PASSKEY, UNKNOWN');
|
|
262
|
+
expect(e.message).toEqual('Invalid backup method: INVALID_METHOD. Valid methods are: GDRIVE, PASSWORD, PASSKEY, CUSTOM, UNKNOWN');
|
|
211
263
|
done();
|
|
212
264
|
});
|
|
213
265
|
});
|
|
@@ -1246,7 +1298,7 @@ describe('Mpc', () => {
|
|
|
1246
1298
|
}));
|
|
1247
1299
|
});
|
|
1248
1300
|
mpc
|
|
1249
|
-
.getQuote(
|
|
1301
|
+
.getQuote('eip155:1', mockQuoteArgs, mockApikey)
|
|
1250
1302
|
.then((data) => {
|
|
1251
1303
|
expect(data).toEqual(res);
|
|
1252
1304
|
done();
|
|
@@ -1281,7 +1333,7 @@ describe('Mpc', () => {
|
|
|
1281
1333
|
}));
|
|
1282
1334
|
});
|
|
1283
1335
|
mpc
|
|
1284
|
-
.getQuote(
|
|
1336
|
+
.getQuote('eip155:1', mockQuoteArgs, mockApikey)
|
|
1285
1337
|
.then(() => {
|
|
1286
1338
|
expect(0).toEqual(1);
|
|
1287
1339
|
done();
|
|
@@ -1314,7 +1366,7 @@ describe('Mpc', () => {
|
|
|
1314
1366
|
}));
|
|
1315
1367
|
});
|
|
1316
1368
|
mpc
|
|
1317
|
-
.getSources(
|
|
1369
|
+
.getSources('eip155:1', mockApikey)
|
|
1318
1370
|
.then((data) => {
|
|
1319
1371
|
expect(data).toEqual(res);
|
|
1320
1372
|
done();
|
|
@@ -1345,7 +1397,7 @@ describe('Mpc', () => {
|
|
|
1345
1397
|
}));
|
|
1346
1398
|
});
|
|
1347
1399
|
mpc
|
|
1348
|
-
.getSources(
|
|
1400
|
+
.getSources('eip155:1', mockApikey)
|
|
1349
1401
|
.then(() => {
|
|
1350
1402
|
expect(0).toEqual(1);
|
|
1351
1403
|
done();
|
|
@@ -2493,4 +2545,741 @@ describe('Mpc', () => {
|
|
|
2493
2545
|
});
|
|
2494
2546
|
});
|
|
2495
2547
|
});
|
|
2548
|
+
describe('getSwapsQuoteV2', () => {
|
|
2549
|
+
const args = mockZeroExQuoteV2Request;
|
|
2550
|
+
const options = mockZeroExOptions;
|
|
2551
|
+
const res = mockZeroExQuoteV2Response;
|
|
2552
|
+
it('should successfully return the quote', (done) => {
|
|
2553
|
+
var _a;
|
|
2554
|
+
jest
|
|
2555
|
+
.spyOn((_a = mpc.iframe) === null || _a === void 0 ? void 0 : _a.contentWindow, 'postMessage')
|
|
2556
|
+
.mockImplementation((message, origin) => {
|
|
2557
|
+
const { type, data } = message;
|
|
2558
|
+
expect(type).toEqual('portal:swaps:getQuoteV2');
|
|
2559
|
+
expect(data).toEqual(Object.assign(Object.assign({}, args), { options }));
|
|
2560
|
+
expect(origin).toEqual(mockHostOrigin);
|
|
2561
|
+
window.dispatchEvent(new MessageEvent('message', {
|
|
2562
|
+
origin: mockHostOrigin,
|
|
2563
|
+
data: {
|
|
2564
|
+
type: 'portal:swaps:getQuoteV2Result',
|
|
2565
|
+
data: res,
|
|
2566
|
+
},
|
|
2567
|
+
}));
|
|
2568
|
+
});
|
|
2569
|
+
mpc
|
|
2570
|
+
.getSwapsQuoteV2(args, options)
|
|
2571
|
+
.then((data) => {
|
|
2572
|
+
expect(data).toEqual(res);
|
|
2573
|
+
done();
|
|
2574
|
+
})
|
|
2575
|
+
.catch((_) => {
|
|
2576
|
+
expect(0).toEqual(1);
|
|
2577
|
+
done();
|
|
2578
|
+
});
|
|
2579
|
+
});
|
|
2580
|
+
it('should successfully return the quote without options', (done) => {
|
|
2581
|
+
var _a;
|
|
2582
|
+
jest
|
|
2583
|
+
.spyOn((_a = mpc.iframe) === null || _a === void 0 ? void 0 : _a.contentWindow, 'postMessage')
|
|
2584
|
+
.mockImplementation((message, origin) => {
|
|
2585
|
+
const { type, data } = message;
|
|
2586
|
+
expect(type).toEqual('portal:swaps:getQuoteV2');
|
|
2587
|
+
expect(data).toEqual(Object.assign(Object.assign({}, args), { options: undefined }));
|
|
2588
|
+
expect(origin).toEqual(mockHostOrigin);
|
|
2589
|
+
window.dispatchEvent(new MessageEvent('message', {
|
|
2590
|
+
origin: mockHostOrigin,
|
|
2591
|
+
data: {
|
|
2592
|
+
type: 'portal:swaps:getQuoteV2Result',
|
|
2593
|
+
data: res,
|
|
2594
|
+
},
|
|
2595
|
+
}));
|
|
2596
|
+
});
|
|
2597
|
+
mpc
|
|
2598
|
+
.getSwapsQuoteV2(args)
|
|
2599
|
+
.then((data) => {
|
|
2600
|
+
expect(data).toEqual(res);
|
|
2601
|
+
done();
|
|
2602
|
+
})
|
|
2603
|
+
.catch((_) => {
|
|
2604
|
+
expect(0).toEqual(1);
|
|
2605
|
+
done();
|
|
2606
|
+
});
|
|
2607
|
+
});
|
|
2608
|
+
it('should error out if the iframe sends an error message', (done) => {
|
|
2609
|
+
var _a;
|
|
2610
|
+
jest
|
|
2611
|
+
.spyOn((_a = mpc.iframe) === null || _a === void 0 ? void 0 : _a.contentWindow, 'postMessage')
|
|
2612
|
+
.mockImplementationOnce((message, origin) => {
|
|
2613
|
+
const { type, data } = message;
|
|
2614
|
+
expect(type).toEqual('portal:swaps:getQuoteV2');
|
|
2615
|
+
expect(data).toEqual(Object.assign(Object.assign({}, args), { options }));
|
|
2616
|
+
expect(origin).toEqual(mockHostOrigin);
|
|
2617
|
+
window.dispatchEvent(new MessageEvent('message', {
|
|
2618
|
+
origin: mockHostOrigin,
|
|
2619
|
+
data: {
|
|
2620
|
+
type: 'portal:swaps:getQuoteV2Error',
|
|
2621
|
+
data: {
|
|
2622
|
+
code: 1,
|
|
2623
|
+
message: 'test',
|
|
2624
|
+
},
|
|
2625
|
+
},
|
|
2626
|
+
}));
|
|
2627
|
+
});
|
|
2628
|
+
mpc
|
|
2629
|
+
.getSwapsQuoteV2(args, options)
|
|
2630
|
+
.then(() => {
|
|
2631
|
+
expect(0).toEqual(1);
|
|
2632
|
+
done();
|
|
2633
|
+
})
|
|
2634
|
+
.catch((e) => {
|
|
2635
|
+
expect(e).toBeInstanceOf(PortalMpcError);
|
|
2636
|
+
expect(e.message).toEqual('test');
|
|
2637
|
+
expect(e.code).toEqual(1);
|
|
2638
|
+
done();
|
|
2639
|
+
});
|
|
2640
|
+
});
|
|
2641
|
+
});
|
|
2642
|
+
describe('getSwapsSourcesV2', () => {
|
|
2643
|
+
const args = mockZeroExSourcesV2Request;
|
|
2644
|
+
const options = mockZeroExOptions;
|
|
2645
|
+
const res = mockZeroExSourcesV2Response;
|
|
2646
|
+
it('should successfully return the sources', (done) => {
|
|
2647
|
+
var _a;
|
|
2648
|
+
jest
|
|
2649
|
+
.spyOn((_a = mpc.iframe) === null || _a === void 0 ? void 0 : _a.contentWindow, 'postMessage')
|
|
2650
|
+
.mockImplementation((message, origin) => {
|
|
2651
|
+
const { type, data } = message;
|
|
2652
|
+
expect(type).toEqual('portal:swaps:getSourcesV2');
|
|
2653
|
+
expect(data).toEqual(Object.assign(Object.assign({}, args), { options }));
|
|
2654
|
+
expect(origin).toEqual(mockHostOrigin);
|
|
2655
|
+
window.dispatchEvent(new MessageEvent('message', {
|
|
2656
|
+
origin: mockHostOrigin,
|
|
2657
|
+
data: {
|
|
2658
|
+
type: 'portal:swaps:getSourcesV2Result',
|
|
2659
|
+
data: res,
|
|
2660
|
+
},
|
|
2661
|
+
}));
|
|
2662
|
+
});
|
|
2663
|
+
mpc
|
|
2664
|
+
.getSwapsSourcesV2(args, options)
|
|
2665
|
+
.then((data) => {
|
|
2666
|
+
expect(data).toEqual(res);
|
|
2667
|
+
done();
|
|
2668
|
+
})
|
|
2669
|
+
.catch((_) => {
|
|
2670
|
+
expect(0).toEqual(1);
|
|
2671
|
+
done();
|
|
2672
|
+
});
|
|
2673
|
+
});
|
|
2674
|
+
it('should successfully return the sources without options', (done) => {
|
|
2675
|
+
var _a;
|
|
2676
|
+
jest
|
|
2677
|
+
.spyOn((_a = mpc.iframe) === null || _a === void 0 ? void 0 : _a.contentWindow, 'postMessage')
|
|
2678
|
+
.mockImplementation((message, origin) => {
|
|
2679
|
+
const { type, data } = message;
|
|
2680
|
+
expect(type).toEqual('portal:swaps:getSourcesV2');
|
|
2681
|
+
expect(data).toEqual(Object.assign(Object.assign({}, args), { options: undefined }));
|
|
2682
|
+
expect(origin).toEqual(mockHostOrigin);
|
|
2683
|
+
window.dispatchEvent(new MessageEvent('message', {
|
|
2684
|
+
origin: mockHostOrigin,
|
|
2685
|
+
data: {
|
|
2686
|
+
type: 'portal:swaps:getSourcesV2Result',
|
|
2687
|
+
data: res,
|
|
2688
|
+
},
|
|
2689
|
+
}));
|
|
2690
|
+
});
|
|
2691
|
+
mpc
|
|
2692
|
+
.getSwapsSourcesV2(args)
|
|
2693
|
+
.then((data) => {
|
|
2694
|
+
expect(data).toEqual(res);
|
|
2695
|
+
done();
|
|
2696
|
+
})
|
|
2697
|
+
.catch((_) => {
|
|
2698
|
+
expect(0).toEqual(1);
|
|
2699
|
+
done();
|
|
2700
|
+
});
|
|
2701
|
+
});
|
|
2702
|
+
it('should error out if the iframe sends an error message', (done) => {
|
|
2703
|
+
var _a;
|
|
2704
|
+
jest
|
|
2705
|
+
.spyOn((_a = mpc.iframe) === null || _a === void 0 ? void 0 : _a.contentWindow, 'postMessage')
|
|
2706
|
+
.mockImplementationOnce((message, origin) => {
|
|
2707
|
+
const { type, data } = message;
|
|
2708
|
+
expect(type).toEqual('portal:swaps:getSourcesV2');
|
|
2709
|
+
expect(data).toEqual(Object.assign(Object.assign({}, args), { options }));
|
|
2710
|
+
expect(origin).toEqual(mockHostOrigin);
|
|
2711
|
+
window.dispatchEvent(new MessageEvent('message', {
|
|
2712
|
+
origin: mockHostOrigin,
|
|
2713
|
+
data: {
|
|
2714
|
+
type: 'portal:swaps:getSourcesV2Error',
|
|
2715
|
+
data: {
|
|
2716
|
+
code: 1,
|
|
2717
|
+
message: 'test',
|
|
2718
|
+
},
|
|
2719
|
+
},
|
|
2720
|
+
}));
|
|
2721
|
+
});
|
|
2722
|
+
mpc
|
|
2723
|
+
.getSwapsSourcesV2(args, options)
|
|
2724
|
+
.then(() => {
|
|
2725
|
+
expect(0).toEqual(1);
|
|
2726
|
+
done();
|
|
2727
|
+
})
|
|
2728
|
+
.catch((e) => {
|
|
2729
|
+
expect(e).toBeInstanceOf(PortalMpcError);
|
|
2730
|
+
expect(e.message).toEqual('test');
|
|
2731
|
+
expect(e.code).toEqual(1);
|
|
2732
|
+
done();
|
|
2733
|
+
});
|
|
2734
|
+
});
|
|
2735
|
+
});
|
|
2736
|
+
describe('getSwapsPrice', () => {
|
|
2737
|
+
const args = mockZeroExPriceRequest;
|
|
2738
|
+
const options = mockZeroExOptions;
|
|
2739
|
+
const res = mockZeroExPriceResponse;
|
|
2740
|
+
it('should successfully return the price', (done) => {
|
|
2741
|
+
var _a;
|
|
2742
|
+
jest
|
|
2743
|
+
.spyOn((_a = mpc.iframe) === null || _a === void 0 ? void 0 : _a.contentWindow, 'postMessage')
|
|
2744
|
+
.mockImplementation((message, origin) => {
|
|
2745
|
+
const { type, data } = message;
|
|
2746
|
+
expect(type).toEqual('portal:swaps:getPrice');
|
|
2747
|
+
expect(data).toEqual(Object.assign(Object.assign({}, args), { options }));
|
|
2748
|
+
expect(origin).toEqual(mockHostOrigin);
|
|
2749
|
+
window.dispatchEvent(new MessageEvent('message', {
|
|
2750
|
+
origin: mockHostOrigin,
|
|
2751
|
+
data: {
|
|
2752
|
+
type: 'portal:swaps:getPriceResult',
|
|
2753
|
+
data: res,
|
|
2754
|
+
},
|
|
2755
|
+
}));
|
|
2756
|
+
});
|
|
2757
|
+
mpc
|
|
2758
|
+
.getSwapsPrice(args, options)
|
|
2759
|
+
.then((data) => {
|
|
2760
|
+
expect(data).toEqual(res);
|
|
2761
|
+
done();
|
|
2762
|
+
})
|
|
2763
|
+
.catch((_) => {
|
|
2764
|
+
expect(0).toEqual(1);
|
|
2765
|
+
done();
|
|
2766
|
+
});
|
|
2767
|
+
});
|
|
2768
|
+
it('should successfully return the price without options', (done) => {
|
|
2769
|
+
var _a;
|
|
2770
|
+
jest
|
|
2771
|
+
.spyOn((_a = mpc.iframe) === null || _a === void 0 ? void 0 : _a.contentWindow, 'postMessage')
|
|
2772
|
+
.mockImplementation((message, origin) => {
|
|
2773
|
+
const { type, data } = message;
|
|
2774
|
+
expect(type).toEqual('portal:swaps:getPrice');
|
|
2775
|
+
expect(data).toEqual(Object.assign(Object.assign({}, args), { options: undefined }));
|
|
2776
|
+
expect(origin).toEqual(mockHostOrigin);
|
|
2777
|
+
window.dispatchEvent(new MessageEvent('message', {
|
|
2778
|
+
origin: mockHostOrigin,
|
|
2779
|
+
data: {
|
|
2780
|
+
type: 'portal:swaps:getPriceResult',
|
|
2781
|
+
data: res,
|
|
2782
|
+
},
|
|
2783
|
+
}));
|
|
2784
|
+
});
|
|
2785
|
+
mpc
|
|
2786
|
+
.getSwapsPrice(args)
|
|
2787
|
+
.then((data) => {
|
|
2788
|
+
expect(data).toEqual(res);
|
|
2789
|
+
done();
|
|
2790
|
+
})
|
|
2791
|
+
.catch((_) => {
|
|
2792
|
+
expect(0).toEqual(1);
|
|
2793
|
+
done();
|
|
2794
|
+
});
|
|
2795
|
+
});
|
|
2796
|
+
it('should error out if the iframe sends an error message', (done) => {
|
|
2797
|
+
var _a;
|
|
2798
|
+
jest
|
|
2799
|
+
.spyOn((_a = mpc.iframe) === null || _a === void 0 ? void 0 : _a.contentWindow, 'postMessage')
|
|
2800
|
+
.mockImplementationOnce((message, origin) => {
|
|
2801
|
+
const { type, data } = message;
|
|
2802
|
+
expect(type).toEqual('portal:swaps:getPrice');
|
|
2803
|
+
expect(data).toEqual(Object.assign(Object.assign({}, args), { options }));
|
|
2804
|
+
expect(origin).toEqual(mockHostOrigin);
|
|
2805
|
+
window.dispatchEvent(new MessageEvent('message', {
|
|
2806
|
+
origin: mockHostOrigin,
|
|
2807
|
+
data: {
|
|
2808
|
+
type: 'portal:swaps:getPriceError',
|
|
2809
|
+
data: {
|
|
2810
|
+
code: 1,
|
|
2811
|
+
message: 'test',
|
|
2812
|
+
},
|
|
2813
|
+
},
|
|
2814
|
+
}));
|
|
2815
|
+
});
|
|
2816
|
+
mpc
|
|
2817
|
+
.getSwapsPrice(args, options)
|
|
2818
|
+
.then(() => {
|
|
2819
|
+
expect(0).toEqual(1);
|
|
2820
|
+
done();
|
|
2821
|
+
})
|
|
2822
|
+
.catch((e) => {
|
|
2823
|
+
expect(e).toBeInstanceOf(PortalMpcError);
|
|
2824
|
+
expect(e.message).toEqual('test');
|
|
2825
|
+
expect(e.code).toEqual(1);
|
|
2826
|
+
done();
|
|
2827
|
+
});
|
|
2828
|
+
});
|
|
2829
|
+
});
|
|
2830
|
+
describe('scanAddresses', () => {
|
|
2831
|
+
const args = mockScanAddressesRequest;
|
|
2832
|
+
const res = mockScanAddressesResponse;
|
|
2833
|
+
it('should successfully scan addresses', (done) => {
|
|
2834
|
+
var _a;
|
|
2835
|
+
jest
|
|
2836
|
+
.spyOn((_a = mpc.iframe) === null || _a === void 0 ? void 0 : _a.contentWindow, 'postMessage')
|
|
2837
|
+
.mockImplementation((message, origin) => {
|
|
2838
|
+
const { type, data } = message;
|
|
2839
|
+
expect(type).toEqual('portal:security:scanAddresses');
|
|
2840
|
+
expect(data).toEqual(args);
|
|
2841
|
+
expect(origin).toEqual(mockHostOrigin);
|
|
2842
|
+
window.dispatchEvent(new MessageEvent('message', {
|
|
2843
|
+
origin: mockHostOrigin,
|
|
2844
|
+
data: {
|
|
2845
|
+
type: 'portal:security:scanAddressesResult',
|
|
2846
|
+
data: res,
|
|
2847
|
+
},
|
|
2848
|
+
}));
|
|
2849
|
+
});
|
|
2850
|
+
mpc
|
|
2851
|
+
.scanAddresses(args)
|
|
2852
|
+
.then((data) => {
|
|
2853
|
+
expect(data).toEqual(res);
|
|
2854
|
+
done();
|
|
2855
|
+
})
|
|
2856
|
+
.catch((_) => {
|
|
2857
|
+
expect(0).toEqual(1);
|
|
2858
|
+
done();
|
|
2859
|
+
});
|
|
2860
|
+
});
|
|
2861
|
+
it('should error out if the iframe sends an error message', (done) => {
|
|
2862
|
+
var _a;
|
|
2863
|
+
jest
|
|
2864
|
+
.spyOn((_a = mpc.iframe) === null || _a === void 0 ? void 0 : _a.contentWindow, 'postMessage')
|
|
2865
|
+
.mockImplementationOnce((message, origin) => {
|
|
2866
|
+
const { type, data } = message;
|
|
2867
|
+
expect(type).toEqual('portal:security:scanAddresses');
|
|
2868
|
+
expect(data).toEqual(args);
|
|
2869
|
+
expect(origin).toEqual(mockHostOrigin);
|
|
2870
|
+
window.dispatchEvent(new MessageEvent('message', {
|
|
2871
|
+
origin: mockHostOrigin,
|
|
2872
|
+
data: {
|
|
2873
|
+
type: 'portal:security:scanAddressesError',
|
|
2874
|
+
data: {
|
|
2875
|
+
code: 1,
|
|
2876
|
+
message: 'test',
|
|
2877
|
+
},
|
|
2878
|
+
},
|
|
2879
|
+
}));
|
|
2880
|
+
});
|
|
2881
|
+
mpc
|
|
2882
|
+
.scanAddresses(args)
|
|
2883
|
+
.then(() => {
|
|
2884
|
+
expect(0).toEqual(1);
|
|
2885
|
+
done();
|
|
2886
|
+
})
|
|
2887
|
+
.catch((e) => {
|
|
2888
|
+
expect(e).toBeInstanceOf(PortalMpcError);
|
|
2889
|
+
expect(e.message).toEqual('test');
|
|
2890
|
+
expect(e.code).toEqual(1);
|
|
2891
|
+
done();
|
|
2892
|
+
});
|
|
2893
|
+
});
|
|
2894
|
+
});
|
|
2895
|
+
describe('scanEVMTx', () => {
|
|
2896
|
+
const args = mockScanEVMTxRequest;
|
|
2897
|
+
const res = mockScanEVMTxResponse;
|
|
2898
|
+
it('should successfully scan EIP-155 transaction', (done) => {
|
|
2899
|
+
var _a;
|
|
2900
|
+
jest
|
|
2901
|
+
.spyOn((_a = mpc.iframe) === null || _a === void 0 ? void 0 : _a.contentWindow, 'postMessage')
|
|
2902
|
+
.mockImplementation((message, origin) => {
|
|
2903
|
+
const { type, data } = message;
|
|
2904
|
+
expect(type).toEqual('portal:security:scanEVMTx');
|
|
2905
|
+
expect(data).toEqual(args);
|
|
2906
|
+
expect(origin).toEqual(mockHostOrigin);
|
|
2907
|
+
window.dispatchEvent(new MessageEvent('message', {
|
|
2908
|
+
origin: mockHostOrigin,
|
|
2909
|
+
data: {
|
|
2910
|
+
type: 'portal:security:scanEVMTxResult',
|
|
2911
|
+
data: res,
|
|
2912
|
+
},
|
|
2913
|
+
}));
|
|
2914
|
+
});
|
|
2915
|
+
mpc
|
|
2916
|
+
.scanEVMTx(args)
|
|
2917
|
+
.then((data) => {
|
|
2918
|
+
expect(data).toEqual(res);
|
|
2919
|
+
done();
|
|
2920
|
+
})
|
|
2921
|
+
.catch((_) => {
|
|
2922
|
+
expect(0).toEqual(1);
|
|
2923
|
+
done();
|
|
2924
|
+
});
|
|
2925
|
+
});
|
|
2926
|
+
it('should error out if the iframe sends an error message', (done) => {
|
|
2927
|
+
var _a;
|
|
2928
|
+
jest
|
|
2929
|
+
.spyOn((_a = mpc.iframe) === null || _a === void 0 ? void 0 : _a.contentWindow, 'postMessage')
|
|
2930
|
+
.mockImplementationOnce((message, origin) => {
|
|
2931
|
+
const { type, data } = message;
|
|
2932
|
+
expect(type).toEqual('portal:security:scanEVMTx');
|
|
2933
|
+
expect(data).toEqual(args);
|
|
2934
|
+
expect(origin).toEqual(mockHostOrigin);
|
|
2935
|
+
window.dispatchEvent(new MessageEvent('message', {
|
|
2936
|
+
origin: mockHostOrigin,
|
|
2937
|
+
data: {
|
|
2938
|
+
type: 'portal:security:scanEVMTxError',
|
|
2939
|
+
data: {
|
|
2940
|
+
code: 1,
|
|
2941
|
+
message: 'test',
|
|
2942
|
+
},
|
|
2943
|
+
},
|
|
2944
|
+
}));
|
|
2945
|
+
});
|
|
2946
|
+
mpc
|
|
2947
|
+
.scanEVMTx(args)
|
|
2948
|
+
.then(() => {
|
|
2949
|
+
expect(0).toEqual(1);
|
|
2950
|
+
done();
|
|
2951
|
+
})
|
|
2952
|
+
.catch((e) => {
|
|
2953
|
+
expect(e).toBeInstanceOf(PortalMpcError);
|
|
2954
|
+
expect(e.message).toEqual('test');
|
|
2955
|
+
expect(e.code).toEqual(1);
|
|
2956
|
+
done();
|
|
2957
|
+
});
|
|
2958
|
+
});
|
|
2959
|
+
});
|
|
2960
|
+
describe('scanEip712Tx', () => {
|
|
2961
|
+
const args = mockScanEip712TxRequest;
|
|
2962
|
+
const res = mockScanEip712TxResponse;
|
|
2963
|
+
it('should successfully scan EIP-712 transaction', (done) => {
|
|
2964
|
+
var _a;
|
|
2965
|
+
jest
|
|
2966
|
+
.spyOn((_a = mpc.iframe) === null || _a === void 0 ? void 0 : _a.contentWindow, 'postMessage')
|
|
2967
|
+
.mockImplementation((message, origin) => {
|
|
2968
|
+
const { type, data } = message;
|
|
2969
|
+
expect(type).toEqual('portal:security:scanEip712Tx');
|
|
2970
|
+
expect(data).toEqual(args);
|
|
2971
|
+
expect(origin).toEqual(mockHostOrigin);
|
|
2972
|
+
window.dispatchEvent(new MessageEvent('message', {
|
|
2973
|
+
origin: mockHostOrigin,
|
|
2974
|
+
data: {
|
|
2975
|
+
type: 'portal:security:scanEip712TxResult',
|
|
2976
|
+
data: res,
|
|
2977
|
+
},
|
|
2978
|
+
}));
|
|
2979
|
+
});
|
|
2980
|
+
mpc
|
|
2981
|
+
.scanEip712Tx(args)
|
|
2982
|
+
.then((data) => {
|
|
2983
|
+
expect(data).toEqual(res);
|
|
2984
|
+
done();
|
|
2985
|
+
})
|
|
2986
|
+
.catch((_) => {
|
|
2987
|
+
expect(0).toEqual(1);
|
|
2988
|
+
done();
|
|
2989
|
+
});
|
|
2990
|
+
});
|
|
2991
|
+
it('should error out if the iframe sends an error message', (done) => {
|
|
2992
|
+
var _a;
|
|
2993
|
+
jest
|
|
2994
|
+
.spyOn((_a = mpc.iframe) === null || _a === void 0 ? void 0 : _a.contentWindow, 'postMessage')
|
|
2995
|
+
.mockImplementationOnce((message, origin) => {
|
|
2996
|
+
const { type, data } = message;
|
|
2997
|
+
expect(type).toEqual('portal:security:scanEip712Tx');
|
|
2998
|
+
expect(data).toEqual(args);
|
|
2999
|
+
expect(origin).toEqual(mockHostOrigin);
|
|
3000
|
+
window.dispatchEvent(new MessageEvent('message', {
|
|
3001
|
+
origin: mockHostOrigin,
|
|
3002
|
+
data: {
|
|
3003
|
+
type: 'portal:security:scanEip712TxError',
|
|
3004
|
+
data: {
|
|
3005
|
+
code: 1,
|
|
3006
|
+
message: 'test',
|
|
3007
|
+
},
|
|
3008
|
+
},
|
|
3009
|
+
}));
|
|
3010
|
+
});
|
|
3011
|
+
mpc
|
|
3012
|
+
.scanEip712Tx(args)
|
|
3013
|
+
.then(() => {
|
|
3014
|
+
expect(0).toEqual(1);
|
|
3015
|
+
done();
|
|
3016
|
+
})
|
|
3017
|
+
.catch((e) => {
|
|
3018
|
+
expect(e).toBeInstanceOf(PortalMpcError);
|
|
3019
|
+
expect(e.message).toEqual('test');
|
|
3020
|
+
expect(e.code).toEqual(1);
|
|
3021
|
+
done();
|
|
3022
|
+
});
|
|
3023
|
+
});
|
|
3024
|
+
});
|
|
3025
|
+
describe('scanSolanaTx', () => {
|
|
3026
|
+
const args = mockScanSolanaTxRequest;
|
|
3027
|
+
const res = mockScanSolanaTxResponse;
|
|
3028
|
+
it('should successfully scan Solana transaction', (done) => {
|
|
3029
|
+
var _a;
|
|
3030
|
+
jest
|
|
3031
|
+
.spyOn((_a = mpc.iframe) === null || _a === void 0 ? void 0 : _a.contentWindow, 'postMessage')
|
|
3032
|
+
.mockImplementation((message, origin) => {
|
|
3033
|
+
const { type, data } = message;
|
|
3034
|
+
expect(type).toEqual('portal:security:scanSolanaTx');
|
|
3035
|
+
expect(data).toEqual(args);
|
|
3036
|
+
expect(origin).toEqual(mockHostOrigin);
|
|
3037
|
+
window.dispatchEvent(new MessageEvent('message', {
|
|
3038
|
+
origin: mockHostOrigin,
|
|
3039
|
+
data: {
|
|
3040
|
+
type: 'portal:security:scanSolanaTxResult',
|
|
3041
|
+
data: res,
|
|
3042
|
+
},
|
|
3043
|
+
}));
|
|
3044
|
+
});
|
|
3045
|
+
mpc
|
|
3046
|
+
.scanSolanaTx(args)
|
|
3047
|
+
.then((data) => {
|
|
3048
|
+
expect(data).toEqual(res);
|
|
3049
|
+
done();
|
|
3050
|
+
})
|
|
3051
|
+
.catch((_) => {
|
|
3052
|
+
expect(0).toEqual(1);
|
|
3053
|
+
done();
|
|
3054
|
+
});
|
|
3055
|
+
});
|
|
3056
|
+
it('should error out if the iframe sends an error message', (done) => {
|
|
3057
|
+
var _a;
|
|
3058
|
+
jest
|
|
3059
|
+
.spyOn((_a = mpc.iframe) === null || _a === void 0 ? void 0 : _a.contentWindow, 'postMessage')
|
|
3060
|
+
.mockImplementationOnce((message, origin) => {
|
|
3061
|
+
const { type, data } = message;
|
|
3062
|
+
expect(type).toEqual('portal:security:scanSolanaTx');
|
|
3063
|
+
expect(data).toEqual(args);
|
|
3064
|
+
expect(origin).toEqual(mockHostOrigin);
|
|
3065
|
+
window.dispatchEvent(new MessageEvent('message', {
|
|
3066
|
+
origin: mockHostOrigin,
|
|
3067
|
+
data: {
|
|
3068
|
+
type: 'portal:security:scanSolanaTxError',
|
|
3069
|
+
data: {
|
|
3070
|
+
code: 1,
|
|
3071
|
+
message: 'test',
|
|
3072
|
+
},
|
|
3073
|
+
},
|
|
3074
|
+
}));
|
|
3075
|
+
});
|
|
3076
|
+
mpc
|
|
3077
|
+
.scanSolanaTx(args)
|
|
3078
|
+
.then(() => {
|
|
3079
|
+
expect(0).toEqual(1);
|
|
3080
|
+
done();
|
|
3081
|
+
})
|
|
3082
|
+
.catch((e) => {
|
|
3083
|
+
expect(e).toBeInstanceOf(PortalMpcError);
|
|
3084
|
+
expect(e.message).toEqual('test');
|
|
3085
|
+
expect(e.code).toEqual(1);
|
|
3086
|
+
done();
|
|
3087
|
+
});
|
|
3088
|
+
});
|
|
3089
|
+
});
|
|
3090
|
+
describe('scanNft', () => {
|
|
3091
|
+
const args = mockScanNftRequest;
|
|
3092
|
+
const res = mockScanNftResponse;
|
|
3093
|
+
it('should successfully scan NFT', (done) => {
|
|
3094
|
+
var _a;
|
|
3095
|
+
jest
|
|
3096
|
+
.spyOn((_a = mpc.iframe) === null || _a === void 0 ? void 0 : _a.contentWindow, 'postMessage')
|
|
3097
|
+
.mockImplementation((message, origin) => {
|
|
3098
|
+
const { type, data } = message;
|
|
3099
|
+
expect(type).toEqual('portal:security:scanNfts');
|
|
3100
|
+
expect(data).toEqual(args);
|
|
3101
|
+
expect(origin).toEqual(mockHostOrigin);
|
|
3102
|
+
window.dispatchEvent(new MessageEvent('message', {
|
|
3103
|
+
origin: mockHostOrigin,
|
|
3104
|
+
data: {
|
|
3105
|
+
type: 'portal:security:scanNftsResult',
|
|
3106
|
+
data: res,
|
|
3107
|
+
},
|
|
3108
|
+
}));
|
|
3109
|
+
});
|
|
3110
|
+
mpc
|
|
3111
|
+
.scanNFTs(args)
|
|
3112
|
+
.then((data) => {
|
|
3113
|
+
expect(data).toEqual(res);
|
|
3114
|
+
done();
|
|
3115
|
+
})
|
|
3116
|
+
.catch((_) => {
|
|
3117
|
+
expect(0).toEqual(1);
|
|
3118
|
+
done();
|
|
3119
|
+
});
|
|
3120
|
+
});
|
|
3121
|
+
it('should error out if the iframe sends an error message', (done) => {
|
|
3122
|
+
var _a;
|
|
3123
|
+
jest
|
|
3124
|
+
.spyOn((_a = mpc.iframe) === null || _a === void 0 ? void 0 : _a.contentWindow, 'postMessage')
|
|
3125
|
+
.mockImplementationOnce((message, origin) => {
|
|
3126
|
+
const { type, data } = message;
|
|
3127
|
+
expect(type).toEqual('portal:security:scanNfts');
|
|
3128
|
+
expect(data).toEqual(args);
|
|
3129
|
+
expect(origin).toEqual(mockHostOrigin);
|
|
3130
|
+
window.dispatchEvent(new MessageEvent('message', {
|
|
3131
|
+
origin: mockHostOrigin,
|
|
3132
|
+
data: {
|
|
3133
|
+
type: 'portal:security:scanNftsError',
|
|
3134
|
+
data: {
|
|
3135
|
+
code: 1,
|
|
3136
|
+
message: 'test',
|
|
3137
|
+
},
|
|
3138
|
+
},
|
|
3139
|
+
}));
|
|
3140
|
+
});
|
|
3141
|
+
mpc
|
|
3142
|
+
.scanNFTs(args)
|
|
3143
|
+
.then(() => {
|
|
3144
|
+
expect(0).toEqual(1);
|
|
3145
|
+
done();
|
|
3146
|
+
})
|
|
3147
|
+
.catch((e) => {
|
|
3148
|
+
expect(e).toBeInstanceOf(PortalMpcError);
|
|
3149
|
+
expect(e.message).toEqual('test');
|
|
3150
|
+
expect(e.code).toEqual(1);
|
|
3151
|
+
done();
|
|
3152
|
+
});
|
|
3153
|
+
});
|
|
3154
|
+
});
|
|
3155
|
+
describe('scanToken', () => {
|
|
3156
|
+
const args = mockScanTokenRequest;
|
|
3157
|
+
const res = mockScanTokenResponse;
|
|
3158
|
+
it('should successfully scan token', (done) => {
|
|
3159
|
+
var _a;
|
|
3160
|
+
jest
|
|
3161
|
+
.spyOn((_a = mpc.iframe) === null || _a === void 0 ? void 0 : _a.contentWindow, 'postMessage')
|
|
3162
|
+
.mockImplementation((message, origin) => {
|
|
3163
|
+
const { type, data } = message;
|
|
3164
|
+
expect(type).toEqual('portal:security:scanTokens');
|
|
3165
|
+
expect(data).toEqual(args);
|
|
3166
|
+
expect(origin).toEqual(mockHostOrigin);
|
|
3167
|
+
window.dispatchEvent(new MessageEvent('message', {
|
|
3168
|
+
origin: mockHostOrigin,
|
|
3169
|
+
data: {
|
|
3170
|
+
type: 'portal:security:scanTokensResult',
|
|
3171
|
+
data: res,
|
|
3172
|
+
},
|
|
3173
|
+
}));
|
|
3174
|
+
});
|
|
3175
|
+
mpc
|
|
3176
|
+
.scanTokens(args)
|
|
3177
|
+
.then((data) => {
|
|
3178
|
+
expect(data).toEqual(res);
|
|
3179
|
+
done();
|
|
3180
|
+
})
|
|
3181
|
+
.catch((_) => {
|
|
3182
|
+
expect(0).toEqual(1);
|
|
3183
|
+
done();
|
|
3184
|
+
});
|
|
3185
|
+
});
|
|
3186
|
+
it('should error out if the iframe sends an error message', (done) => {
|
|
3187
|
+
var _a;
|
|
3188
|
+
jest
|
|
3189
|
+
.spyOn((_a = mpc.iframe) === null || _a === void 0 ? void 0 : _a.contentWindow, 'postMessage')
|
|
3190
|
+
.mockImplementationOnce((message, origin) => {
|
|
3191
|
+
const { type, data } = message;
|
|
3192
|
+
expect(type).toEqual('portal:security:scanTokens');
|
|
3193
|
+
expect(data).toEqual(args);
|
|
3194
|
+
expect(origin).toEqual(mockHostOrigin);
|
|
3195
|
+
window.dispatchEvent(new MessageEvent('message', {
|
|
3196
|
+
origin: mockHostOrigin,
|
|
3197
|
+
data: {
|
|
3198
|
+
type: 'portal:security:scanTokensError',
|
|
3199
|
+
data: {
|
|
3200
|
+
code: 1,
|
|
3201
|
+
message: 'test',
|
|
3202
|
+
},
|
|
3203
|
+
},
|
|
3204
|
+
}));
|
|
3205
|
+
});
|
|
3206
|
+
mpc
|
|
3207
|
+
.scanTokens(args)
|
|
3208
|
+
.then(() => {
|
|
3209
|
+
expect(0).toEqual(1);
|
|
3210
|
+
done();
|
|
3211
|
+
})
|
|
3212
|
+
.catch((e) => {
|
|
3213
|
+
expect(e).toBeInstanceOf(PortalMpcError);
|
|
3214
|
+
expect(e.message).toEqual('test');
|
|
3215
|
+
expect(e.code).toEqual(1);
|
|
3216
|
+
done();
|
|
3217
|
+
});
|
|
3218
|
+
});
|
|
3219
|
+
});
|
|
3220
|
+
describe('scanUrl', () => {
|
|
3221
|
+
const args = mockScanUrlRequest;
|
|
3222
|
+
const res = mockScanUrlResponse;
|
|
3223
|
+
it('should successfully scan URL', (done) => {
|
|
3224
|
+
var _a;
|
|
3225
|
+
jest
|
|
3226
|
+
.spyOn((_a = mpc.iframe) === null || _a === void 0 ? void 0 : _a.contentWindow, 'postMessage')
|
|
3227
|
+
.mockImplementation((message, origin) => {
|
|
3228
|
+
const { type, data } = message;
|
|
3229
|
+
expect(type).toEqual('portal:security:scanUrl');
|
|
3230
|
+
expect(data).toEqual({ url: args });
|
|
3231
|
+
expect(origin).toEqual(mockHostOrigin);
|
|
3232
|
+
window.dispatchEvent(new MessageEvent('message', {
|
|
3233
|
+
origin: mockHostOrigin,
|
|
3234
|
+
data: {
|
|
3235
|
+
type: 'portal:security:scanUrlResult',
|
|
3236
|
+
data: res,
|
|
3237
|
+
},
|
|
3238
|
+
}));
|
|
3239
|
+
});
|
|
3240
|
+
mpc
|
|
3241
|
+
.scanUrl(args)
|
|
3242
|
+
.then((data) => {
|
|
3243
|
+
expect(data).toEqual(res);
|
|
3244
|
+
done();
|
|
3245
|
+
})
|
|
3246
|
+
.catch((_) => {
|
|
3247
|
+
expect(0).toEqual(1);
|
|
3248
|
+
done();
|
|
3249
|
+
});
|
|
3250
|
+
});
|
|
3251
|
+
it('should error out if the iframe sends an error message', (done) => {
|
|
3252
|
+
var _a;
|
|
3253
|
+
jest
|
|
3254
|
+
.spyOn((_a = mpc.iframe) === null || _a === void 0 ? void 0 : _a.contentWindow, 'postMessage')
|
|
3255
|
+
.mockImplementationOnce((message, origin) => {
|
|
3256
|
+
const { type, data } = message;
|
|
3257
|
+
expect(type).toEqual('portal:security:scanUrl');
|
|
3258
|
+
expect(data).toEqual({ url: args });
|
|
3259
|
+
expect(origin).toEqual(mockHostOrigin);
|
|
3260
|
+
window.dispatchEvent(new MessageEvent('message', {
|
|
3261
|
+
origin: mockHostOrigin,
|
|
3262
|
+
data: {
|
|
3263
|
+
type: 'portal:security:scanUrlError',
|
|
3264
|
+
data: {
|
|
3265
|
+
code: 1,
|
|
3266
|
+
message: 'test',
|
|
3267
|
+
},
|
|
3268
|
+
},
|
|
3269
|
+
}));
|
|
3270
|
+
});
|
|
3271
|
+
mpc
|
|
3272
|
+
.scanUrl(args)
|
|
3273
|
+
.then(() => {
|
|
3274
|
+
expect(0).toEqual(1);
|
|
3275
|
+
done();
|
|
3276
|
+
})
|
|
3277
|
+
.catch((e) => {
|
|
3278
|
+
expect(e).toBeInstanceOf(PortalMpcError);
|
|
3279
|
+
expect(e.message).toEqual('test');
|
|
3280
|
+
expect(e.code).toEqual(1);
|
|
3281
|
+
done();
|
|
3282
|
+
});
|
|
3283
|
+
});
|
|
3284
|
+
});
|
|
2496
3285
|
});
|