Changeset View
Changeset View
Standalone View
Standalone View
web/cashtab/src/utils/__tests__/validation.test.js
Show First 20 Lines • Show All 80 Lines • ▼ Show 20 Lines | it(`Returns error if ${ | ||||
currency.ticker | currency.ticker | ||||
} send amount is less than ${fromSmallestDenomination( | } send amount is less than ${fromSmallestDenomination( | ||||
currency.dustSats, | currency.dustSats, | ||||
).toString()} minimum in fiat currency`, () => { | ).toString()} minimum in fiat currency`, () => { | ||||
const expectedValidationError = `Send amount must be at least ${fromSmallestDenomination( | const expectedValidationError = `Send amount must be at least ${fromSmallestDenomination( | ||||
currency.dustSats, | currency.dustSats, | ||||
).toString()} ${currency.ticker}`; | ).toString()} ${currency.ticker}`; | ||||
expect( | expect( | ||||
shouldRejectAmountInput('0.0000005', 'USD', 14.63, 0.52574662), | shouldRejectAmountInput('0.0000005', 'USD', 0.00005, 1000000), | ||||
).toBe(expectedValidationError); | ).toBe(expectedValidationError); | ||||
}); | }); | ||||
it(`Returns balance error if ${currency.ticker} send amount is greater than user balance with fiat currency selected`, () => { | it(`Returns balance error if ${currency.ticker} send amount is greater than user balance with fiat currency selected`, () => { | ||||
const expectedValidationError = `Amount cannot exceed your ${currency.ticker} balance`; | const expectedValidationError = `Amount cannot exceed your ${currency.ticker} balance`; | ||||
// Here, user is trying to send $170 USD, where 1 BCHA = $20 USD, and the user has a balance of 5 BCHA or $100 | // Here, user is trying to send $170 USD, where 1 BCHA = $20 USD, and the user has a balance of 5 BCHA or $100 | ||||
expect(shouldRejectAmountInput('170', 'USD', 20.0, 5)).toBe( | expect(shouldRejectAmountInput('170', 'USD', 20.0, 5)).toBe( | ||||
expectedValidationError, | expectedValidationError, | ||||
); | ); | ||||
}); | }); | ||||
it(`Returns precision error if ${currency.ticker} send amount has more than ${currency.cashDecimals} decimal places`, () => { | it(`Returns precision error if ${currency.ticker} send amount has more than ${currency.cashDecimals} decimal places`, () => { | ||||
const expectedValidationError = `${currency.ticker} transactions do not support more than ${currency.cashDecimals} decimal places`; | const expectedValidationError = `${currency.ticker} transactions do not support more than ${currency.cashDecimals} decimal places`; | ||||
expect( | expect( | ||||
shouldRejectAmountInput('17.123456789', currency.ticker, 20.0, 35), | shouldRejectAmountInput('17.123456789', currency.ticker, 20.0, 35), | ||||
).toBe(expectedValidationError); | ).toBe(expectedValidationError); | ||||
}); | }); | ||||
it(`Returns expected crypto amount with ${currency.cashDecimals} decimals of precision even if inputs have higher precision`, () => { | it(`Returns expected crypto amount with ${currency.cashDecimals} decimals of precision even if inputs have higher precision`, () => { | ||||
expect(fiatToCrypto('10.97231694823432', 20.3231342349234234)).toBe( | expect(fiatToCrypto('10.97231694823432', 20.3231342349234234, 8)).toBe( | ||||
'0.53989295', | '0.53989295', | ||||
); | ); | ||||
}); | }); | ||||
it(`Returns expected crypto amount with ${currency.cashDecimals} decimals of precision even if inputs have higher precision`, () => { | |||||
expect(fiatToCrypto('10.97231694823432', 20.3231342349234234, 2)).toBe( | |||||
'0.54', | |||||
); | |||||
}); | |||||
it(`Returns expected crypto amount with ${currency.cashDecimals} decimals of precision even if inputs have lower precision`, () => { | it(`Returns expected crypto amount with ${currency.cashDecimals} decimals of precision even if inputs have lower precision`, () => { | ||||
expect(fiatToCrypto('10.94', 10)).toBe('1.09400000'); | expect(fiatToCrypto('10.94', 10, 8)).toBe('1.09400000'); | ||||
}); | }); | ||||
it(`Accepts a valid ${currency.tokenTicker} token name`, () => { | it(`Accepts a valid ${currency.tokenTicker} token name`, () => { | ||||
expect(isValidTokenName('Valid token name')).toBe(true); | expect(isValidTokenName('Valid token name')).toBe(true); | ||||
}); | }); | ||||
it(`Accepts a valid ${currency.tokenTicker} token name that is a stringified number`, () => { | it(`Accepts a valid ${currency.tokenTicker} token name that is a stringified number`, () => { | ||||
expect(isValidTokenName('123456789')).toBe(true); | expect(isValidTokenName('123456789')).toBe(true); | ||||
}); | }); | ||||
it(`Rejects ${currency.tokenTicker} token name if longer than 68 characters`, () => { | it(`Rejects ${currency.tokenTicker} token name if longer than 68 characters`, () => { | ||||
▲ Show 20 Lines • Show All 92 Lines • Show Last 20 Lines |