Changeset View
Changeset View
Standalone View
Standalone View
web/cashtab/src/hooks/__tests__/migrations.test.js
import { currency } from '../../components/Common/Ticker'; | import { currency } from '../../components/Common/Ticker'; | ||||
import BigNumber from 'bignumber.js'; | import BigNumber from 'bignumber.js'; | ||||
import BCHJS from '@psf/bch-js'; | |||||
import useBCH from '../useBCH'; | |||||
describe('Testing functions for upgrading Cashtab', () => { | describe('Testing functions for upgrading Cashtab', () => { | ||||
it('Replacement currency.dust parameter parsing matches legacy DUST parameter', () => { | it('Replacement currency.dust parameter parsing matches legacy DUST parameter', () => { | ||||
expect(parseFloat(new BigNumber(currency.dust).toFixed(8))).toBe( | expect(parseFloat(new BigNumber(currency.dust).toFixed(8))).toBe( | ||||
0.00000546, | 0.00000546, | ||||
); | ); | ||||
}); | }); | ||||
it('For strings with 8 decimal places, toBaseUnit() outputs a BigNumber equivalent to the toSatoshi() integer output', () => { | |||||
const BCH = new BCHJS(); | |||||
const testAmount = 0.12345678; | |||||
const { toSmallestDenomination } = useBCH(); | |||||
const dustLimitInSatoshis = BCH.BitcoinCash.toSatoshi( | |||||
new BigNumber(testAmount).toFixed(8), | |||||
); | |||||
const dustLimitInCashDecimalsDenomination = parseInt( | |||||
toSmallestDenomination(new BigNumber(testAmount)).toString(), | |||||
); | |||||
expect(dustLimitInSatoshis).toBe(dustLimitInCashDecimalsDenomination); | |||||
}); | |||||
}); | }); |