Skip to content

Commit

Permalink
chore: wire up quote selector to bridge tx submission action
Browse files Browse the repository at this point in the history
  • Loading branch information
infiniteflower committed Oct 15, 2024
1 parent 4d6bab4 commit 9c4ed4d
Show file tree
Hide file tree
Showing 5 changed files with 93 additions and 78 deletions.
95 changes: 53 additions & 42 deletions ui/ducks/bridge/actions.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,6 @@ import * as actions from '../../store/actions';
import * as selectors from '../../selectors';
import { submitBridgeTransaction } from './actions';
import { DummyQuotesNoApproval, DummyQuotesWithApproval } from './dummy-quotes';
import * as bridgeSelectors from './selectors';

jest.mock('../../store/actions', () => {
const original = jest.requireActual('../../store/actions');
Expand All @@ -18,13 +17,6 @@ jest.mock('../../store/actions', () => {
};
});

jest.mock('./selectors', () => {
const original = jest.requireActual('./selectors');
return {
...original,
getQuotes: jest.fn(),
};
});
jest.mock('../../selectors', () => {
const original = jest.requireActual('../../selectors');
return {
Expand Down Expand Up @@ -119,10 +111,6 @@ describe('bridge/actions', () => {
};
});

(bridgeSelectors.getQuotes as jest.Mock).mockImplementation(
() => DummyQuotesWithApproval.ETH_11_USDC_TO_ARB,
);

// For some reason, setBackgroundConnection does not work, gets hung up on the promise, so mock this way instead
(actions.addTransactionAndWaitForPublish as jest.Mock).mockImplementation(
mockAddTransactionAndWaitForPublish,
Expand All @@ -131,7 +119,12 @@ describe('bridge/actions', () => {
const history = makeMockHistory();

// Execute
await store.dispatch(submitBridgeTransaction(history as any) as any);
await store.dispatch(
submitBridgeTransaction(
DummyQuotesWithApproval.ETH_11_USDC_TO_ARB[0] as any,
history as any,
) as any,
);

// Assert
expect(mockAddTransactionAndWaitForPublish).toHaveBeenLastCalledWith(
Expand Down Expand Up @@ -173,10 +166,6 @@ describe('bridge/actions', () => {
};
});

(bridgeSelectors.getQuotes as jest.Mock).mockImplementation(
() => DummyQuotesWithApproval.ETH_11_USDC_TO_ARB,
);

// For some reason, setBackgroundConnection does not work, gets hung up on the promise, so mock this way instead
(actions.addTransactionAndWaitForPublish as jest.Mock).mockImplementation(
mockAddTransactionAndWaitForPublish,
Expand All @@ -185,7 +174,12 @@ describe('bridge/actions', () => {
const history = makeMockHistory();

// Execute
await store.dispatch(submitBridgeTransaction(history as any) as any);
await store.dispatch(
submitBridgeTransaction(
DummyQuotesWithApproval.ETH_11_USDC_TO_ARB[0] as any,
history as any,
) as any,
);

// Assert
expect(mockAddTransactionAndWaitForPublish).toHaveBeenNthCalledWith(
Expand Down Expand Up @@ -247,15 +241,17 @@ describe('bridge/actions', () => {
const store = makeMockStore();
const history = makeMockHistory();

(bridgeSelectors.getQuotes as jest.Mock).mockImplementation(
() => DummyQuotesWithApproval.ETH_11_USDC_TO_ARB,
);
(actions.addToken as jest.Mock).mockImplementation(
() => async () => ({}),
);

// Execute
await store.dispatch(submitBridgeTransaction(history as any) as any);
await store.dispatch(
submitBridgeTransaction(
DummyQuotesWithApproval.ETH_11_USDC_TO_ARB[0] as any,
history as any,
) as any,
);

// Assert
expect(actions.addToken).toHaveBeenCalledWith({
Expand Down Expand Up @@ -287,15 +283,17 @@ describe('bridge/actions', () => {
(actions.addTransactionAndWaitForPublish as jest.Mock).mockImplementation(
mockAddTransactionAndWaitForPublish,
);
(bridgeSelectors.getQuotes as jest.Mock).mockImplementation(
() => DummyQuotesNoApproval.OP_0_005_ETH_TO_ARB,
);
(actions.addToken as jest.Mock).mockImplementation(
() => async () => ({}),
);

// Execute
await store.dispatch(submitBridgeTransaction(history as any) as any);
await store.dispatch(
submitBridgeTransaction(
DummyQuotesNoApproval.OP_0_005_ETH_TO_ARB[0] as any,
history as any,
) as any,
);

// Assert
expect(actions.addToken).not.toHaveBeenCalled();
Expand All @@ -311,15 +309,17 @@ describe('bridge/actions', () => {
const store = makeMockStore();
const history = makeMockHistory();

(bridgeSelectors.getQuotes as jest.Mock).mockImplementation(
() => DummyQuotesWithApproval.ETH_11_USDC_TO_ARB,
);
(actions.addToken as jest.Mock).mockImplementation(
() => async () => ({}),
);

// Execute
await store.dispatch(submitBridgeTransaction(history as any) as any);
await store.dispatch(
submitBridgeTransaction(
DummyQuotesWithApproval.ETH_11_USDC_TO_ARB[0] as any,
history as any,
) as any,
);

// Assert
expect(actions.addToken).toHaveBeenCalledWith({
Expand Down Expand Up @@ -351,15 +351,17 @@ describe('bridge/actions', () => {
(actions.addTransactionAndWaitForPublish as jest.Mock).mockImplementation(
mockAddTransactionAndWaitForPublish,
);
(bridgeSelectors.getQuotes as jest.Mock).mockImplementation(
() => DummyQuotesNoApproval.OP_0_005_ETH_TO_ARB,
);
(actions.addToken as jest.Mock).mockImplementation(
() => async () => ({}),
);

// Execute
await store.dispatch(submitBridgeTransaction(history as any) as any);
await store.dispatch(
submitBridgeTransaction(
DummyQuotesNoApproval.OP_0_005_ETH_TO_ARB[0] as any,
history as any,
) as any,
);

// Assert
expect(actions.addToken).not.toHaveBeenCalled();
Expand All @@ -385,12 +387,11 @@ describe('bridge/actions', () => {
mockAddTransactionAndWaitForPublish,
);

(bridgeSelectors.getQuotes as jest.Mock).mockImplementation(
() => DummyQuotesWithApproval.ETH_11_USDC_TO_ARB,
);
(
selectors.getNetworkConfigurationsByChainId as jest.Mock
).mockImplementation(() => ({
const mockedGetNetworkConfigurationsByChainId =
// @ts-expect-error this is a jest mock
selectors.getNetworkConfigurationsByChainId as jest.Mock;

mockedGetNetworkConfigurationsByChainId.mockImplementation(() => ({
'0x1': {
blockExplorerUrls: ['https://etherscan.io'],
chainId: '0x1',
Expand Down Expand Up @@ -424,7 +425,12 @@ describe('bridge/actions', () => {
}));

// Execute
await store.dispatch(submitBridgeTransaction(history as any) as any);
await store.dispatch(
submitBridgeTransaction(
DummyQuotesWithApproval.ETH_11_USDC_TO_ARB[0] as any,
history as any,
) as any,
);

// Assert
expect(actions.addNetwork).toHaveBeenCalledWith({
Expand All @@ -447,7 +453,12 @@ describe('bridge/actions', () => {
const history = makeMockHistory();

// Execute
await store.dispatch(submitBridgeTransaction(history as any) as any);
await store.dispatch(
submitBridgeTransaction(
DummyQuotesWithApproval.ETH_11_USDC_TO_ARB[0] as any,
history as any,
) as any,
);

// Assert
expect(history.push).toHaveBeenCalledWith('/');
Expand Down
Loading

0 comments on commit 9c4ed4d

Please sign in to comment.