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 { | import { | ||||
fromSmallestDenomination, | fromSmallestDenomination, | ||||
batchArray, | batchArray, | ||||
flattenBatchedHydratedUtxos, | flattenBatchedHydratedUtxos, | ||||
loadStoredWallet, | loadStoredWallet, | ||||
isValidStoredWallet, | isValidStoredWallet, | ||||
fromLegacyDecimals, | fromLegacyDecimals, | ||||
convertToEcashPrefix, | convertToEcashPrefix, | ||||
checkNullUtxosForTokenStatus, | checkNullUtxosForTokenStatus, | ||||
confirmNonEtokenUtxos, | confirmNonEtokenUtxos, | ||||
isLegacyMigrationRequired, | isLegacyMigrationRequired, | ||||
toLegacyCash, | toLegacyCash, | ||||
toLegacyToken, | toLegacyToken, | ||||
toLegacyCashArray, | toLegacyCashArray, | ||||
convertEtokenToEcashAddr, | |||||
parseOpReturn, | parseOpReturn, | ||||
isExcludedUtxo, | isExcludedUtxo, | ||||
whichUtxosWereAdded, | whichUtxosWereAdded, | ||||
whichUtxosWereConsumed, | whichUtxosWereConsumed, | ||||
addNewHydratedUtxos, | addNewHydratedUtxos, | ||||
removeConsumedUtxos, | removeConsumedUtxos, | ||||
getUtxoCount, | getUtxoCount, | ||||
areAllUtxosIncludedInIncrementallyHydratedUtxos, | areAllUtxosIncludedInIncrementallyHydratedUtxos, | ||||
▲ Show 20 Lines • Show All 685 Lines • ▼ Show 20 Lines | describe('Correctly executes cash utility functions', () => { | ||||
test('areAllUtxosIncludedInIncrementallyHydratedUtxos returns false if utxo set is invalid', async () => { | test('areAllUtxosIncludedInIncrementallyHydratedUtxos returns false if utxo set is invalid', async () => { | ||||
expect( | expect( | ||||
areAllUtxosIncludedInIncrementallyHydratedUtxos( | areAllUtxosIncludedInIncrementallyHydratedUtxos( | ||||
{}, | {}, | ||||
incrementallyHydratedUtxosAfterProcessing, | incrementallyHydratedUtxosAfterProcessing, | ||||
), | ), | ||||
).toBe(false); | ).toBe(false); | ||||
}); | }); | ||||
test('convertEtokenToEcashAddr successfully converts a valid eToken address to eCash', async () => { | |||||
const result = convertEtokenToEcashAddr( | |||||
'etoken:qpatql05s9jfavnu0tv6lkjjk25n6tmj9gcldpffcs', | |||||
); | |||||
expect(result).toStrictEqual( | |||||
'ecash:qpatql05s9jfavnu0tv6lkjjk25n6tmj9gkpyrlwu8', | |||||
); | |||||
}); | |||||
test('convertEtokenToEcashAddr successfully converts prefixless eToken address as input', async () => { | |||||
const result = convertEtokenToEcashAddr( | |||||
'qpatql05s9jfavnu0tv6lkjjk25n6tmj9gcldpffcs', | |||||
); | |||||
expect(result).toStrictEqual( | |||||
'ecash:qpatql05s9jfavnu0tv6lkjjk25n6tmj9gkpyrlwu8', | |||||
); | |||||
}); | |||||
test('convertEtokenToEcashAddr throws error with an invalid eToken address as input', async () => { | |||||
const result = convertEtokenToEcashAddr('etoken:qpj9gcldpffcs'); | |||||
expect(result).toStrictEqual( | |||||
new Error( | |||||
'cashMethods.convertToEcashAddr() error: etoken:qpj9gcldpffcs is not a valid etoken address', | |||||
), | |||||
); | |||||
}); | |||||
test('convertEtokenToEcashAddr throws error with an ecash address as input', async () => { | |||||
const result = convertEtokenToEcashAddr( | |||||
'ecash:qpatql05s9jfavnu0tv6lkjjk25n6tmj9gkpyrlwu8', | |||||
); | |||||
expect(result).toStrictEqual( | |||||
new Error( | |||||
'cashMethods.convertToEcashAddr() error: ecash:qpatql05s9jfavnu0tv6lkjjk25n6tmj9gkpyrlwu8 is not a valid etoken address', | |||||
), | |||||
); | |||||
}); | |||||
test('convertEtokenToEcashAddr throws error with null input', async () => { | |||||
const result = convertEtokenToEcashAddr(null); | |||||
expect(result).toStrictEqual( | |||||
new Error( | |||||
'cashMethods.convertToEcashAddr() error: No etoken address provided', | |||||
), | |||||
); | |||||
}); | |||||
test('convertEtokenToEcashAddr throws error with empty string input', async () => { | |||||
const result = convertEtokenToEcashAddr(''); | |||||
expect(result).toStrictEqual( | |||||
new Error( | |||||
'cashMethods.convertToEcashAddr() error: No etoken address provided', | |||||
), | |||||
); | |||||
}); | |||||
}); | }); |