Skip to content

Commit

Permalink
Add tests for "apply slippage" not modifying the passed object
Browse files Browse the repository at this point in the history
  • Loading branch information
ChiTimesChi committed Dec 27, 2023
1 parent 43ed59f commit dbff955
Showing 1 changed file with 33 additions and 0 deletions.
33 changes: 33 additions & 0 deletions packages/sdk-router/src/module/query.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -193,6 +193,17 @@ describe('#query', () => {
rawParams: '5',
})
})

it('does not modify the original query', () => {
applySlippage(query, 50, 10000)
expect(query).toEqual({
swapAdapter: '1',
tokenOut: '2',
minAmountOut: BigNumber.from(10).pow(18).mul(1_000_000),
deadline: BigNumber.from(4),
rawParams: '5',
})
})
})

describe('CCTPRouterQuery', () => {
Expand Down Expand Up @@ -261,6 +272,17 @@ describe('#query', () => {
rawParams: '5',
})
})

it('does not modify the original query', () => {
applySlippage(query, 50, 10000)
expect(query).toEqual({
routerAdapter: '1',
tokenOut: '2',
minAmountOut: BigNumber.from(10).pow(6).mul(1_000_000),
deadline: BigNumber.from(4),
rawParams: '5',
})
})
})

describe('errors', () => {
Expand Down Expand Up @@ -326,6 +348,17 @@ describe('#query', () => {
expect(newQuery).toEqual(newQueryInBips)
})

it('does not modify the original query', () => {
applySlippageInBips(query, 50)
expect(query).toEqual({
swapAdapter: '1',
tokenOut: '2',
minAmountOut: BigNumber.from(10).pow(18).mul(1_000_000),
deadline: BigNumber.from(4),
rawParams: '5',
})
})

it('throws if basis points are negative', () => {
expect(() => applySlippageInBips(routerQuery, -1)).toThrow(
'Slippage numerator cannot be negative'
Expand Down

0 comments on commit dbff955

Please sign in to comment.