Changeset View
Changeset View
Standalone View
Standalone View
web/cashtab/src/components/Common/__tests__/Ticker.test.js
import { ValidationError } from 'ecashaddrjs'; | import { ValidationError } from 'ecashaddrjs'; | ||||
import { | import { | ||||
isValidCashPrefix, | isValidCashPrefix, | ||||
isValidTokenPrefix, | isValidTokenPrefix, | ||||
toLegacy, | toLegacy, | ||||
toLegacyArray, | |||||
isCashtabOutput, | isCashtabOutput, | ||||
isEtokenOutput, | isEtokenOutput, | ||||
extractCashtabMessage, | extractCashtabMessage, | ||||
extractExternalMessage, | extractExternalMessage, | ||||
getETokenEncodingSubstring, | getETokenEncodingSubstring, | ||||
getCashtabEncodingSubstring, | getCashtabEncodingSubstring, | ||||
} from '../Ticker'; | } from '../Ticker'; | ||||
import { | |||||
validAddressArrayInput, | |||||
validAddressArrayOutput, | |||||
validLargeAddressArrayInput, | |||||
validLargeAddressArrayOutput, | |||||
invalidAddressArrayInput, | |||||
} from '../__mocks__/mockAddressArray'; | |||||
test('Rejects cash address with bitcoincash: prefix', async () => { | test('Rejects cash address with bitcoincash: prefix', async () => { | ||||
const result = isValidCashPrefix( | const result = isValidCashPrefix( | ||||
'bitcoincash:qqd3qn4zazjhygk5a2vzw2gvqgqwempr4gjykk3wa0', | 'bitcoincash:qqd3qn4zazjhygk5a2vzw2gvqgqwempr4gjykk3wa0', | ||||
); | ); | ||||
expect(result).toStrictEqual(false); | expect(result).toStrictEqual(false); | ||||
}); | }); | ||||
▲ Show 20 Lines • Show All 91 Lines • ▼ Show 20 Lines | test('toLegacy throws error if input address has invalid prefix', async () => { | ||||
expect(result).toStrictEqual( | expect(result).toStrictEqual( | ||||
new Error( | new Error( | ||||
'Address prefix is not a valid cash address with a prefix from the Ticker.prefixes array', | 'Address prefix is not a valid cash address with a prefix from the Ticker.prefixes array', | ||||
), | ), | ||||
); | ); | ||||
}); | }); | ||||
test('toLegacyArray throws error if the addressArray input is null', async () => { | |||||
const result = toLegacyArray(null); | |||||
expect(result).toStrictEqual(new Error('Invalid addressArray input')); | |||||
}); | |||||
test('toLegacyArray throws error if the addressArray input is empty', async () => { | |||||
const result = toLegacyArray([]); | |||||
expect(result).toStrictEqual(new Error('Invalid addressArray input')); | |||||
}); | |||||
test('toLegacyArray throws error if the addressArray input is a number', async () => { | |||||
const result = toLegacyArray(12345); | |||||
expect(result).toStrictEqual(new Error('Invalid addressArray input')); | |||||
}); | |||||
test('toLegacyArray throws error if the addressArray input is undefined', async () => { | |||||
const result = toLegacyArray(undefined); | |||||
expect(result).toStrictEqual(new Error('Invalid addressArray input')); | |||||
}); | |||||
test('toLegacyArray successfully converts a standard sized valid addressArray input', async () => { | |||||
const result = toLegacyArray(validAddressArrayInput); | |||||
expect(result).toStrictEqual(validAddressArrayOutput); | |||||
}); | |||||
test('toLegacyArray successfully converts a large valid addressArray input', async () => { | |||||
const result = toLegacyArray(validLargeAddressArrayInput); | |||||
expect(result).toStrictEqual(validLargeAddressArrayOutput); | |||||
}); | |||||
test('toLegacyArray throws an error on an addressArray with invalid addresses', async () => { | |||||
const result = toLegacyArray(invalidAddressArrayInput); | |||||
expect(result).toStrictEqual( | |||||
new ValidationError( | |||||
'Invalid checksum: ecash:qrqgwxrrrrrrrrrrrrrrrrrrrrrrrrr7zsvk.', | |||||
), | |||||
); | |||||
}); | |||||
test('getCashtabEncodingSubstring() returns the appropriate substring for cashtab message outputs', async () => { | test('getCashtabEncodingSubstring() returns the appropriate substring for cashtab message outputs', async () => { | ||||
const result = getCashtabEncodingSubstring(); | const result = getCashtabEncodingSubstring(); | ||||
expect(result).toStrictEqual('6a0400746162'); | expect(result).toStrictEqual('6a0400746162'); | ||||
}); | }); | ||||
test('getETokenEncodingSubstring() returns the appropriate substring for eToken outputs', async () => { | test('getETokenEncodingSubstring() returns the appropriate substring for eToken outputs', async () => { | ||||
const result = getETokenEncodingSubstring(); | const result = getETokenEncodingSubstring(); | ||||
expect(result).toStrictEqual('6a04534c5000'); | expect(result).toStrictEqual('6a04534c5000'); | ||||
▲ Show 20 Lines • Show All 64 Lines • Show Last 20 Lines |