import { PACKAGE_NAME } from '../src/constants' ; import { UtxoInfo } from '@bitaccess/coinlib-common' ; import { TestLogger } from '../../../common/testUtils' ; import { BitcoinishTxOutput } from '../src/bitcoinish/types' ; import { toBaseDenominationNumber } from '../src' ; import { omit } from 'lodash' ; export * from '../../../common/testUtils' ; export const logger = new TestLogger ( PACKAGE_NAME ) ; export function makeUtxos ( confirmedValues , unconfirmedValues = [ ] ) { return [ ... confirmedValues . map ( ( value , i ) => ( { txid : `utxo-confirmed-${ i }` , vout : i , value : value , satoshis : toBaseDenominationNumber ( value ) , confirmations : 10 , height : '1234' , } ) ) , ... unconfirmedValues . map ( ( value , i ) => ( { txid : `utxo-unconfirmed-${ i }` , vout : i , value : value , satoshis : toBaseDenominationNumber ( value ) , } ) ) ] ; } export function makeOutputs ( address , ... values ) { return values . map ( ( value ) => ( { address , value : String ( value ) , } ) ) ; } export function sortUtxosByTxid ( utxos ) { return [ ... utxos ] . sort ( ( a , b ) => a . txid . localeCompare ( b . txid ) || ( b . vout - a . vout ) ) ; } export function expectUtxosEqual ( expectedUtxos , actualUtxos ) { expect ( sortUtxosByTxid ( expectedUtxos ) ) . toEqual ( sortUtxosByTxid ( actualUtxos ) ) ; } function stripBitcoinishTxInfoForEquality ( txInfo ) { return omit ( { ... txInfo , data : { ... txInfo . data , vout : txInfo . data . vout . map ( ( o ) => omit ( o , [ 'spent' ] ) ) , } , outputUtxos : txInfo . outputUtxos ?. map ( ( o ) => omit ( o , [ 'confirmations' ] ) ) , } , [ 'data.confirmations' , 'confirmations' , 'currentBlockNumber' ] ) ; } export function assertBitcoinishTxInfoEquality ( actual , expected ) { expect ( stripBitcoinishTxInfoForEquality ( actual ) ) . toEqual ( stripBitcoinishTxInfoForEquality ( expected ) ) ; }