Changeset View
Changeset View
Standalone View
Standalone View
web/cashtab/src/utils/__tests__/cashMethods.test.js
import { | import { | ||||
fromSmallestDenomination, | fromSmallestDenomination, | ||||
formatBalance, | formatBalance, | ||||
batchArray, | batchArray, | ||||
flattenBatchedHydratedUtxos, | flattenBatchedHydratedUtxos, | ||||
loadStoredWallet, | |||||
isValidStoredWallet, | |||||
} from '@utils/cashMethods'; | } from '@utils/cashMethods'; | ||||
import { | import { | ||||
unbatchedArray, | unbatchedArray, | ||||
arrayBatchedByThree, | arrayBatchedByThree, | ||||
} from '../__mocks__/mockBatchedArrays'; | } from '../__mocks__/mockBatchedArrays'; | ||||
import { | import { | ||||
originalFinal, | |||||
batchedFinal, | |||||
unflattenedHydrateUtxosResponse, | unflattenedHydrateUtxosResponse, | ||||
flattenedHydrateUtxosResponse, | flattenedHydrateUtxosResponse, | ||||
} from '../__mocks__/flattenBatchedHydratedUtxosMocks'; | } from '../__mocks__/flattenBatchedHydratedUtxosMocks'; | ||||
import { | |||||
cachedUtxos, | |||||
utxosLoadedFromCache, | |||||
} from '../__mocks__/mockCachedUtxos'; | |||||
import { | |||||
validStoredWallet, | |||||
invalidStoredWallet, | |||||
} from '../__mocks__/mockStoredWallets'; | |||||
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 All 35 Lines | describe('Correctly executes cash utility functions', () => { | ||||
it(`If array length is less than batch size, return original array as first and only element of new array`, () => { | it(`If array length is less than batch size, return original array as first and only element of new array`, () => { | ||||
expect(batchArray(unbatchedArray, 20)).toStrictEqual([unbatchedArray]); | expect(batchArray(unbatchedArray, 20)).toStrictEqual([unbatchedArray]); | ||||
}); | }); | ||||
it(`Flattens hydrateUtxos from Promise.all() response into array that can be parsed by getSlpBalancesAndUtxos`, () => { | it(`Flattens hydrateUtxos from Promise.all() response into array that can be parsed by getSlpBalancesAndUtxos`, () => { | ||||
expect( | expect( | ||||
flattenBatchedHydratedUtxos(unflattenedHydrateUtxosResponse), | flattenBatchedHydratedUtxos(unflattenedHydrateUtxosResponse), | ||||
).toStrictEqual(flattenedHydrateUtxosResponse); | ).toStrictEqual(flattenedHydrateUtxosResponse); | ||||
}); | }); | ||||
it(`Accepts a cachedWalletState that has not preserved BigNumber object types, and returns the same wallet state with BigNumber type re-instituted`, () => { | |||||
expect(loadStoredWallet(cachedUtxos)).toStrictEqual( | |||||
utxosLoadedFromCache, | |||||
); | |||||
}); | |||||
it(`Recognizes a stored wallet as valid if it has all required fields`, () => { | |||||
expect(isValidStoredWallet(validStoredWallet)).toBe(true); | |||||
}); | |||||
it(`Recognizes a stored wallet as invalid if it is missing required fields`, () => { | |||||
expect(isValidStoredWallet(invalidStoredWallet)).toBe(false); | |||||
}); | |||||
}); | }); |