Changeset View
Changeset View
Standalone View
Standalone View
web/cashtab/src/hooks/__tests__/useBCH.test.js
Show All 21 Lines | import { | ||||
mockSentCashTx, | mockSentCashTx, | ||||
mockReceivedCashTx, | mockReceivedCashTx, | ||||
mockSentTokenTx, | mockSentTokenTx, | ||||
mockReceivedTokenTx, | mockReceivedTokenTx, | ||||
} from '../__mocks__/mockParsedTxs'; | } 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'; | ||||
import { fromSmallestDenomination } from '@utils/cashMethods'; | |||||
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 169 Lines • ▼ Show 20 Lines | it('Throws error on attempt to send one satoshi less than backend dust limit', async () => { | ||||
BCH.RawTransactions.sendRawTransaction = jest | BCH.RawTransactions.sendRawTransaction = jest | ||||
.fn() | .fn() | ||||
.mockResolvedValue(expectedTxId); | .mockResolvedValue(expectedTxId); | ||||
const failedSendBch = sendBch( | const failedSendBch = sendBch( | ||||
BCH, | BCH, | ||||
wallet, | wallet, | ||||
utxos, | utxos, | ||||
destinationAddress, | destinationAddress, | ||||
new BigNumber(currency.dust) | new BigNumber( | ||||
fromSmallestDenomination(currency.dustSats).toString(), | |||||
) | |||||
.minus(new BigNumber('0.00000001')) | .minus(new BigNumber('0.00000001')) | ||||
.toString(), | .toString(), | ||||
1.01, | 1.01, | ||||
); | ); | ||||
expect(failedSendBch).rejects.toThrow(new Error('dust')); | expect(failedSendBch).rejects.toThrow(new Error('dust')); | ||||
const nullValuesSendBch = await sendBch( | const nullValuesSendBch = await sendBch( | ||||
BCH, | BCH, | ||||
wallet, | wallet, | ||||
▲ Show 20 Lines • Show All 187 Lines • Show Last 20 Lines |