All files / tests/mocks actor.ts

100% Statements 28/28
100% Branches 4/4
100% Functions 17/17
100% Lines 24/24

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 49 50 51 52 53 54 55 56 57 58      2x 2x 2x   2x 34x 14x 9x 2x 3x 12x                             5x       2x     71x 60x 6x 8x 9x       2x 25x 22x       2x   2x 1x   1x      
import { SwapActor, TokenActor, ActorAdapter } from '@/integrations';
import { Agent } from '@dfinity/agent';
import { SwapIDL, TokenIDL } from 'declarations';
import { mockAllPairsResponse } from './pair';
import { mockPrincipal } from './principal';
import { mockSupportedTokenListResponse } from './token';
 
export const mockSwapActor = (params: Partial<SwapIDL.Swap> = {}): SwapActor =>
  ({
    getSupportedTokenList: async () => mockSupportedTokenListResponse(),
    getAllPairs: async () => mockAllPairsResponse(),
    deposit: async () => ({ ok: BigInt(1) }),
    withdraw: async () => ({ ok: BigInt(1) }),
    getUserBalances: async () => [
      ['aanaa-xaaaa-aaaah-aaeiq-cai', BigInt(1000000000000)],
      ['utozz-siaaa-aaaam-qaaxq-cai', BigInt(100000000)],
      ['onuey-xaaaa-aaaah-qcf7a-cai', BigInt(100000000)],
      ['oexpe-biaaa-aaaah-qcf6q-cai', BigInt(100000000)],
      ['a7saq-3aaaa-aaaai-qbcdq-cai', BigInt(100000000)],
      ['kftk5-4qaaa-aaaah-aa5lq-cai', BigInt(100000000)],
      ['li5ot-tyaaa-aaaah-aa5ma-cai', BigInt(100000000)],
      ['gagfc-iqaaa-aaaah-qcdvq-cai', BigInt(100000000)],
      ['u2nsf-eaaaa-aaaam-qaawa-cai', BigInt(100000000)],
      ['gvbup-jyaaa-aaaah-qcdwa-cai', BigInt(100000000)],
      ['xe4vl-dqaaa-aaaam-qaa7a-cai', BigInt(100000000)],
      ['cfoim-fqaaa-aaaai-qbcmq-cai', BigInt(100000000)],
      ['wjsrf-myaaa-aaaam-qaayq-cai', BigInt(100000000)],
    ],
    swapExactTokensForTokens: async () => ({ ok: BigInt(1) }),
    ...params,
  } as unknown as SwapActor);
 
export const mockTokenActor = (
  params: Partial<TokenIDL.Token> = {}
): TokenActor =>
  ({
    balanceOf: async () => BigInt('1'),
    approve: async () => ({ Ok: BigInt(1) }),
    allowance: async () => BigInt(0),
    decimals: async () => 12,
    ...params,
  } as unknown as TokenActor);
 
export const mockAgent = (params: Partial<Agent> = {}): Agent =>
  ({
    getPrincipal: async () => mockPrincipal(),
    ...params,
  } as unknown as Agent);
 
export const mockActorProvider = (
  params: Partial<ActorAdapter.Provider> = {}
): ActorAdapter.Provider => ({
  createActor: async () => ({} as any),
  agent: mockAgent(),
  createAgent: async () => mockAgent(),
  ...params,
});