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 mockReturnGetUtxos from '../__mocks__/mockReturnGetUtxos'; | import mockReturnGetUtxos from '../__mocks__/mockReturnGetUtxos'; | ||||
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 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 sendBCH from '../__mocks__/sendBCH'; | import sendBCH from '../__mocks__/sendBCH'; | ||||
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: { | ||||
REACT_APP_NETWORK: `testnet`, | REACT_APP_NETWORK: `testnet`, | ||||
REACT_APP_BCHA_APIS: | REACT_APP_BCHA_APIS: | ||||
'https://rest.kingbch.com/v3/,https://wallet-service-prod.bitframe.org/v3/,notevenaurl,https://rest.kingbch.com/v3/', | 'https://rest.kingbch.com/v3/,https://wallet-service-prod.bitframe.org/v3/,notevenaurl,https://rest.kingbch.com/v3/', | ||||
▲ Show 20 Lines • Show All 136 Lines • ▼ Show 20 Lines | it('Throws error on attempt to send one satoshi less than backend dust limit', async () => { | ||||
const { sendBch } = useBCH(); | const { sendBch } = useBCH(); | ||||
const BCH = new BCHJS(); | const BCH = new BCHJS(); | ||||
const { expectedTxId, utxos, wallet, addresses } = sendBCHMock; | const { expectedTxId, utxos, wallet, addresses } = sendBCHMock; | ||||
BCH.RawTransactions.sendRawTransaction = jest | BCH.RawTransactions.sendRawTransaction = jest | ||||
.fn() | .fn() | ||||
.mockResolvedValue(expectedTxId); | .mockResolvedValue(expectedTxId); | ||||
const failedSendBch = sendBch(BCH, wallet, utxos, { | const failedSendBch = sendBch(BCH, wallet, utxos, { | ||||
addresses, | addresses, | ||||
values: [0.00000546 - 0.00000001], | values: [ | ||||
new BigNumber(currency.dust) | |||||
.minus(new BigNumber('0.00000001')) | |||||
.toString(), | |||||
], | |||||
}); | }); | ||||
expect(failedSendBch).rejects.toThrow(new Error('dust')); | expect(failedSendBch).rejects.toThrow(new Error('dust')); | ||||
const nullValuesSendBch = await sendBch(BCH, wallet, utxos, { | const nullValuesSendBch = await sendBch(BCH, wallet, utxos, { | ||||
addresses, | addresses, | ||||
values: null, | values: null, | ||||
}); | }); | ||||
expect(nullValuesSendBch).toBe(null); | expect(nullValuesSendBch).toBe(null); | ||||
}); | }); | ||||
▲ Show 20 Lines • Show All 59 Lines • Show Last 20 Lines |