forked from BlockNG-Foundation/blockng-swap-sdk
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathroute.test.ts
40 lines (35 loc) · 1.65 KB
/
route.test.ts
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
import { Token, WETH, ChainId, Pair, TokenAmount, Route, ETHER } from '../src'
describe('Route', () => {
const token0 = new Token(ChainId.MAINNET, '0x0000000000000000000000000000000000000001', 18, 't0')
const token1 = new Token(ChainId.MAINNET, '0x0000000000000000000000000000000000000002', 18, 't1')
const weth = WETH[ChainId.MAINNET]
const pair_0_1 = new Pair(new TokenAmount(token0, '100'), new TokenAmount(token1, '200'))
const pair_0_weth = new Pair(new TokenAmount(token0, '100'), new TokenAmount(weth, '100'))
const pair_1_weth = new Pair(new TokenAmount(token1, '175'), new TokenAmount(weth, '100'))
it('constructs a path from the tokens', () => {
const route = new Route([pair_0_1], token0)
expect(route.pairs).toEqual([pair_0_1])
expect(route.path).toEqual([token0, token1])
expect(route.input).toEqual(token0)
expect(route.output).toEqual(token1)
expect(route.chainId).toEqual(ChainId.MAINNET)
})
it('can have a token as both input and output', () => {
const route = new Route([pair_0_weth, pair_0_1, pair_1_weth], weth)
expect(route.pairs).toEqual([pair_0_weth, pair_0_1, pair_1_weth])
expect(route.input).toEqual(weth)
expect(route.output).toEqual(weth)
})
it('supports ether input', () => {
const route = new Route([pair_0_weth], ETHER)
expect(route.pairs).toEqual([pair_0_weth])
expect(route.input).toEqual(ETHER)
expect(route.output).toEqual(token0)
})
it('supports ether output', () => {
const route = new Route([pair_0_weth], token0, ETHER)
expect(route.pairs).toEqual([pair_0_weth])
expect(route.input).toEqual(token0)
expect(route.output).toEqual(ETHER)
})
})