Commit 0e25c055 authored by Justin Domingue's avatar Justin Domingue Committed by GitHub

add more tests for tryParseTick (#2110)

parent 82a07993
......@@ -16,7 +16,7 @@ describe('hooks', () => {
expect(tryParsePrice(baseToken, quoteToken, '20.')).toEqual(undefined)
})
it('should return a price', () => {
it('should return a price when decimals are the same', () => {
const baseToken = new Token(1, '0x6b175474e89094c44da98b954eedeac495271d0f', 6)
const quoteToken = new Token(1, '0x1b175474e89094c44da98b954eedeac495271d0f', 6)
......@@ -36,5 +36,26 @@ describe('hooks', () => {
tryParsePrice(baseToken, quoteToken, /* ~2^-128 */ '0.000000000000000000000000000587747')?.toSignificant(6)
).toEqual('0.000000000000000000000000000587747')
})
it('should return a price when decimals are different', () => {
const baseToken = new Token(1, '0x6b175474e89094c44da98b954eedeac495271d0f', 2)
const quoteToken = new Token(1, '0x1b175474e89094c44da98b954eedeac495271d0f', 4)
expect(tryParsePrice(baseToken, quoteToken, '20')?.toSignificant(6)).toEqual('20')
expect(tryParsePrice(baseToken, quoteToken, '20.05')?.toSignificant(6)).toEqual('20.05')
expect(tryParsePrice(baseToken, quoteToken, '20.123456789')?.toSignificant(6)).toEqual('20.1235')
expect(tryParsePrice(baseToken, quoteToken, '0.123456789')?.toSignificant(6)).toEqual('0.123457')
expect(tryParsePrice(baseToken, quoteToken, '.123456789')?.toSignificant(6)).toEqual('0.123457')
expect(
tryParsePrice(
baseToken,
quoteToken,
(2 ** 128).toLocaleString('fullwide', { useGrouping: false })
)?.toSignificant(6)
).toEqual('340282000000000000000000000000000000000')
expect(
tryParsePrice(baseToken, quoteToken, /* ~2^-128 */ '0.000000000000000000000000000587747')?.toSignificant(6)
).toEqual('0.000000000000000000000000000587747')
})
})
})
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment