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 { | import { | ||||
| fromSmallestDenomination, | fromSmallestDenomination, | ||||
| toSmallestDenomination, | toSmallestDenomination, | ||||
| } from '@utils/cashMethods'; | } from '@utils/cashMethods'; | ||||
| describe('Testing functions for upgrading Cashtab', () => { | describe('Testing functions for upgrading Cashtab', () => { | ||||
| it('Replacement currency.dustSats parameter parsing matches legacy DUST parameter', () => { | it('Replacement currency.dustSats parameter parsing matches legacy DUST parameter', () => { | ||||
| expect( | expect( | ||||
| parseFloat( | parseFloat( | ||||
| new BigNumber( | new BigNumber( | ||||
| fromSmallestDenomination(currency.dustSats, 8).toString(), | fromSmallestDenomination(currency.dustSats, 8).toString(), | ||||
| ).toFixed(8), | ).toFixed(8), | ||||
| ), | ), | ||||
| ).toBe(0.00000546); | ).toBe(0.0000055); | ||||
| }); | }); | ||||
| 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', () => { | ||||
| const BCH = new BCHJS(); | const BCH = new BCHJS(); | ||||
| const testSendAmount = '0.12345678'; | const testSendAmount = '0.12345678'; | ||||
| expect( | expect( | ||||
| parseInt(toSmallestDenomination(new BigNumber(testSendAmount), 8)), | parseInt(toSmallestDenomination(new BigNumber(testSendAmount), 8)), | ||||
| ).toBe(BCH.BitcoinCash.toSatoshi(Number(testSendAmount).toFixed(8))); | ).toBe(BCH.BitcoinCash.toSatoshi(Number(testSendAmount).toFixed(8))); | ||||
| }); | }); | ||||
| ▲ Show 20 Lines • Show All 101 Lines • ▼ Show 20 Lines | it('Replicates smallest unit value return value from instance of toBitcoinCash with fromSmallestDenomination and cashDecimals = 8', () => { | ||||
| const testSendAmount = '1'; | const testSendAmount = '1'; | ||||
| expect(fromSmallestDenomination(testSendAmount, 8)).toBe( | expect(fromSmallestDenomination(testSendAmount, 8)).toBe( | ||||
| BCH.BitcoinCash.toBitcoinCash(testSendAmount), | BCH.BitcoinCash.toBitcoinCash(testSendAmount), | ||||
| ); | ); | ||||
| }); | }); | ||||
| it(`Converts dust limit in satoshis to dust limit in current app setting`, () => { | it(`Converts dust limit in satoshis to dust limit in current app setting`, () => { | ||||
| expect(fromSmallestDenomination(currency.dustSats, 8).toString()).toBe( | expect(fromSmallestDenomination(currency.dustSats, 8).toString()).toBe( | ||||
| '0.00000546', | '0.0000055', | ||||
| ); | ); | ||||
| }); | }); | ||||
| }); | }); | ||||