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'; | ||||
import { fromSmallestDenomination } from '@utils/cashMethods'; | |||||
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', () => { | it('Replicate 8-decimal return value from instance of toSatoshi in TransactionBuilder with toSmallestDenomination', () => { | ||||
▲ Show 20 Lines • Show All 97 Lines • ▼ Show 20 Lines | it(`BigNumber version of remainder variable is equivalent to Math.floor version`, () => { | ||||
originalAmountTest.minus(satoshisToSendTest).minus(txFeeTest), | originalAmountTest.minus(satoshisToSendTest).minus(txFeeTest), | ||||
), | ), | ||||
); | ); | ||||
}); | }); | ||||
it(`Using parseInt on a BigNumber returns output type required for Transaction Builder`, () => { | it(`Using parseInt on a BigNumber returns output type required for Transaction Builder`, () => { | ||||
const remainder = new BigNumber('12345678'); | const remainder = new BigNumber('12345678'); | ||||
expect(parseInt(remainder)).toStrictEqual(12345678); | expect(parseInt(remainder)).toStrictEqual(12345678); | ||||
}); | }); | ||||
it('Replicates return value from instance of toBitcoinCash with fromSmallestDenomination and cashDecimals = 8', () => { | |||||
const BCH = new BCHJS(); | |||||
const testSendAmount = '12345678'; | |||||
expect(fromSmallestDenomination(testSendAmount, 8)).toBe( | |||||
BCH.BitcoinCash.toBitcoinCash(testSendAmount), | |||||
); | |||||
}); | |||||
it('Replicates largest possible digits return value from instance of toBitcoinCash with fromSmallestDenomination and cashDecimals = 8', () => { | |||||
const BCH = new BCHJS(); | |||||
const testSendAmount = '1000000012345678'; | |||||
expect(fromSmallestDenomination(testSendAmount, 8)).toBe( | |||||
BCH.BitcoinCash.toBitcoinCash(testSendAmount), | |||||
); | |||||
}); | |||||
it('Replicates smallest unit value return value from instance of toBitcoinCash with fromSmallestDenomination and cashDecimals = 8', () => { | |||||
const BCH = new BCHJS(); | |||||
const testSendAmount = '1'; | |||||
expect(fromSmallestDenomination(testSendAmount, 8)).toBe( | |||||
BCH.BitcoinCash.toBitcoinCash(testSendAmount), | |||||
); | |||||
}); | |||||
}); | }); |