-
Notifications
You must be signed in to change notification settings - Fork 146
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
1 parent
333577c
commit a80163d
Showing
2 changed files
with
114 additions
and
0 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,54 @@ | ||
import { ChainWalletBase, ChainRecord } from "@cosmos-kit/core"; | ||
import { chains } from "chain-registry"; | ||
import { mockExtensionInfo as walletInfo } from '../src/mock-extension/extension/registry'; | ||
|
||
// Mock global window object | ||
global.window = { | ||
// @ts-ignore | ||
localStorage: { | ||
getItem: jest.fn(), | ||
setItem: jest.fn(), | ||
removeItem: jest.fn() | ||
} | ||
}; | ||
|
||
|
||
const chainRecord: ChainRecord = { | ||
name: 'cosmoshub', | ||
chain: chains.find(c => c.chain_name === 'cosmoshub'), | ||
clientOptions: { | ||
preferredSignType: 'direct' | ||
}, | ||
}; | ||
|
||
const chainWallet = new ChainWalletBase(walletInfo, chainRecord); | ||
|
||
async function connectAndFetchAccount() { | ||
try { | ||
await chainWallet.update({ connect: true }); | ||
console.log('Connected and account data fetched:', chainWallet.data); | ||
} catch (error) { | ||
console.error('Failed to connect or fetch account data:', error); | ||
} | ||
} | ||
|
||
connectAndFetchAccount(); | ||
|
||
describe('ChainWalletBase', () => { | ||
let chainWallet; | ||
beforeEach(() => { | ||
chainWallet = new ChainWalletBase(walletInfo, chainRecord); | ||
// Mocking necessary methods and properties | ||
// jest.spyOn(chainWallet, 'connectChains').mockResolvedValue(undefined); | ||
jest.spyOn(chainWallet.client, 'getSimpleAccount').mockResolvedValue({ | ||
namespace: 'cosmos', | ||
chainId: 'cosmoshub-4', | ||
address: 'cosmos1...' | ||
}); | ||
}); | ||
|
||
it('should update and fetch account data', async () => { | ||
await expect(chainWallet.update({ connect: true })).resolves.not.toThrow(); | ||
expect(chainWallet.data.address).toBe('cosmos1...'); | ||
}); | ||
}); |
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,60 @@ | ||
import { WalletManager, Logger, ChainRecord, Session } from '@cosmos-kit/core'; | ||
import { chains, assets } from 'chain-registry'; | ||
import { MockExtensionWallet } from '../src/mock-extension/extension'; | ||
import { mockExtensionInfo as walletInfo } from '../src/mock-extension/extension/registry'; | ||
|
||
const logger = new Logger(); function logoutUser() { | ||
console.log('Session expired. Logging out user.'); | ||
// Code to log out user | ||
} | ||
|
||
// Session duration set for 30 minutes | ||
const userSession = new Session({ | ||
duration: 30 * 60 * 1000, // 30 minutes in milliseconds | ||
callback: logoutUser | ||
}); | ||
|
||
// Start the session when the user logs in | ||
userSession.update(); | ||
|
||
const mainWalletBase = new MockExtensionWallet(walletInfo) | ||
|
||
describe('WalletManager', () => { | ||
let walletManager: WalletManager; | ||
|
||
beforeEach(() => { | ||
walletManager = new WalletManager( | ||
chains, | ||
[mainWalletBase], | ||
logger, | ||
true, // throwErrors | ||
true, // subscribeConnectEvents | ||
false // disableIframe | ||
); | ||
}); | ||
|
||
it('should initialize with provided configurations', () => { | ||
expect(walletManager.throwErrors).toBe(true); | ||
expect(walletManager.subscribeConnectEvents).toBe(true); | ||
expect(walletManager.disableIframe).toBe(false); | ||
expect(walletManager.chainRecords).toHaveLength(2); // Assuming `convertChain` is mocked | ||
}); | ||
|
||
it('should handle onMounted lifecycle correctly', async () => { | ||
// Mock environment parser | ||
jest.mock('Bowser', () => ({ | ||
getParser: () => ({ | ||
getBrowserName: jest.fn().mockReturnValue('chrome'), | ||
getPlatform: jest.fn().mockReturnValue({ type: 'desktop' }), | ||
getOSName: jest.fn().mockReturnValue('windows') | ||
}) | ||
})); | ||
|
||
await walletManager.onMounted(); | ||
|
||
expect(walletManager.walletRepos).toHaveLength(2); // Depends on internal logic | ||
expect(logger.debug).toHaveBeenCalled(); // Check if debug logs are called | ||
}); | ||
|
||
// Add more tests as needed for each method | ||
}); |