Changeset View
Changeset View
Standalone View
Standalone View
web/cashtab/src/hooks/__tests__/useBCH.test.js
/* eslint-disable no-native-reassign */ | /* eslint-disable no-native-reassign */ | ||||
import useBCH from '../useBCH'; | import useBCH from '../useBCH'; | ||||
import mockReturnGetHydratedUtxoDetails from '../__mocks__/mockReturnGetHydratedUtxoDetails'; | import mockReturnGetHydratedUtxoDetails from '../__mocks__/mockReturnGetHydratedUtxoDetails'; | ||||
import mockReturnGetSlpBalancesAndUtxos from '../__mocks__/mockReturnGetSlpBalancesAndUtxos'; | import mockReturnGetSlpBalancesAndUtxos from '../__mocks__/mockReturnGetSlpBalancesAndUtxos'; | ||||
import sendBCHMock from '../__mocks__/sendBCH'; | import sendBCHMock from '../__mocks__/sendBCH'; | ||||
import mockTxHistory from '../__mocks__/mockTxHistory'; | |||||
import mockFlatTxHistory from '../__mocks__/mockFlatTxHistory'; | |||||
import mockTxDataWithPassthrough from '../__mocks__/mockTxDataWithPassthrough'; | |||||
import { | |||||
mockSentCashTx, | |||||
mockReceivedCashTx, | |||||
mockSentTokenTx, | |||||
mockReceivedTokenTx, | |||||
} from '../__mocks__/mockParsedTxs'; | |||||
import BCHJS from '@psf/bch-js'; // TODO: should be removed when external lib not needed anymore | import BCHJS from '@psf/bch-js'; // TODO: should be removed when external lib not needed anymore | ||||
import { currency } from '../../components/Common/Ticker'; | import { currency } from '../../components/Common/Ticker'; | ||||
import BigNumber from 'bignumber.js'; | import BigNumber from 'bignumber.js'; | ||||
describe('useBCH hook', () => { | describe('useBCH hook', () => { | ||||
it('gets Rest Api Url on testnet', () => { | it('gets Rest Api Url on testnet', () => { | ||||
process = { | process = { | ||||
env: { | env: { | ||||
▲ Show 20 Lines • Show All 239 Lines • ▼ Show 20 Lines | it('receives errors from the network and parses it', async () => { | ||||
1.01, | 1.01, | ||||
); | ); | ||||
await expect(tooManyAncestorsMempool).rejects.toThrow( | await expect(tooManyAncestorsMempool).rejects.toThrow( | ||||
new Error( | new Error( | ||||
'too-long-mempool-chain, too many unconfirmed ancestors [limit: 25] (code 64)', | 'too-long-mempool-chain, too many unconfirmed ancestors [limit: 25] (code 64)', | ||||
), | ), | ||||
); | ); | ||||
}); | }); | ||||
it('Correctly flattens transaction history', () => { | |||||
const { flattenTransactions } = useBCH(); | |||||
expect(flattenTransactions(mockTxHistory)).toStrictEqual( | |||||
mockFlatTxHistory, | |||||
); | |||||
}); | |||||
it(`Correctly parses a "send ${currency.ticker}" transaction`, () => { | |||||
const { parseTxData } = useBCH(); | |||||
expect(parseTxData([mockTxDataWithPassthrough[0]])).toStrictEqual( | |||||
mockSentCashTx, | |||||
); | |||||
}); | |||||
it(`Correctly parses a "receive ${currency.ticker}" transaction`, () => { | |||||
const { parseTxData } = useBCH(); | |||||
expect(parseTxData([mockTxDataWithPassthrough[5]])).toStrictEqual( | |||||
mockReceivedCashTx, | |||||
); | |||||
}); | |||||
it(`Correctly parses a "send ${currency.tokenTicker}" transaction`, () => { | |||||
const { parseTxData } = useBCH(); | |||||
expect(parseTxData([mockTxDataWithPassthrough[1]])).toStrictEqual( | |||||
mockSentTokenTx, | |||||
); | |||||
}); | |||||
it(`Correctly parses a "receive ${currency.tokenTicker}" transaction`, () => { | |||||
const { parseTxData } = useBCH(); | |||||
expect(parseTxData([mockTxDataWithPassthrough[3]])).toStrictEqual( | |||||
mockReceivedTokenTx, | |||||
); | |||||
}); | |||||
}); | }); |