Changeset View
Changeset View
Standalone View
Standalone View
web/cashtab/src/hooks/__tests__/migrations.test.js
Show First 20 Lines • Show All 83 Lines • ▼ Show 20 Lines | it('toSmallestDenomination() returns exact result as toSatoshi but in BigNumber format', () => { | ||||
const testAmountInCashDecimals = toSmallestDenomination(testAmount); | const testAmountInCashDecimals = toSmallestDenomination(testAmount); | ||||
expect(testAmountInSatoshis).toStrictEqual(12345678); | expect(testAmountInSatoshis).toStrictEqual(12345678); | ||||
expect(testAmountInCashDecimals).toStrictEqual( | expect(testAmountInCashDecimals).toStrictEqual( | ||||
new BigNumber(testAmountInSatoshis), | new BigNumber(testAmountInSatoshis), | ||||
); | ); | ||||
}); | }); | ||||
it(`BigNumber version of remainder variable is equivalent to Math.floor version`, () => { | |||||
const { toSmallestDenomination } = useBCH(); | |||||
// Test case for sending 0.12345678 BCHA | |||||
let satoshisToSendTest = toSmallestDenomination( | |||||
new BigNumber('0.12345678'), | |||||
); | |||||
// Assume total BCHA available in utxos is 500 sats higher than 0.123456578 BCHA | |||||
let originalAmountTest = satoshisToSendTest.plus(500); | |||||
// Assume 229 byte tx fee | |||||
let txFeeTest = 229; | |||||
expect( | |||||
Math.floor( | |||||
originalAmountTest.minus(satoshisToSendTest).minus(txFeeTest), | |||||
), | |||||
).toStrictEqual( | |||||
parseInt( | |||||
originalAmountTest.minus(satoshisToSendTest).minus(txFeeTest), | |||||
), | |||||
); | |||||
}); | |||||
it(`Using parseInt on a BigNumber returns output type required for Transaction Builder`, () => { | |||||
const remainder = new BigNumber('12345678'); | |||||
expect(parseInt(remainder)).toStrictEqual(12345678); | |||||
}); | |||||
}); | }); |