Skip to content

Commit

Permalink
Revert "fix: add tests for WalletConnectContext"
Browse files Browse the repository at this point in the history
This reverts commit 5c08405.
  • Loading branch information
iamacook committed Oct 4, 2023
1 parent 552ab2b commit a167e8c
Show file tree
Hide file tree
Showing 5 changed files with 10 additions and 237 deletions.
220 changes: 0 additions & 220 deletions src/services/walletconnect/WalletConnectContext.test.tsx

This file was deleted.

6 changes: 3 additions & 3 deletions src/services/walletconnect/WalletConnectContext.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -6,10 +6,10 @@ import WalletConnectWallet from './WalletConnectWallet'
import { asError } from '../exceptions/utils'
import { stripEip155Prefix } from './utils'

const walletConnectSingleton = WalletConnectWallet
const walletConnectSingleton = new WalletConnectWallet()

export const WalletConnectContext = createContext<{
walletConnect: typeof WalletConnectWallet | null
walletConnect: WalletConnectWallet | null
error: Error | null
}>({
walletConnect: null,
Expand All @@ -21,7 +21,7 @@ export const WalletConnectProvider = ({ children }: { children: ReactNode }) =>
safe: { chainId },
safeAddress,
} = useSafeInfo()
const [walletConnect, setWalletConnect] = useState<typeof WalletConnectWallet | null>(null)
const [walletConnect, setWalletConnect] = useState<WalletConnectWallet | null>(null)
const [error, setError] = useState<Error | null>(null)
const safeWalletProvider = useSafeWalletProvider()

Expand Down
12 changes: 3 additions & 9 deletions src/services/walletconnect/WalletConnectWallet.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ import { hexZeroPad } from 'ethers/lib/utils'
import type { ProposalTypes, SessionTypes, SignClientTypes, Verify } from '@walletconnect/types'
import type { IWeb3Wallet, Web3WalletTypes } from '@walletconnect/web3wallet'

import type WalletConnectWallet from './WalletConnectWallet'
import WalletConnectWallet from './WalletConnectWallet'

jest.mock('@walletconnect/core', () => ({
Core: jest.fn(),
Expand Down Expand Up @@ -45,20 +45,14 @@ jest.mock('@walletconnect/web3wallet', () => {
})

describe('WalletConnectWallet', () => {
let wallet: typeof WalletConnectWallet
let wallet: WalletConnectWallet

beforeEach(async () => {
// Reset import
wallet = (await import('./WalletConnectWallet')).default
wallet = new WalletConnectWallet()

await wallet.init()
})

afterEach(() => {
// Reset instance to avoid side leaking mocks
jest.resetModules()
})

describe('connect', () => {
it('should call pair with the correct parameters', async () => {
const pairSpy = jest.spyOn(((wallet as any).web3Wallet as IWeb3Wallet).core.pairing, 'pair')
Expand Down
3 changes: 1 addition & 2 deletions src/services/walletconnect/WalletConnectWallet.ts
Original file line number Diff line number Diff line change
Expand Up @@ -251,5 +251,4 @@ class WalletConnectWallet {
}
}

// Instance needs to be exported for testing purposes
export default new WalletConnectWallet()
export default WalletConnectWallet
6 changes: 3 additions & 3 deletions src/services/walletconnect/useWalletConnectSessions.test.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,7 @@ describe('useWalletConnectSessions', () => {
getActiveSessions: jest.fn().mockReturnValue(sessions),
onSessionAdd: jest.fn(),
onSessionDelete: jest.fn(),
} as unknown as typeof WalletConnectWallet
} as unknown as WalletConnectWallet

const wrapper = ({ children }: any) => (
<WalletConnectContext.Provider value={{ walletConnect: mockWalletConnect, error: null }}>
Expand All @@ -46,7 +46,7 @@ describe('useWalletConnectSessions', () => {
getActiveSessions: jest.fn().mockReturnValue([]),
onSessionAdd: jest.fn(),
onSessionDelete: jest.fn(),
} as unknown as typeof WalletConnectWallet
} as unknown as WalletConnectWallet

const wrapper = ({ children }: any) => (
<WalletConnectContext.Provider value={{ walletConnect: mockWalletConnect, error: null }}>
Expand Down Expand Up @@ -94,7 +94,7 @@ describe('useWalletConnectSessions', () => {
getActiveSessions: jest.fn().mockReturnValue([]),
onSessionAdd: jest.fn(),
onSessionDelete: jest.fn(),
} as unknown as typeof WalletConnectWallet
} as unknown as WalletConnectWallet

const wrapper = ({ children }: any) => (
<WalletConnectContext.Provider value={{ walletConnect: mockWalletConnect, error: null }}>
Expand Down

0 comments on commit a167e8c

Please sign in to comment.