Skip to content
Draft
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -60,7 +60,7 @@ exports[`BridgeController BatchSell (multiple quote requests) SSE fetch quotes s
}
`;

exports[`BridgeController BatchSell (multiple quote requests) SSE fetch quotes should trigger quote polling if request is valid 2`] = `
exports[`BridgeController BatchSell (multiple quote requests) SSE fetch quotes should trigger quote polling if request is valid 3`] = `
[
[
"Unified SwapBridge Input Changed",
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -9,16 +9,24 @@ exports[`BridgeController SSE should publish validation failures 4`] = `
"chain_id_destination": "solana:5eykt4UsFv8P8NJdTREpY1vzqKqZKvdp",
"chain_id_source": "eip155:1",
"failures": [
"lifi|trade",
"lifi|unknown",
"lifi|quote.src",
"lifi|quote.dest",
"lifi|quote.feeData.metabridge",
"lifi|quote.aggregator",
"lifi|quote.protocols",
"lifi|namespace",
"lifi|chainId",
"lifi|trade.chainId",
"lifi|trade.to",
"lifi|trade.from",
"lifi|trade.value",
"lifi|trade.data",
"lifi|trade.gasLimit",
"lifi|trade",
"lifi|trade.raw_data_hex",
"lifi|trade.unsignedPsbtBase64",
"lifi|trade.inputsToSign",
"lifi|trade.raw_data_hex",
],
"feature_id": "unified_swap_bridge",
"location": "Main View",
Expand Down Expand Up @@ -52,7 +60,14 @@ exports[`BridgeController SSE should publish validation failures 4`] = `
"chain_id_destination": "solana:5eykt4UsFv8P8NJdTREpY1vzqKqZKvdp",
"chain_id_source": "eip155:1",
"failures": [
"unknown|unknown",
"unknown|quote",
"unknown|namespace",
"unknown|chainId",
"unknown|trade",
"unknown|trade.raw_data_hex",
"unknown|trade.unsignedPsbtBase64",
"unknown|trade.inputsToSign",
],
"feature_id": "unified_swap_bridge",
"location": "Main View",
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -7,8 +7,14 @@ import type {
} from '@metamask/messenger';

import { flushPromises } from '../../../tests/helpers';
import { mockBridgeQuotesErc20Erc20V1 } from '../tests/mock-quotes-erc20-erc20';
import { mockBridgeQuotesNativeErc20V1 } from '../tests/mock-quotes-native-erc20';
import {
getMockBridgeQuotesErc20Erc20V2,
mockBridgeQuotesErc20Erc20V1,
} from '../tests/mock-quotes-erc20-erc20';
import {
getMockBridgeQuotesNativeErc20V2,
mockBridgeQuotesNativeErc20V1,
} from '../tests/mock-quotes-native-erc20';
import {
advanceToNthTimerThenFlush,
mockSseBatchSellEventSource,
Expand Down Expand Up @@ -213,6 +219,7 @@ describe('BridgeController BatchSell (multiple quote requests) SSE', function ()
});

it('should trigger quote polling if request is valid', async function () {
const consoleWarnSpy = jest.spyOn(console, 'warn');
await withController(
async ({
controller: bridgeController,
Expand All @@ -227,7 +234,10 @@ describe('BridgeController BatchSell (multiple quote requests) SSE', function ()
mockFetchFn.mockImplementationOnce(async () => {
return mockSseBatchSellEventSource([
mockBridgeQuotesNativeErc20V1,
mockBridgeQuotesErc20Erc20V1,
mockBridgeQuotesErc20Erc20V1.map((quote) => ({
...quote,
quoteRequestIndex: 1,
})),
]);
});
hasSufficientBalanceSpy.mockResolvedValue(true);
Expand Down Expand Up @@ -399,6 +409,7 @@ describe('BridgeController BatchSell (multiple quote requests) SSE', function ()
// After first fetch
jest.advanceTimersByTime(5000);
await flushPromises();
expect(consoleWarnSpy.mock.calls).toMatchInlineSnapshot(`[]`);
expect(fetchAssetPricesSpy).toHaveBeenCalledTimes(1);
expect(bridgeController.state).toStrictEqual({
...expectedState,
Expand All @@ -420,7 +431,7 @@ describe('BridgeController BatchSell (multiple quote requests) SSE', function ()
resetApproval: false,
},
],
quotes: mockBridgeQuotesNativeErc20V1
quotes: getMockBridgeQuotesNativeErc20V2()
.map((quote) => ({
...quote,
l1GasFeesInHexWei: '0x1',
Expand All @@ -429,13 +440,15 @@ describe('BridgeController BatchSell (multiple quote requests) SSE', function ()
featureId: FeatureId.BATCH_SELL,
}))
.concat(
mockBridgeQuotesErc20Erc20V1.map((quote) => ({
...quote,
l1GasFeesInHexWei: '0x2',
resetApproval: undefined,
quoteRequestIndex: 1,
featureId: FeatureId.BATCH_SELL,
})),
getMockBridgeQuotesErc20Erc20V2({ quoteRequestIndex: 1 }).map(
(quote) => ({
...quote,
l1GasFeesInHexWei: '0x2',
resetApproval: undefined,
quoteRequestIndex: 1,
featureId: FeatureId.BATCH_SELL,
}),
),
),
quotesRefreshCount: 1,
quotesLoadingStatus: 1,
Expand Down Expand Up @@ -644,7 +657,7 @@ describe('BridgeController BatchSell (multiple quote requests) SSE', function ()
);
await rootMessenger.call(
'BridgeController:updateBatchSellTrades',
mockBridgeQuotesErc20Erc20V1,
getMockBridgeQuotesErc20Erc20V2(),
false,
);

Expand Down Expand Up @@ -684,7 +697,7 @@ describe('BridgeController BatchSell (multiple quote requests) SSE', function ()
'13.8.0',
]);
expect(fetchBatchSellTradesSpy.mock.calls[1]).toStrictEqual([
mockBridgeQuotesErc20Erc20V1,
getMockBridgeQuotesErc20Erc20V2(),
false,
expect.any(AbortSignal),
'extension',
Expand Down Expand Up @@ -881,7 +894,7 @@ describe('BridgeController BatchSell (multiple quote requests) SSE', function ()
// 2nd fetch
await rootMessenger.call(
'BridgeController:updateBatchSellTrades',
mockBridgeQuotesErc20Erc20V1,
getMockBridgeQuotesErc20Erc20V2(),
false,
);

Expand All @@ -891,7 +904,7 @@ describe('BridgeController BatchSell (multiple quote requests) SSE', function ()
expect(stopAllPollingSpy).toHaveBeenCalledTimes(0);
expect(abortControllerSpy).toHaveBeenCalledTimes(1);
expect(fetchBatchSellTradesSpy.mock.calls[1][0]).toStrictEqual(
mockBridgeQuotesErc20Erc20V1,
getMockBridgeQuotesErc20Erc20V2(),
);
expect(startPollingSpy).not.toHaveBeenCalled();
expect(bridgeController.state.batchSellTrades).toBeNull();
Expand Down
Loading
Loading