-
Notifications
You must be signed in to change notification settings - Fork 428
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
3 changed files
with
60 additions
and
13 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,53 @@ | ||
import { isWalletUnlocked, WalletNames } from '../wallets' | ||
|
||
describe('utils/wallet', () => { | ||
it('should check if MetaMask is unlocked and return false', async () => { | ||
// mock window.ethereum | ||
Object.defineProperty(window, 'ethereum', { | ||
value: { | ||
isMetaMask: true, | ||
selectedAddress: '0x123', | ||
isConnected: () => true, | ||
_metamask: { | ||
isUnlocked: () => Promise.resolve(false), | ||
}, | ||
}, | ||
writable: true, | ||
}) | ||
const result = await isWalletUnlocked(WalletNames.METAMASK) | ||
expect(result).toBe(false) | ||
}) | ||
|
||
it('should check if MetaMask is unlocked and return true', async () => { | ||
// mock window.ethereum | ||
Object.defineProperty(window, 'ethereum', { | ||
value: { | ||
isMetaMask: true, | ||
selectedAddress: '0x123', | ||
isConnected: () => true, | ||
_metamask: { | ||
isUnlocked: () => Promise.resolve(true), | ||
}, | ||
}, | ||
writable: true, | ||
}) | ||
const result = await isWalletUnlocked(WalletNames.METAMASK) | ||
expect(result).toBe(true) | ||
}) | ||
|
||
it('should check if WalletConnect is unlocked', async () => { | ||
window.localStorage.setItem('walletconnect', 'true') | ||
|
||
expect(await isWalletUnlocked(WalletNames.WALLET_CONNECT)).toBe(true) | ||
expect(await isWalletUnlocked(WalletNames.WALLET_CONNECT_V2)).toBe(true) | ||
|
||
window.localStorage.removeItem('walletconnect') | ||
|
||
expect(await isWalletUnlocked(WalletNames.WALLET_CONNECT)).toBe(false) | ||
expect(await isWalletUnlocked(WalletNames.WALLET_CONNECT_V2)).toBe(false) | ||
}) | ||
|
||
it('should return false for unhandled wallets', async () => { | ||
expect(await isWalletUnlocked('PINEAPPLE')).toBe(false) | ||
}) | ||
}) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters