All files / src createStubStakePoolProvider.ts

79.16% Statements 19/24
58.82% Branches 10/17
88.88% Functions 8/9
90% Lines 18/20

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 59 60 61 62 63 64 65 66 67 68 693x 3x   3x                                               3x     4x           3x 3x 3x 3x 3x   6x       6x         3x           1x 1x     70x 70x 70x          
import { Cardano, StakePoolProvider } from '@cardano-sdk/core';
import delay from 'delay';
 
export const somePartialStakePools: Cardano.StakePool[] = [
  {
    hexId: Cardano.PoolIdHex('cf12a9dcaacdc09778616d60502011a88ed4542c482f2ddd08d8ac5a'),
    id: Cardano.PoolId('pool1euf2nh92ehqfw7rpd4s9qgq34z8dg4pvfqhjmhggmzk95gcd402'),
    metadata: {
      description: 'Keiths Pi test pool',
      homepage: '',
      name: 'Keiths PiTest',
      ticker: 'KPIT'
    }
  },
  {
    hexId: Cardano.PoolIdHex('4a2e3b7f4a78ff1452b91329a7673c77c98ca96dece7b55c37869502'),
    id: Cardano.PoolId('pool1fghrkl620rl3g54ezv56weeuwlyce2tdannm2hphs62syf3vyyh'),
    metadata: {
      description: 'VEGAS TestNet(2) ADA Pool',
      homepage: 'https://www.ada.vegas',
      name: 'VEGASPool',
      ticker: 'VEGA2'
    }
  }
] as Cardano.StakePool[];
 
/** Good source for testnet pools: https://testnet.adatools.io/pools */
export const createStubStakePoolProvider = (
  stakePools: Cardano.StakePool[] = somePartialStakePools,
  delayMs?: number
): StakePoolProvider => ({
  healthCheck: async () => {
    Iif (delayMs) await delay(delayMs);
    return { ok: true };
  },
  queryStakePools: async (options) => {
    Iif (delayMs) await delay(delayMs);
    const identifierFilters = options?.filters?.identifier;
    const textSearchValue = options?.filters?.text;
    const filterValues = identifierFilters ? identifierFilters.values : [];
    const pageResults = stakePools.filter(
      ({ id, metadata }) =>
        (textSearchValue && metadata?.name.includes(textSearchValue)) ||
        (textSearchValue && metadata?.ticker.includes(textSearchValue)) ||
        filterValues.some(
          (value) =>
            (value.id && id.includes(value.id)) ||
            (value.name && metadata?.name.includes(value.name)) ||
            (value.ticker && metadata?.ticker.includes(value.ticker))
        )
    );
    return {
      pageResults,
      totalResultCount: pageResults.length
    };
  },
  stakePoolStats: async () => {
    Iif (delayMs) await delay(delayMs);
    return {
      qty: {
        activating: 0,
        active: stakePools.filter((pool) => pool.status === Cardano.StakePoolStatus.Active).length,
        retired: stakePools.filter((pool) => pool.status === Cardano.StakePoolStatus.Retired).length,
        retiring: stakePools.filter((pool) => pool.status === Cardano.StakePoolStatus.Retiring).length
      }
    };
  }
});