Changeset View
Changeset View
Standalone View
Standalone View
web/cashtab/src/utils/__tests__/cashMethods.test.js
import { ValidationError } from 'ecashaddrjs'; | import { ValidationError } from 'ecashaddrjs'; | ||||
import BigNumber from 'bignumber.js'; | |||||
import { | import { | ||||
fromSmallestDenomination, | fromSmallestDenomination, | ||||
batchArray, | batchArray, | ||||
flattenContactList, | flattenContactList, | ||||
flattenBatchedHydratedUtxos, | flattenBatchedHydratedUtxos, | ||||
loadStoredWallet, | loadStoredWallet, | ||||
isValidStoredWallet, | isValidStoredWallet, | ||||
fromLegacyDecimals, | fromLegacyDecimals, | ||||
Show All 13 Lines | import { | ||||
removeConsumedUtxos, | removeConsumedUtxos, | ||||
getUtxoCount, | getUtxoCount, | ||||
areAllUtxosIncludedInIncrementallyHydratedUtxos, | areAllUtxosIncludedInIncrementallyHydratedUtxos, | ||||
convertEcashtoEtokenAddr, | convertEcashtoEtokenAddr, | ||||
getHashArrayFromWallet, | getHashArrayFromWallet, | ||||
parseChronikTx, | parseChronikTx, | ||||
checkWalletForTokenInfo, | checkWalletForTokenInfo, | ||||
isActiveWebsocket, | isActiveWebsocket, | ||||
parseXecSendValue, | |||||
} from 'utils/cashMethods'; | } from 'utils/cashMethods'; | ||||
import { currency } from 'components/Common/Ticker'; | import { currency } from 'components/Common/Ticker'; | ||||
import { | import { | ||||
unbatchedArray, | unbatchedArray, | ||||
arrayBatchedByThree, | arrayBatchedByThree, | ||||
} from '../__mocks__/mockBatchedArrays'; | } from '../__mocks__/mockBatchedArrays'; | ||||
import { | import { | ||||
validAddressArrayInput, | validAddressArrayInput, | ||||
▲ Show 20 Lines • Show All 129 Lines • ▼ Show 20 Lines | import { | ||||
lambdaOutgoingXecTx, | lambdaOutgoingXecTx, | ||||
lambdaIncomingEtokenTx, | lambdaIncomingEtokenTx, | ||||
lambdaOutgoingEtokenTx, | lambdaOutgoingEtokenTx, | ||||
activeWebsocketAlpha, | activeWebsocketAlpha, | ||||
disconnectedWebsocketAlpha, | disconnectedWebsocketAlpha, | ||||
unsubscribedWebsocket, | unsubscribedWebsocket, | ||||
} from '../__mocks__/chronikWs'; | } from '../__mocks__/chronikWs'; | ||||
it(`parseXecSendValue() correctly parses the value for a valid one to one send XEC transaction`, () => { | |||||
expect(parseXecSendValue(false, '550', null)).toStrictEqual( | |||||
new BigNumber(550), | |||||
); | |||||
}); | |||||
it(`parseXecSendValue() correctly parses the value for a valid one to many send XEC transaction`, () => { | |||||
const destinationAddressAndValueArray = [ | |||||
'ecash:qrmz0egsqxj35x5jmzf8szrszdeu72fx0uxgwk3r48,6', | |||||
'ecash:qq9h6d0a5q65fgywv4ry64x04ep906mdku8f0gxfgx,6', | |||||
'ecash:qzvydd4n3lm3xv62cx078nu9rg0e3srmqq0knykfed,6', | |||||
]; | |||||
expect( | |||||
parseXecSendValue(true, null, destinationAddressAndValueArray), | |||||
).toStrictEqual(new BigNumber(18)); | |||||
}); | |||||
it(`parseXecSendValue() correctly throws error when singleSendValue is invalid for a one to one send XEC transaction`, () => { | |||||
let errorThrown; | |||||
try { | |||||
parseXecSendValue(false, null, 550); | |||||
} catch (err) { | |||||
errorThrown = err; | |||||
} | |||||
expect(errorThrown.message).toStrictEqual('Invalid singleSendValue'); | |||||
}); | |||||
it(`parseXecSendValue() correctly throws error when destinationAddressAndValueArray is invalid for a one to many send XEC transaction`, () => { | |||||
let errorThrown; | |||||
try { | |||||
parseXecSendValue(true, null, null); | |||||
} catch (err) { | |||||
errorThrown = err; | |||||
} | |||||
expect(errorThrown.message).toStrictEqual( | |||||
'Invalid destinationAddressAndValueArray', | |||||
); | |||||
}); | |||||
it(`parseXecSendValue() correctly throws error when the total value for a one to one send XEC transaction is below dust`, () => { | |||||
let errorThrown; | |||||
try { | |||||
parseXecSendValue(false, '4.5', null); | |||||
} catch (err) { | |||||
errorThrown = err; | |||||
} | |||||
expect(errorThrown.message).toStrictEqual('dust'); | |||||
}); | |||||
it(`parseXecSendValue() correctly throws error when the total value for a one to many send XEC transaction is below dust`, () => { | |||||
const destinationAddressAndValueArray = [ | |||||
'ecash:qrmz0egsqxj35x5jmzf8szrszdeu72fx0uxgwk3r48,2', | |||||
'ecash:qq9h6d0a5q65fgywv4ry64x04ep906mdku8f0gxfgx,2', | |||||
'ecash:qzvydd4n3lm3xv62cx078nu9rg0e3srmqq0knykfed,1', | |||||
]; | |||||
let errorThrown; | |||||
try { | |||||
parseXecSendValue(true, null, destinationAddressAndValueArray); | |||||
} catch (err) { | |||||
errorThrown = err; | |||||
} | |||||
expect(errorThrown.message).toStrictEqual('dust'); | |||||
}); | |||||
describe('Correctly executes cash utility functions', () => { | describe('Correctly executes cash utility functions', () => { | ||||
it(`Correctly converts smallest base unit to smallest decimal for cashDecimals = 2`, () => { | it(`Correctly converts smallest base unit to smallest decimal for cashDecimals = 2`, () => { | ||||
expect(fromSmallestDenomination(1, 2)).toBe(0.01); | expect(fromSmallestDenomination(1, 2)).toBe(0.01); | ||||
}); | }); | ||||
it(`Correctly converts largest base unit to smallest decimal for cashDecimals = 2`, () => { | it(`Correctly converts largest base unit to smallest decimal for cashDecimals = 2`, () => { | ||||
expect(fromSmallestDenomination(1000000012345678, 2)).toBe( | expect(fromSmallestDenomination(1000000012345678, 2)).toBe( | ||||
10000000123456.78, | 10000000123456.78, | ||||
); | ); | ||||
▲ Show 20 Lines • Show All 811 Lines • Show Last 20 Lines |