Skip to content

Commit

Permalink
fix: fix chains used by wagmi + mock Web3Wrapper during tests
Browse files Browse the repository at this point in the history
  • Loading branch information
therealemjy committed Aug 28, 2023
1 parent 40ab51e commit 27dfc72
Show file tree
Hide file tree
Showing 4 changed files with 14 additions and 17 deletions.
5 changes: 5 additions & 0 deletions src/clients/web3/Web3Wrapper/__mocks__/index.tsx
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
import React from 'react';

const Web3Wrapper: React.FC = ({ children }) => <>{children}</>;

export default Web3Wrapper;
17 changes: 7 additions & 10 deletions src/clients/web3/Web3Wrapper/client.ts
Original file line number Diff line number Diff line change
Expand Up @@ -15,19 +15,17 @@ import { BinanceWalletConnector } from './binanceWalletConnector';

export const chains: Chain[] = config.isOnTestnet ? [bscTestnet] : [bsc];

export const { provider, webSocketProvider } = configureChains(
[bscTestnet],
[
jsonRpcProvider({
rpc: chain => config.rpcUrls[chain.id as ChainId],
}),
publicProvider(),
],
);
const { provider, webSocketProvider } = configureChains(chains, [
jsonRpcProvider({
rpc: chain => config.rpcUrls[chain.id as ChainId],
}),
publicProvider(),
]);

const client = createClient({
autoConnect: true,
provider,
webSocketProvider,
connectors: [
new InjectedConnector({ chains }),
new MetaMaskConnector({ chains }),
Expand All @@ -48,7 +46,6 @@ const client = createClient({
chains,
}),
],
webSocketProvider,
});

export default client;
7 changes: 1 addition & 6 deletions src/setupTests.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@ import useTokenApproval from 'hooks/useTokenApproval';
vi.mock('utilities/isFeatureEnabled');
vi.mock('hooks/useTokenApproval');
vi.mock('clients/api');
vi.mock('clients/web3/Web3Wrapper');

// Mock Lottie
vi.mock('@lottiefiles/react-lottie-player', () => ({
Expand Down Expand Up @@ -41,12 +42,6 @@ vi.mock('@uiw/react-markdown-preview', () => ({
default: ({ content, ...otherProps }: any) => <p {...otherProps}>content</p>,
}));

// Mock connectors to prevent any request from being made to providers
vi.mock('wagmi/connectors/coinbaseWallet');
vi.mock('wagmi/connectors/walletConnect');
vi.mock('wagmi/connectors/injected');
vi.mock('wagmi/connectors/metaMask');

initializeLibraries();

const useTokenApprovalOriginalOutput = useTokenApproval(
Expand Down
2 changes: 1 addition & 1 deletion src/testUtils/renderComponent.tsx
Original file line number Diff line number Diff line change
@@ -1,11 +1,11 @@
// eslint-disable-next-line import/no-extraneous-dependencies
import { render } from '@testing-library/react';
import { getDefaultProvider } from 'ethers';
import { ChainId } from 'packages/contracts';
import React from 'react';
import { QueryClient, QueryClientProvider } from 'react-query';
import { BrowserRouter, Route, Switch } from 'react-router-dom';
import { ToastContainer } from 'react-toastify';
import { ChainId } from 'packages/contracts';

import { Web3Wrapper } from 'clients/web3';
import { AuthContext, AuthContextValue } from 'context/AuthContext';
Expand Down

0 comments on commit 27dfc72

Please sign in to comment.