add more tests for tryParseTick (#2110)
This commit is contained in:
parent
82a079935e
commit
0e25c055fb
@ -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')
|
||||
})
|
||||
})
|
||||
})
|
||||
|
Loading…
Reference in New Issue
Block a user