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 BCHJS from '@psf/bch-js'; | ||||
import useBCH from '../useBCH'; | 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('Replicate 8-decimal return value from instance of toSatoshi in TransactionBuilder with toSmallestDenomination', () => { | |||||
const BCH = new BCHJS(); | |||||
const { toSmallestDenomination } = useBCH(); | |||||
const testSendAmount = '0.12345678'; | |||||
expect( | |||||
parseInt(toSmallestDenomination(new BigNumber(testSendAmount), 8)), | |||||
).toBe(BCH.BitcoinCash.toSatoshi(Number(testSendAmount).toFixed(8))); | |||||
}); | |||||
it('Replicate 2-decimal return value from instance of toSatoshi in TransactionBuilder with toSmallestDenomination', () => { | |||||
const BCH = new BCHJS(); | |||||
const { toSmallestDenomination } = useBCH(); | |||||
const testSendAmount = '0.12'; | |||||
expect( | |||||
parseInt(toSmallestDenomination(new BigNumber(testSendAmount), 8)), | |||||
).toBe(BCH.BitcoinCash.toSatoshi(Number(testSendAmount).toFixed(8))); | |||||
}); | |||||
it('toSmallestDenomination() returns false if input is not a BigNumber', () => { | it('toSmallestDenomination() returns false if input is not a BigNumber', () => { | ||||
const { toSmallestDenomination } = useBCH(); | const { toSmallestDenomination } = useBCH(); | ||||
const testInput = 132.12345678; | const testInput = 132.12345678; | ||||
expect(toSmallestDenomination(testInput)).toBe(false); | expect(toSmallestDenomination(testInput)).toBe(false); | ||||
}); | }); | ||||
it(`toSmallestDenomination() returns false if input is a BigNumber with more decimals than specified by cashDecimals parameter`, () => { | it(`toSmallestDenomination() returns false if input is a BigNumber with more decimals than specified by cashDecimals parameter`, () => { | ||||
const { toSmallestDenomination } = useBCH(); | const { toSmallestDenomination } = useBCH(); | ||||
const testInput = new BigNumber('132.123456789'); | const testInput = new BigNumber('132.123456789'); | ||||
▲ Show 20 Lines • Show All 45 Lines • Show Last 20 Lines |