All files / src/mockProviders mockNetworkInfoProvider2.ts

64.28% Statements 9/14
100% Branches 0/0
0% Functions 0/4
72.72% Lines 8/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  2x 2x 2x 2x   2x         2x         2x                   2x                            
/* eslint-disable jsdoc/require-returns-type */
import { Cardano } from '@cardano-sdk/core';
import { genesisParameters, ledgerTip, protocolParameters } from './mockData';
import { networkInfo } from './mockNetworkInfoProvider';
import delay from 'delay';
 
export const protocolParameters2 = {
  ...protocolParameters,
  maxCollateralInputs: protocolParameters.maxCollateralInputs + 1
};
 
export const genesisParameters2 = {
  ...genesisParameters,
  maxLovelaceSupply: genesisParameters.maxLovelaceSupply + 1n
};
 
export const ledgerTip2 = {
  ...ledgerTip,
  blockNo: Cardano.BlockNo(ledgerTip.blockNo + 1)
};
 
/**
 * A different provider stub for testing, supports delay to simulate network requests.
 *
 * @returns NetworkInfoProvider that returns data that is slightly different to mockNetworkInfoProvider.
 */
export const mockNetworkInfoProvider2 = (delayMs: number) => {
  const delayedJestFn = <T>(resolvedValue: T) =>
    jest.fn().mockImplementation(() => delay(delayMs).then(() => resolvedValue));
 
  return {
    eraSummaries: jest.fn().mockResolvedValue(networkInfo.network.eraSummaries),
    genesisParameters: delayedJestFn(genesisParameters2),
    healthCheck: delayedJestFn({ ok: true }),
    ledgerTip: delayedJestFn(ledgerTip2),
    lovelaceSupply: jest.fn().mockResolvedValue(networkInfo.lovelaceSupply),
    protocolParameters: delayedJestFn(protocolParameters2),
    stake: jest.fn().mockResolvedValue(networkInfo.stake)
  };
};