All files / test/integration util.ts

100% Statements 13/13
100% Branches 1/1
100% Functions 2/2
100% Lines 11/11

Press n or j to go to the next uncovered block, b, p or k for the previous block.

1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 495x   5x 5x 5x 5x                   5x   18x                               5x 18x 18x                     18x    
import { Bip32Account, util } from '@cardano-sdk/key-management';
import { WalletStores } from '../../src/persistence';
import { createPersonalWallet } from '../../src';
import { createStubStakePoolProvider, mockProviders } from '@cardano-sdk/util-dev';
import { dummyLogger as logger } from 'ts-log';
import { testAsyncKeyAgent } from '../../../key-management/test/mocks';
 
const {
  mockAssetProvider,
  mockChainHistoryProvider,
  mockNetworkInfoProvider,
  mockRewardsProvider,
  mockTxSubmitProvider,
  mockUtxoProvider,
  mockDrepProvider
} = mockProviders;
 
const createDefaultProviders = () => ({
  assetProvider: mockAssetProvider(),
  chainHistoryProvider: mockChainHistoryProvider(),
  drepProvider: mockDrepProvider(),
  networkInfoProvider: mockNetworkInfoProvider(),
  rewardsProvider: mockRewardsProvider(),
  stakePoolProvider: createStubStakePoolProvider(),
  txSubmitProvider: mockTxSubmitProvider(),
  utxoProvider: mockUtxoProvider()
});
 
type RequiredProviders = ReturnType<typeof createDefaultProviders>;
export type Providers = {
  [k in keyof RequiredProviders]?: RequiredProviders[k];
};
 
export const createWallet = async (stores?: WalletStores, providers: Providers = {}) => {
  const keyAgent = await testAsyncKeyAgent();
  const wallet = createPersonalWallet(
    { name: 'Test Wallet' },
    {
      ...createDefaultProviders(),
      ...providers,
      bip32Account: await Bip32Account.fromAsyncKeyAgent(keyAgent),
      logger,
      stores,
      witnesser: util.createBip32Ed25519Witnesser(keyAgent)
    }
  );
  return { keyAgent, wallet };
};