All files / src/services/util equals.ts

95.91% Statements 47/49
77.77% Branches 7/9
100% Functions 15/15
100% Lines 26/26

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      46x   46x   46x   46x 117x   99x 320x 9x       90x     46x 33x   33x     6182x   46x 84x   288x     46x 17x   46x   46x 7x   46x   46x 44x   46x   370x  
import { Cardano, EpochInfo, EraSummary } from '@cardano-sdk/core';
import { DelegatedStake } from '../types';
import { GroupedAddress, WitnessedTx } from '@cardano-sdk/key-management';
import { sameArrayItems } from '@cardano-sdk/util';
 
export const tipEquals = (a: Cardano.Tip, b: Cardano.Tip) => a.hash === b.hash;
 
export const txEquals = (a: Cardano.HydratedTx, b: Cardano.HydratedTx) => a.id === b.id;
 
export const sameSortedArrayItems = <T>(arrayA: T[], arrayB: T[], itemEquals: (a: T, b: T) => boolean): boolean => {
  if (arrayA.length !== arrayB.length) return false;
 
  for (const [i, element] of arrayA.entries()) {
    if (!itemEquals(element, arrayB[i])) {
      return false;
    }
  }
 
  return true;
};
 
export const transactionsEquals = (a: Cardano.HydratedTx[], b: Cardano.HydratedTx[]) => {
  Iif (a === b) return true;
 
  return sameSortedArrayItems(a, b, txEquals);
};
 
export const txInEquals = (a: Cardano.TxIn, b: Cardano.TxIn) => a.txId === b.txId && a.index === b.index;
 
export const utxoEquals = (a: Cardano.Utxo[], b: Cardano.Utxo[]) => {
  Iif (a === b) return true;
 
  return sameSortedArrayItems(a, b, ([aTxIn], [bTxIn]) => txInEquals(aTxIn, bTxIn));
};
 
export const eraSummariesEquals = (a: EraSummary[], b: EraSummary[]) =>
  sameArrayItems(a, b, (es1, es2) => es1.start.slot === es2.start.slot);
 
const groupedAddressEquals = (a: GroupedAddress, b: GroupedAddress) => a.address === b.address;
 
export const groupedAddressesEquals = (a: GroupedAddress[], b: GroupedAddress[]) =>
  sameArrayItems(a, b, groupedAddressEquals);
 
export const epochInfoEquals = (a: EpochInfo, b: EpochInfo) => a.epochNo === b.epochNo;
 
export const delegatedStakeEquals = (a: DelegatedStake, b: DelegatedStake) =>
  a.pool.id === b.pool.id && a.stake === b.stake && a.percentage === b.percentage;
 
const signedTxEquals = (a: WitnessedTx, b: WitnessedTx) => a.tx.id === b.tx.id;
 
export const signedTxsEquals = (a: WitnessedTx[], b: WitnessedTx[]) => sameArrayItems(a, b, signedTxEquals);