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 mockReturnGetHydratedUtxoDetailsWithZeroBalance from '../__mocks__/mockReturnGetHydratedUtxoDetailsWithZeroBalance'; | import mockReturnGetHydratedUtxoDetailsWithZeroBalance from '../__mocks__/mockReturnGetHydratedUtxoDetailsWithZeroBalance'; | ||||
import mockReturnGetSlpBalancesAndUtxosNoZeroBalance from '../__mocks__/mockReturnGetSlpBalancesAndUtxosNoZeroBalance'; | import mockReturnGetSlpBalancesAndUtxosNoZeroBalance from '../__mocks__/mockReturnGetSlpBalancesAndUtxosNoZeroBalance'; | ||||
import sendBCHMock from '../__mocks__/sendBCH'; | import sendBCHMock from '../__mocks__/sendBCH'; | ||||
import createTokenMock from '../__mocks__/createToken'; | import createTokenMock from '../__mocks__/createToken'; | ||||
import mockTxHistory from '../__mocks__/mockTxHistory'; | import mockTxHistory from '../__mocks__/mockTxHistory'; | ||||
import mockFlatTxHistory from '../__mocks__/mockFlatTxHistory'; | import mockFlatTxHistory from '../__mocks__/mockFlatTxHistory'; | ||||
import mockTxDataWithPassthrough from '../__mocks__/mockTxDataWithPassthrough'; | import mockTxDataWithPassthrough from '../__mocks__/mockTxDataWithPassthrough'; | ||||
import mockPublicKeys from '../__mocks__/mockPublicKeys'; | |||||
import { | import { | ||||
flattenedHydrateUtxosResponse, | flattenedHydrateUtxosResponse, | ||||
legacyHydrateUtxosResponse, | legacyHydrateUtxosResponse, | ||||
} from '../__mocks__/mockHydrateUtxosBatched'; | } from '../__mocks__/mockHydrateUtxosBatched'; | ||||
import { | import { | ||||
tokenSendWdt, | tokenSendWdt, | ||||
tokenReceiveGarmonbozia, | tokenReceiveGarmonbozia, | ||||
tokenReceiveTBS, | tokenReceiveTBS, | ||||
▲ Show 20 Lines • Show All 362 Lines • ▼ Show 20 Lines | describe('useBCH hook', () => { | ||||
it('Correctly flattens transaction history', () => { | it('Correctly flattens transaction history', () => { | ||||
const { flattenTransactions } = useBCH(); | const { flattenTransactions } = useBCH(); | ||||
expect(flattenTransactions(mockTxHistory, 10)).toStrictEqual( | expect(flattenTransactions(mockTxHistory, 10)).toStrictEqual( | ||||
mockFlatTxHistory, | mockFlatTxHistory, | ||||
); | ); | ||||
}); | }); | ||||
it(`Correctly parses a "send ${currency.ticker}" transaction`, () => { | it(`Correctly parses a "send ${currency.ticker}" transaction`, async () => { | ||||
const { parseTxData } = useBCH(); | const { parseTxData } = useBCH(); | ||||
expect(parseTxData([mockTxDataWithPassthrough[0]])).toStrictEqual( | const BCH = new BCHJS(); | ||||
mockSentCashTx, | expect( | ||||
); | await parseTxData( | ||||
BCH, | |||||
[mockTxDataWithPassthrough[0]], | |||||
mockPublicKeys, | |||||
), | |||||
).toStrictEqual(mockSentCashTx); | |||||
}); | }); | ||||
it(`Correctly parses a "receive ${currency.ticker}" transaction`, () => { | it(`Correctly parses a "receive ${currency.ticker}" transaction`, async () => { | ||||
const { parseTxData } = useBCH(); | const { parseTxData } = useBCH(); | ||||
expect(parseTxData([mockTxDataWithPassthrough[5]])).toStrictEqual( | const BCH = new BCHJS(); | ||||
mockReceivedCashTx, | expect( | ||||
); | await parseTxData( | ||||
BCH, | |||||
[mockTxDataWithPassthrough[5]], | |||||
mockPublicKeys, | |||||
), | |||||
).toStrictEqual(mockReceivedCashTx); | |||||
}); | }); | ||||
it(`Correctly parses a "send ${currency.tokenTicker}" transaction`, () => { | it(`Correctly parses a "send ${currency.tokenTicker}" transaction`, async () => { | ||||
const { parseTxData } = useBCH(); | const { parseTxData } = useBCH(); | ||||
expect(parseTxData([mockTxDataWithPassthrough[1]])).toStrictEqual( | const BCH = new BCHJS(); | ||||
mockSentTokenTx, | expect( | ||||
); | await parseTxData( | ||||
BCH, | |||||
[mockTxDataWithPassthrough[1]], | |||||
mockPublicKeys, | |||||
), | |||||
).toStrictEqual(mockSentTokenTx); | |||||
}); | }); | ||||
it(`Correctly parses a "receive ${currency.tokenTicker}" transaction`, () => { | it(`Correctly parses a "receive ${currency.tokenTicker}" transaction`, async () => { | ||||
const { parseTxData } = useBCH(); | const { parseTxData } = useBCH(); | ||||
expect(parseTxData([mockTxDataWithPassthrough[3]])).toStrictEqual( | const BCH = new BCHJS(); | ||||
mockReceivedTokenTx, | expect( | ||||
); | await parseTxData( | ||||
BCH, | |||||
[mockTxDataWithPassthrough[3]], | |||||
mockPublicKeys, | |||||
), | |||||
).toStrictEqual(mockReceivedTokenTx); | |||||
}); | }); | ||||
it(`Correctly parses a "send ${currency.tokenTicker}" transaction with token details`, () => { | it(`Correctly parses a "send ${currency.tokenTicker}" transaction with token details`, () => { | ||||
const { parseTokenInfoForTxHistory } = useBCH(); | const { parseTokenInfoForTxHistory } = useBCH(); | ||||
const BCH = new BCHJS(); | const BCH = new BCHJS(); | ||||
expect( | expect( | ||||
parseTokenInfoForTxHistory( | parseTokenInfoForTxHistory( | ||||
BCH, | BCH, | ||||
Show All 34 Lines | it(`Correctly parses a "GENESIS ${currency.tokenTicker}" transaction with token details`, () => { | ||||
parseTokenInfoForTxHistory( | parseTokenInfoForTxHistory( | ||||
BCH, | BCH, | ||||
tokenGenesisCashtabMintAlpha.parsedTx, | tokenGenesisCashtabMintAlpha.parsedTx, | ||||
tokenGenesisCashtabMintAlpha.tokenInfo, | tokenGenesisCashtabMintAlpha.tokenInfo, | ||||
), | ), | ||||
).toStrictEqual(tokenGenesisCashtabMintAlpha.cashtabTokenInfo); | ).toStrictEqual(tokenGenesisCashtabMintAlpha.cashtabTokenInfo); | ||||
}); | }); | ||||
it(`Correctly parses a "send ${currency.ticker}" transaction with an OP_RETURN message`, () => { | it(`Correctly parses a "send ${currency.ticker}" transaction with an OP_RETURN message`, async () => { | ||||
const { parseTxData } = useBCH(); | const { parseTxData } = useBCH(); | ||||
expect(parseTxData([mockTxDataWithPassthrough[10]])).toStrictEqual( | const BCH = new BCHJS(); | ||||
mockSentOpReturnMessageTx, | expect( | ||||
); | await parseTxData( | ||||
BCH, | |||||
[mockTxDataWithPassthrough[10]], | |||||
mockPublicKeys, | |||||
), | |||||
).toStrictEqual(mockSentOpReturnMessageTx); | |||||
}); | }); | ||||
it(`Correctly parses a "receive ${currency.ticker}" transaction with an OP_RETURN message`, () => { | it(`Correctly parses a "receive ${currency.ticker}" transaction with an OP_RETURN message`, async () => { | ||||
const { parseTxData } = useBCH(); | const { parseTxData } = useBCH(); | ||||
expect(parseTxData([mockTxDataWithPassthrough[11]])).toStrictEqual( | const BCH = new BCHJS(); | ||||
mockReceivedOpReturnMessageTx, | BCH.RawTransactions.getRawTransaction = jest | ||||
); | .fn() | ||||
.mockResolvedValue(mockTxDataWithPassthrough[12]); | |||||
expect( | |||||
await parseTxData( | |||||
BCH, | |||||
[mockTxDataWithPassthrough[11]], | |||||
mockPublicKeys, | |||||
), | |||||
).toStrictEqual(mockReceivedOpReturnMessageTx); | |||||
}); | }); | ||||
}); | }); |